feat(ext/telemetry): copy relevant span attributes to HTTP metrics#32720
Merged
bartlomieju merged 5 commits intodenoland:mainfrom Mar 19, 2026
Merged
Conversation
Allow users to set attributes like `http.route` on the automatically instrumented HTTP server span, and have those attributes reflected in the HTTP server metrics (duration histogram, request/response size). The HTTP server span is now created in Rust and stored on HttpRecord, then exposed to JavaScript via `op_http_get_span`. When the response is finalized, `op_http_copy_span_attributes_to_otel_info` reads `http.route` from the span and copies it to OtelInfo for metrics. Key changes: - Make OtelSpan cloneable (Rc-wrapped) and public - Export OtelSpanState, SpanData, SpanContext, etc. from deno_telemetry - Create HTTP span in Rust (service.rs handle_request) - Add ops: op_http_get_span, op_http_copy_span_attributes_to_otel_info - Add http.route to OtelInfoAttributes and histogram metrics - Export Span class and SPAN_KEY from telemetry.ts Closes denoland#28445 Co-Authored-By: Leo Kettmeir <crowlkats@users.noreply.github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…et_span The previous approach created the OTel span in Rust, which broke trace context propagation and deterministic ID generation. This moves span creation back to JS and stores it on the HttpRecord via op_http_set_span so attributes can be copied to metrics. Still needs: move op_http_copy_span_attributes_to_otel_info call to before the request external is invalidated (currently panics in finally). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
bartlomieju
commented
Mar 19, 2026
# Conflicts: # ext/telemetry/lib.rs
- Remove op_http_set_span and otel_span field from HttpRecord - Instead, copy span attributes to OtelInfo in JS after the handler returns (before the request external is invalidated) - Add op_http_copy_span_to_otel_info that takes the span directly - Add http_route spec test verifying http.route appears in both spans and metrics when set via @opentelemetry/api Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
crowlKats
approved these changes
Mar 19, 2026
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
Supersedes #28476. Reimplemented from scratch on current
mainfollowing the same design proposed in #28445.HttpRecord, so it can be shared with JavaScriptop_http_get_span— frameworks/users can set attributes likehttp.routeon itop_http_copy_span_attributes_to_otel_infocopieshttp.routefrom the span toOtelInfofor metricshttp.routeto the HTTP server duration histogram and other metric attributesThis enables the workflow described in #28445: a router sets
http.routeon the auto-instrumented span, and that attribute automatically appears onhttp.server.request.durationand other HTTP metrics.Key changes
ext/telemetry/lib.rsOtelSpanClone-able (Rc-wrapped), public; exportOtelSpanState,SpanData,SpanContext, etc.ext/http/service.rshandle_request, store onHttpRecord, addget_otel_span+copy_span_attributes_to_otel_infomethodsext/http/http_next.rsop_http_get_spanandop_http_copy_span_attributes_to_otel_infoopsext/http/lib.rshttp.routefield toOtelInfoAttributes, include in histogram attributesext/http/00_serve.tsext/telemetry/telemetry.tsSpanclass andSPAN_KEYCloses #28445
Test plan
otel_basicspec tests pass (HTTP metrics still work)http.routeon span in handler, verify it appears in metric attributeshttp.routein metrics🤖 Generated with Claude Code