Skip to content

[DO NOT MERGE] Add incubating span type - #8991

Draft
lmolkova wants to merge 1 commit into
open-telemetry:mainfrom
lmolkova:span-type
Draft

lmolkova wants to merge 1 commit into
open-telemetry:mainfrom
lmolkova:span-type

Conversation

@lmolkova

Copy link
Copy Markdown
Member

Implements opentelemetry-specification#5378.

Changes

  • ExtendedSpanBuilder.setType(String) in the API incubator.
  • The SDK validates the type before sampling. Invalid types are logged and dropped.
  • Processors and exporters read the type through internal ExtendedReadableSpan and ExtendedSpanData.
  • No exporter changes. OTLP needs opentelemetry-proto#884.

Open question

To read the type, exporters will cast to ExtendedSpanData, an internal interface in sdk-trace. OTLP already does this for metric data and resource entities, and event name did it before it was stable. Is there a better option?

Benchmarks

SpanRecordBenchmark sets a 48-character type on every span, the longest span type in semantic conventions. Single thread, ops/s:

Span size main this PR Change
SMALL, no attributes 7.79M ± 0.23M 5.76M ± 0.08M -26%
MEDIUM, 10 attributes 1.15M ± 0.06M 1.12M ± 0.04M -2%
LARGE, 100 attributes 119K ± 2.6K 120K ± 2.4K +1%

Spans that need a type usually have several attributes, so SMALL doesn't reflect real use. For scale, the first attribute on a SMALL span costs +10 ns and +440 B. Span type costs +45 ns and +8 B.

@opentelemetry-pr-dashboard

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-10-31 02:33 UTC

Move out of draft to request review.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Logging unbounded rejected span types allocates memory proportional to their length on every span creation, even when logs are throttled, so the logged value needs truncation.

1 open issue
What changed in this PR

Adds incubating span-type support to the tracing API and SDK, exposing validated types to processors and exporters through internal interfaces. Exporter serialization remains unchanged.

Changes:

  • Adds ExtendedSpanBuilder.setType(String) and validates types before sampling.
  • Preserves span types in SDK spans and exposes them through readable-span and span-data interfaces.
  • Adds validation tests and benchmarks with optional span types.
File Description
sdk/​trace/​src/​testIncubating/​java/​io/​opentelemetry/​sdk/​trace/​SpanTypeTest.java Tests type validation, builder behavior, and data exposure.
sdk/​trace/​src/​test/​java/​io/​opentelemetry/​sdk/​trace/​SdkSpanTest.java Updates span construction for the type parameter.
sdk/​trace/​src/​test/​java/​io/​opentelemetry/​sdk/​trace/​SdkSpanBuilderTest.java Updates expected span-data string output.
sdk/​trace/​src/​main/​java/​io/​opentelemetry/​sdk/​trace/​SpanWrapper.java Exposes the type through exported span data.
sdk/​trace/​src/​main/​java/​io/​opentelemetry/​sdk/​trace/​SdkSpanBuilder.java Stores, validates, and passes types to spans.
sdk/​trace/​src/​main/​java/​io/​opentelemetry/​sdk/​trace/​SdkSpan.java Stores and exposes the immutable span type.
sdk/​trace/​src/​main/​java/​io/​opentelemetry/​sdk/​trace/​internal/​ExtendedSpanData.java Defines experimental span-data type access.
sdk/​trace/​src/​main/​java/​io/​opentelemetry/​sdk/​trace/​internal/​ExtendedReadableSpan.java Defines experimental readable-span type access.
sdk/​trace/​src/​main/​java/​io/​opentelemetry/​sdk/​trace/​ExtendedSdkSpanBuilder.java Implements the fluent incubating type setter.
sdk/​all/​src/​jmh/​java/​io/​opentelemetry/​sdk/​SpanRecordBenchmark.java Benchmarks recording with and without types.
api/​incubator/​src/​test/​java/​io/​opentelemetry/​api/​incubator/​trace/​ExtendedDefaultTracerTest.java Tests no-op type-setter behavior.
api/​incubator/​src/​main/​java/​io/​opentelemetry/​api/​incubator/​trace/​ExtendedSpanBuilder.java Adds and documents the incubating type setter.

Review effort: Balanced

logger.log(
Level.WARNING,
"Span type \""
+ validatedType
@codecov

codecov Bot commented Oct 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.14286% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.39%. Comparing base (dc3019e) to head (95fb9fd).

Files with missing lines Patch % Lines
...ava/io/opentelemetry/sdk/trace/SdkSpanBuilder.java 96.29% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8991      +/-   ##
============================================
+ Coverage     90.36%   90.39%   +0.02%     
- Complexity    10995    11019      +24     
============================================
  Files          1020     1020              
  Lines         30096    30130      +34     
  Branches       3929     3937       +8     
============================================
+ Hits          27197    27235      +38     
+ Misses         1942     1937       -5     
- Partials        957      958       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

2 participants