Skip to content

feat(tracing): add OpenTelemetry tracing#3464

Merged
jnatten merged 1 commit into
masterfrom
feat/tracing
Jun 18, 2026
Merged

feat(tracing): add OpenTelemetry tracing#3464
jnatten merged 1 commit into
masterfrom
feat/tracing

Conversation

@jnatten

@jnatten jnatten commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@jnatten jnatten requested a review from a team June 17, 2026 07:41
Comment thread src/server/correlationFetch.ts Outdated
const correlationID = getCorrelationId();
if (!correlationID) return originalFetch(input, init);

const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : undefined));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ekstremt skudd fra hofta, men burde disse merges på en eller annen måte?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kan vel til og med slippe unna med å bare opprette headers fra init.headers og bare sende input videre?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Endret så denne ble lik som i ndla-frontend. Gjerne sjekk på nytt om det gjør det jeg tror det gjør 🤓

Comment thread src/server/spanNamingMiddleware.ts Outdated
import { trace } from "@opentelemetry/api";
import { NextFunction, Request, Response } from "express";

export const spanNamingMiddleware = (req: Request, _res: Response, next: NextFunction): void => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sånn migreringsmessig tipper jeg det er kulere å bruke RequestHandler-typen.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hva betyr migreringsmessig i denne konteksten sjef?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At vi slipper å få teite typefeil her når vi oppgraderer express

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Er det noe du vet kommer til å skje eller er dette defansivt i tilfelle express endrer signaturene på request handlerene sine?

Kan fikse either way altså, bare nysgjerrig.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutt defanstivt, jeg har null peiling!

Comment thread src/server/correlationContext.ts Outdated
Comment thread src/server/correlationFetch.ts Outdated
const correlationID = getCorrelationId();
if (!correlationID) return originalFetch(input, init);

const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : undefined));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kan vel til og med slippe unna med å bare opprette headers fra init.headers og bare sende input videre?

Run the OpenTelemetry Node SDK so the server emits HTTP server and
client spans and propagates W3C trace context downstream.

- Add an env-gated NodeSDK bootstrap, imported first so http and fetch
  are instrumented before use; off unless OTEL_EXPORTER_OTLP_ENDPOINT
  (or OTEL_TRACES_EXPORTER) is set.
- Add correlation-id middleware and a global fetch wrapper to read and
  forward X-Correlation-ID on server-side outgoing calls.
- Add correlationID and trace_id/span_id to logs.
- Name the server span after a low-cardinality route bucket.
- Add a SIGTERM handler that flushes spans on shutdown.
@jnatten jnatten requested a review from Jonas-C June 17, 2026 10:27
@jnatten jnatten merged commit f00e281 into master Jun 18, 2026
3 checks passed
@jnatten jnatten deleted the feat/tracing branch June 18, 2026 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants