Skip to content

Commit b4fa813

Browse files
heiskrCopilot
andauthored
Add OpenTelemetry distributed tracing (#60386)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 5279706 commit b4fa813

File tree

9 files changed

+3265
-152
lines changed

9 files changed

+3265
-152
lines changed

config/moda/configuration/default/env.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ data:
99
RATE_LIMIT_MAX: '21'
1010
# Moda uses a non-default port for sending datadog metrics
1111
DD_DOGSTATSD_PORT: '28125'
12+
# OTel distributed tracing — sends spans to OTel Collector via OTLP/HTTP (proto).
13+
# Uses stamp address (not mesh) since docs-internal is not on the service mesh.
14+
# See https://thehub.github.com/epd/engineering/dev-practicals/observability/distributed-tracing/instrumentation/
15+
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: 'https://otelcol.service.%stamp%.github.net/v1/traces'

config/moda/configuration/production/env.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ data:
1212
# Identifies the service deployment environment as production
1313
# Equivalent to HEAVEN_DEPLOYED_ENV === 'production'
1414
MODA_PROD_SERVICE_ENV: 'true'
15+
# OTel distributed tracing — sends spans to OTel Collector via OTLP/HTTP (proto).
16+
# Uses stamp address (not mesh) since docs-internal is not on the service mesh.
17+
# See https://thehub.github.com/epd/engineering/dev-practicals/observability/distributed-tracing/instrumentation/
18+
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: 'https://otelcol.service.%stamp%.github.net/v1/traces'

config/moda/secrets/production/secrets.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,8 @@ secrets:
6464
type: hydro_api_key
6565
owner: '@github/docs-engineering'
6666
externally_usable: true
67+
OTEL_EXPORTER_OTLP_TRACES_HEADERS:
68+
kind: latest_at_deployment_start
69+
type: salt
70+
owner: '@github/docs-engineering'
71+
externally_usable: true

next.config.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ const config: NextConfig = {
1515
// Transpile @primer/react so Next's webpack can process its CSS and other assets
1616
// This ensures CSS in node_modules/@primer/react is handled by the app's loaders.
1717
transpilePackages: ['@primer/react'],
18+
// Keep OTel packages out of the Next.js server bundle.
19+
// They must be loaded via native require() for auto-instrumentation to work.
20+
serverExternalPackages: [
21+
'@opentelemetry/api',
22+
'@opentelemetry/auto-instrumentations-node',
23+
'@opentelemetry/core',
24+
'@opentelemetry/exporter-trace-otlp-proto',
25+
'@opentelemetry/sdk-node',
26+
],
1827
// speed up production `next build` by ignoring typechecking during that step of build.
1928
// type-checking still occurs in the Dockerfile build
2029
typescript: {
@@ -48,8 +57,15 @@ const config: NextConfig = {
4857
})
4958
},
5059

51-
webpack: (webpackConfig) => {
60+
webpack: (webpackConfig, { isServer }) => {
5261
webpackConfig.resolve.fallback = { fs: false, async_hooks: false }
62+
// OTel is server-only. Alias to empty stub in browser bundles.
63+
if (!isServer) {
64+
webpackConfig.resolve.alias = {
65+
...webpackConfig.resolve.alias,
66+
'@/observability/lib/tracing': path.resolve('./src/observability/lib/tracing.browser.ts'),
67+
}
68+
}
5369
return webpackConfig
5470
},
5571

@@ -71,6 +87,9 @@ const config: NextConfig = {
7187
'@/observability/logger/lib/logger-context': {
7288
browser: './empty.ts',
7389
},
90+
'@/observability/lib/tracing': {
91+
browser: './src/observability/lib/tracing.browser.ts',
92+
},
7493
},
7594
},
7695

0 commit comments

Comments
 (0)