feat(otel): add Vercel handler instrumentation for distributed tracing#163
Draft
Schniz wants to merge 1 commit into
Draft
feat(otel): add Vercel handler instrumentation for distributed tracing#163Schniz wants to merge 1 commit into
Schniz wants to merge 1 commit into
Conversation
Implements OpenTelemetry instrumentation for Vercel handlers by patching the Node.js HTTP Server's emit method to automatically extract trace context from incoming request headers and propagate it through the request lifecycle. 🤖 Generated with [opencode](https://opencode.ai)
Contributor
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
lucleray
reviewed
Aug 8, 2025
| extends InstrumentationConfig {} | ||
|
|
||
| export class VercelHandlerInstrumentation implements Instrumentation { | ||
| instrumentationName = "@vercel/otel/handlers"; |
Member
There was a problem hiding this comment.
Nit, to be more inline with the class name/file name (also it's more clear what it is):
Suggested change
| instrumentationName = "@vercel/otel/handlers"; | |
| instrumentationName = "@vercel/otel/vercel-handler"; |
lucleray
reviewed
Aug 8, 2025
| export class VercelHandlerInstrumentation implements Instrumentation { | ||
| instrumentationName = "@vercel/otel/handlers"; | ||
| instrumentationVersion = "1.0.0"; | ||
| instrumentationDescription?: string; |
lucleray
reviewed
Aug 8, 2025
| instrumentationVersion = "1.0.0"; | ||
| instrumentationDescription?: string; | ||
|
|
||
| traceProvider?: TracerProvider; |
Member
There was a problem hiding this comment.
Typo i think (tracerProvider):
Suggested change
| traceProvider?: TracerProvider; | |
| tracerProvider?: TracerProvider; |
lucleray
reviewed
Aug 8, 2025
| instrumentationDescription?: string; | ||
|
|
||
| traceProvider?: TracerProvider; | ||
| supportedVersions?: string[]; |
lucleray
reviewed
Aug 8, 2025
| if (isEnabled() && event === "request") { | ||
| const request = args[0]; | ||
| console.log("instrumenting request", request.headers); | ||
| const c = propagation.extract(context.active(), request.headers); |
Member
There was a problem hiding this comment.
Question: should we be a bit more defensive here:
- what if
requestis undefined or null? - what if
request.headersis undefined or null?
lucleray
reviewed
Aug 8, 2025
| const next = () => emit.call(this, event, ...args); | ||
| if (isEnabled() && event === "request") { | ||
| const request = args[0]; | ||
| console.log("instrumenting request", request.headers); |
Member
There was a problem hiding this comment.
Suggested change
| console.log("instrumenting request", request.headers); |
dvoytenko
reviewed
Aug 18, 2025
| if (isEnabled() && event === "request") { | ||
| const request = args[0]; | ||
| console.log("instrumenting request", request.headers); | ||
| const c = propagation.extract(context.active(), request.headers); |
Member
There was a problem hiding this comment.
You might need to provide a custom header reader here. I don't quite remember the exact request.headers API - is it always a simple Record<string, string>?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements OpenTelemetry instrumentation for Vercel handlers by patching
the Node.js HTTP Server's emit method to automatically extract trace
context from incoming request headers and propagate it through the
request lifecycle.
🤖 Generated with opencode