Skip to content

Commit 7b45975

Browse files
authored
feat: otel instrumentation of wundernode and server (#1004)
* feat: otel instrumentation * chore: add sdk interface * chore: upgrade to go 1.19.0 due to otel dep * chore: zero overhead when disabling otel * chore: add example, improve error reporting * chore: ensure same default * chore: add e2e tests * chore: address feedback * chore: limit concurrency for big machines * chore: update vitest * chore: upgrade to go 1.20 and docker compose 3.8 * chore: run with limited concurrency, improves performance and stability * chore: fix port race in tests
1 parent 79f968a commit 7b45975

109 files changed

Lines changed: 4576 additions & 940 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/actions/go/action.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: 'This action install go and cache modules and build dependencies'
33
inputs:
44
go-version:
55
description: 'The go version to install'
6-
default: '1.18'
6+
default: '1.20'
77
required: false
88
working-directory:
99
description: 'The working directory of your go module'

‎.github/workflows/engine-ci.yaml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ jobs:
7373
- name: Linters
7474
uses: golangci/golangci-lint-action@v3
7575
with:
76-
version: v1.50
76+
# keep in sync with local version
77+
version: v1.52.2
7778
args: --timeout 2m
7879

7980
- name: Run unit and integration tests

‎.github/workflows/packages-ci.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ jobs:
7878
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7979

8080
- name: Run testsuite
81-
run: pnpm test:suite
81+
run: pnpm test:suite:ci
8282

8383
- name: Determine changed files
8484
id: changed

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This guide assumes you have already installed the following software:
99
- make (should be installed on all linux / IOS systems)
1010
- [protoc](https://grpc.io/docs/protoc-installation/) (3.15.8)
1111
- curl -LO "https://github.com/protocolbuffers/protobuf/releases/download/v21.5/protoc-21.5-linux-x86_64.zip"
12-
- golang `>= 1.18`
12+
- golang `>= 1.20`
1313
- Node.js [LTS](https://nodejs.org/en/about/releases/)
1414
- pnpm `7`
1515

‎Dockerfile‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.18 as builder
1+
FROM golang:1.20 as builder
22

33
ARG COMMIT
44
ARG VERSION
@@ -12,7 +12,7 @@ RUN go mod download
1212

1313
RUN make build
1414

15-
from golang:1.18-alpine as runner
15+
from golang:1.20-alpine as runner
1616

1717
WORKDIR /usr/src/app
1818

‎Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ codegen: install-proto codegen-go
5050
pnpm codegen
5151

5252
build: codegen
53-
cd cmd/wunderctl && go build -o ../../wunderctl -ldflags "-X 'main.commit=$(shell git rev-parse --short HEAD)' -X 'main.builtBy=dev' -X 'main.version=dev' -X 'main.date=$(shell date)'" -trimpath
53+
cd cmd/wunderctl && CGO_ENABLED=0 go build -o ../../wunderctl -ldflags "-X 'main.commit=$(shell git rev-parse --short HEAD)' -X 'main.builtBy=dev' -X 'main.version=dev' -X 'main.date=$(shell date)'" -trimpath
5454

5555
# This command builds the wunderctl binary and copies it into the nodejs wunderctl wrapper
5656
wunderctl: build

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ The best way to try them out is by cloning the mono-repo.
244244

245245
- [Use Turborepo to speed up builds in monorepos.](https://github.com/wundergraph/cloud-starter-turbo)
246246
- [Manage multiple WunderGraph Cloud Projects in a single repository](https://github.com/wundergraph/cloud-multi-projects-demo)
247+
- [Built-in OpenTelemetry instrumentation](examples/openapi-mocking)
247248

248249
## The WunderGraph Stack
249250

‎cli/commands/node.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ func StartWunderGraphNode(n *node.Node, opts ...Option) error {
151151
node.WithStaticWunderNodeConfig(wunderNodeConfig),
152152
node.WithForceHttpsRedirects(!disableForceHttpsRedirects),
153153
node.WithIntrospection(enableIntrospection),
154+
node.WithTraceBatchTimeout(otelBatchTimeout),
154155
}
155156

156157
if shutdownAfterIdle > 0 {

‎cli/commands/root.go‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"io/fs"
66
"os"
7+
"strconv"
78
"time"
89

910
"github.com/fatih/color"
@@ -41,6 +42,9 @@ var (
4142
cmdDurationMetric telemetry.DurationMetric
4243
zapLogLevel zapcore.Level
4344
_wunderGraphDirConfig string
45+
// otelBatchTimeout is the maximum timeout before a batch of otel data is sent
46+
// By default it is 5 seconds but for CI and debugging purposes it should be set much lower
47+
otelBatchTimeout time.Duration
4448

4549
rootFlags helpers.RootFlags
4650

@@ -268,6 +272,15 @@ func init() {
268272
_, isTelemetryDebugEnabled := os.LookupEnv("WG_TELEMETRY_DEBUG")
269273
telemetryAnonymousID := os.Getenv("WG_TELEMETRY_ANONYMOUS_ID")
270274

275+
if otelBatchTimeoutEnv, ok := os.LookupEnv("WG_OTEL_BATCH_TIMEOUT_MS"); ok {
276+
ms, err := strconv.Atoi(otelBatchTimeoutEnv)
277+
if err != nil {
278+
log.Error("Value behind WG_OTEL_BATCH_TIMEOUT_MS could not be parsed as integer", zap.Error(err))
279+
} else {
280+
otelBatchTimeout = time.Duration(ms) * time.Millisecond
281+
}
282+
}
283+
271284
config.InitConfig(config.Options{
272285
TelemetryEnabled: !isTelemetryDisabled,
273286
TelemetryAnonymousID: telemetryAnonymousID,

‎cli/commands/start.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ var startCmd = &cobra.Command{
6666
// Only exit with error code 1 when the server was not stopped by the signal
6767
if err := g.Wait(); sigCtx.Err() == nil && err != nil {
6868
// Exit with error code 1 to indicate failure and restart
69-
log.Error("WunderGraph start process shutdown: %w", zap.Error(err))
69+
log.Error("WunderGraph start process shutdown", zap.Error(err))
7070
return err
7171
}
7272

0 commit comments

Comments
 (0)