feat: inject traceparent meta tag when OpenTelemetry is active#3729
Merged
Conversation
When an OTel exporter is configured, Fresh now automatically adds a
<meta name="traceparent"> tag to the <head> of rendered HTML pages.
This enables client-side OTel instrumentation (e.g.,
@opentelemetry/instrumentation-document-load) to connect browser
traces to the server-side span that rendered the page.
The tag follows the W3C Trace Context format:
<meta name="traceparent" content="00-{traceId}-{spanId}-{flags}">
Only injected when a valid span context exists (real OTel exporter
configured), so there is zero overhead when OTel is not in use.
Closes #2830
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move `as any` cast to a single line so the deno-lint-ignore directive covers it, fixing ban-unused-ignore and no-explicit-any errors on CI. Also document the new traceparent meta tag injection in the OpenTelemetry docs page. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The ignore directive only applies to the immediately following line. After formatting, `items.push(` was on its own line, so the directive covered that instead of the `as any` cast. Move the comment inside the push() call, directly above the line that needs it. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
npmjs.com returns 403 to automated link checkers. Link to the OpenTelemetry GitHub repo instead. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The package is under packages/, not plugins/web/. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
When an OpenTelemetry exporter is configured, Fresh now automatically injects a
<meta name="traceparent">tag into the<head>of rendered HTML pages. This enables client-side OTel instrumentation (e.g.,@opentelemetry/instrumentation-document-load) to connect browser performance traces to the server-side span that rendered the page.Output example
How it works
<head>rendering inpreact_hooks.ts, checks for an active OTel span viatrace.getActiveSpan()isSpanContextValid()to ensure a real exporter is configured (not the no-op default)<meta name="traceparent">tag in W3C Trace Context format:00-{traceId}-{spanId}-{traceFlags}getActiveSpan()returnsundefinedwith the no-op providerTest plan
deno test -A packages/fresh/src/app_test.tsx— 46 passeddeno test -A packages/fresh/src/fs_routes_test.tsx— 55 passedCloses #2830
🤖 Generated with Claude Code