豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

feat(ext/telemetry): copy relevant span attributes to HTTP metrics#32720

Merged
bartlomieju merged 5 commits intodenoland:mainfrom
bartlomieju:otel-http-span-attribute-metrics
Mar 19, 2026
Merged

feat(ext/telemetry): copy relevant span attributes to HTTP metrics#32720
bartlomieju merged 5 commits intodenoland:mainfrom
bartlomieju:otel-http-span-attribute-metrics

Conversation

@bartlomieju
Copy link
Copy Markdown
Member

Summary

Supersedes #28476. Reimplemented from scratch on current main following the same design proposed in #28445.

  • Create the HTTP server OTel span in Rust and store it on HttpRecord, so it can be shared with JavaScript
  • Expose the span to JS via op_http_get_span — frameworks/users can set attributes like http.route on it
  • Before the span ends, op_http_copy_span_attributes_to_otel_info copies http.route from the span to OtelInfo for metrics
  • Add http.route to the HTTP server duration histogram and other metric attributes

This enables the workflow described in #28445: a router sets http.route on the auto-instrumented span, and that attribute automatically appears on http.server.request.duration and other HTTP metrics.

Key changes

File Change
ext/telemetry/lib.rs Make OtelSpan Clone-able (Rc-wrapped), public; export OtelSpanState, SpanData, SpanContext, etc.
ext/http/service.rs Create span in handle_request, store on HttpRecord, add get_otel_span + copy_span_attributes_to_otel_info methods
ext/http/http_next.rs Add op_http_get_span and op_http_copy_span_attributes_to_otel_info ops
ext/http/lib.rs Add http.route field to OtelInfoAttributes, include in histogram attributes
ext/http/00_serve.ts Use Rust-created span when available, call copy op before span end
ext/telemetry/telemetry.ts Export Span class and SPAN_KEY

Closes #28445

Test plan

  • Existing otel_basic spec tests pass (HTTP metrics still work)
  • Manual test: set http.route on span in handler, verify it appears in metric attributes
  • Add spec test for http.route in metrics

🤖 Generated with Claude Code

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>
bartlomieju and others added 2 commits March 15, 2026 13:10
…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 bartlomieju changed the title feat(http): copy relevant span attributes to HTTP metrics feat(ext/telemetry): copy relevant span attributes to HTTP metrics Mar 16, 2026
Comment thread ext/http/00_serve.ts Outdated
bartlomieju and others added 2 commits March 19, 2026 14:26
- 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>
@bartlomieju bartlomieju enabled auto-merge (squash) March 19, 2026 14:59
@bartlomieju bartlomieju merged commit af16b8a into denoland:main Mar 19, 2026
112 checks passed
@bartlomieju bartlomieju deleted the otel-http-span-attribute-metrics branch March 19, 2026 15:06
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.

[otel] Add support for specifying http.route on automatic HTTP server metrics

2 participants