Add OpenTelemetry tracing for websocket flows#916
Conversation
Claude ReviewCritical
Issues
Missing Tests
Documentation
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b170a43768
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| import { redisClientManager } from './redis/client'; | ||
|
|
||
| async function main() { | ||
| setupTracing(); |
There was a problem hiding this comment.
Initialize tracing before loading instrumented modules
setupTracing() is invoked inside main(), but all static imports run first; that means ./redis/client (which imports ioredis at module load) is loaded before registerInstrumentations({ instrumentations: [new IORedisInstrumentation()] }) runs in observability/tracing.ts. In this ordering, the ioredis patch is applied too late, so Redis spans are never emitted even though tracing is enabled.
Useful? React with 👍 / 👎.
| function attachTrace(event: unknown, span: ReturnType<typeof tracer.startSpan>): void { | ||
| const ctxWithSpan = trace.setSpan(otelContext.active(), span); | ||
| (event as Record<string, unknown>).__trace = injectTraceContext(ctxWithSpan); |
There was a problem hiding this comment.
Propagate trace context through GraphQL response extensions
attachTrace stores the carrier on a private __trace property of the event object, but subscription responses are serialized from schema-selected fields, so this property is not delivered to clients; the web client then looks for traceparent/tracestate/baggage in payload extensions/data and finds nothing. As a result, graphql.ws.message spans cannot inherit mutation/session context, breaking the intended end-to-end websocket trace linkage.
Useful? React with 👍 / 👎.
| @@ -0,0 +1,47 @@ | |||
| import { context as otelContext, propagation, type Context, defaultTextMapGetter, defaultTextMapSetter } from '@opentelemetry/api'; | |||
There was a problem hiding this comment.
Declare @opentelemetry/api in shared-schema dependencies
This new module imports @opentelemetry/api, but packages/shared-schema/package.json was not updated to declare that dependency. Relying on other workspaces to hoist it creates an undeclared transitive dependency and can fail in isolated workspace installs or stricter package manager layouts.
Useful? React with 👍 / 👎.
No description provided.