GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Implement span started and live health metrics by JonasKunz · Pull Request #7430 · open-telemetry/opentelemetry-java

Conversation

@JonasKunz

@JonasKunz JonasKunz commented Jun 18, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Implements the semantic conventions SDK health metrics otel.sdk.span.live and otel.sdk.span.endedotel.sdk.span.started metrics.

Follows the approach of #7265 that these metrics are currently disabled by default, but can be enabled via the SdkTracerProviderBuilder.

Some examples of insights gained from these metrics:

  • The effective span sampling rate
  • Detection of span-leaks due to missing end() calls (via a steadily increasing otel.sdk.span.live count)
  • Mis-configured / Mis-instrumentation detection indication via excessive span counts

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
JonasKunz added 3 commits June 18, 2025 12:33
@JonasKunz
Implement span live and ended metrics
e3b403d
@JonasKunz
Fix toString internalTelemetrySchemaVersion left-overs
393786e
@JonasKunz
Rebase fixes
8ffc6c7
JonasKunz
JonasKunz commented Jun 18, 2025
View reviewed changes
Comment thread exporters/common/src/main/java/io/opentelemetry/exporter/internal/grpc/GrpcExporterBuilder.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@codecov

codecov Bot commented Jun 18, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.42308% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.08%. Comparing base (5772c1d) to head (e05ea4b).
⚠️ Report is 19 commits behind head on main.

Files with missing lines Patch % Lines
...sdk/trace/internal/SemConvSpanInstrumentation.java 89.55% 4 Missing and 3 partials ⚠️
...ava/io/opentelemetry/sdk/trace/SdkSpanBuilder.java 50.00% 1 Missing and 1 partial ⚠️
...emetry/sdk/trace/internal/SpanInstrumentation.java 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main    #7430   +/-   ##
=========================================
  Coverage     90.08%   90.08%           
- Complexity     7325     7350   +25     
=========================================
  Files           825      828    +3     
  Lines         22051    22149   +98     
  Branches       2179     2186    +7     
=========================================
+ Hits          19865    19954   +89     
- Misses         1506     1510    +4     
- Partials        680      685    +5     

☔ View full report in Codecov by Sentry.
📢 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.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JonasKunz added 2 commits June 18, 2025 13:50
@JonasKunz
Add test for NonRecordingSpan
54d80c0
@JonasKunz
Rename method after copy pasta
be0d766
JonasKunz
JonasKunz commented Jun 18, 2025
View reviewed changes
Comment thread sdk/trace/src/test/java/io/opentelemetry/sdk/trace/NonRecordingSpanTest.java Outdated

@Test
void doNotCrash() {
Span span = new NonRecordingSpan(DUMMY_CONTEXT, mockRecording);

@JonasKunz JonasKunz Jun 18, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This test is pretty much a copy of PropagatedSpanTest.doNotCrash. I don't think it's very useful, but it keeps the CodeCov bot happy

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jack-berg reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@JonasKunz
JonasKunz marked this pull request as ready for review June 18, 2025 12:19
@JonasKunz
JonasKunz requested a review from a team as a code owner June 18, 2025 12:19
jack-berg
jack-berg reviewed Jun 27, 2025
View reviewed changes

@jack-berg jack-berg left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Solid stuff. One recommendation about renaming to *Instrumentation - since there's going to be more and more internal telemetry, we should try to standardize naming / patterns where we can.

Thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JonasKunz reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkTracerProviderBuilder.java Outdated
* Sets the {@link MeterProvider} supplier used to collect self-monitoring metrics. If not set,
* uses {@link GlobalOpenTelemetry#getMeterProvider()}.
*/
public SdkTracerProviderBuilder setMeterProvider(Supplier<MeterProvider> meterProviderSupplier) {

@jack-berg jack-berg Jun 25, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I know this is the contract of other components, but I wonder if we may want to think bigger, and start accepting Supplier<OpenTelemetry> for internal monitoring. That would position us well if there are semantic conventions that involve emitting traces or logs or events for internal monitoring.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JonasKunz reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@JonasKunz JonasKunz Jun 30, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Fixed in 74fdbae. I changed it just at the API-level, the implementation still directly uses Supplier<MeterProvider> for now, because this is the only part used currently..

I went for setInternalTelemetryOpenTelemetry as name, because I feel setOpenTelemetry would be confusing: It could make it look like the counterpart to SdkOpenTelemetryBuilder.setTracerProvider.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread sdk/trace/src/main/java/io/opentelemetry/sdk/trace/internal/metrics/SpanMetrics.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkTracerProvider.java Outdated
this.tracerConfigurator = tracerConfigurator;
}

private static SpanMetrics createSpanMetrics(

@jack-berg jack-berg Jun 27, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Let's follow the pattern of ExporterInstrumentation:

  • Let's have a class called SpanInstrumentation (or maybe TracerProviderInstrumentation)
  • Class should have a constructor which accepts InternalTelemetryVersion and Supplier<MeterProvider> and initializes accordingly.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@JonasKunz JonasKunz Jun 30, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Changed in 6f4b0af.

However, I kept SpanInstrumentation as an interface instead of class with a static create method for now: It doesn't contain any logic except for create, which is why I think making it a class and adding delegation like ExporterInstrumentation would be unnecessary boilerplate. It however does allow us to change to this model later if we need it without touching the consumers of SpanInstrumentation.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread sdk/trace/src/main/java/io/opentelemetry/sdk/trace/NonRecordingSpan.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread sdk/trace/src/main/java/io/opentelemetry/sdk/trace/internal/metrics/SemConvSpanMetrics.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread sdk/trace/src/main/java/io/opentelemetry/sdk/trace/internal/metrics/SemConvSpanMetrics.java

@Override
public synchronized void recordSpanEnd() {
if (endAlreadyReported) {

@jack-berg jack-berg Jun 27, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Should we mark endAlreadyReported concurrent safe? If a span is ended multiple times on different threads, then the state of these metrics could become corrupted. On the other hand, SdkSpan#endInternal is already protected by a lock, so the only thing that could cause is is concurrent calls to end a span + NonRecordSpan, which isn't protected by a lock.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@JonasKunz JonasKunz Jun 30, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I added a @GuardedBy("this"), is this what you meant? It was already concurrent safe because recordSpanEnd() is synchronized.
Also this is in fact necessary, because for NonRecordingSpan end() isn't synchronized.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread sdk/trace/src/test/java/io/opentelemetry/sdk/trace/SdkSpanBuilderTest.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@JonasKunz JonasKunz mentioned this pull request Jun 30, 2025
Replace otel.sdk.span.ended metric with improved span.started metric open-telemetry/semantic-conventions#2431
Merged
2 of 3 tasks
JonasKunz added 4 commits June 30, 2025 10:29
@JonasKunz
Use OpenTelemetry at configuration level instead of MeterProvider
74fdbae
@JonasKunz
Fix NonRecordingSpan javadoc
44cccc8
@JonasKunz
Change pattern to SpanInstrumentation
6f4b0af
@JonasKunz
Remaining review fixes
f42b0ad
@JonasKunz
JonasKunz requested a review from jack-berg June 30, 2025 14:00
@JonasKunz

JonasKunz commented Jun 30, 2025

Copy link
Copy Markdown
Contributor Author

I'm moving this back to draft, because this implementation actally violates the spec. See this comment.

We'll fix the definition of the metrics first on that Sem-Conv PR, and then update this one after reaching consensus there.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JonasKunz
JonasKunz marked this pull request as draft June 30, 2025 14:34
JonasKunz added 2 commits July 3, 2025 11:20
@JonasKunz
Replace span.ended with span.started, add parent.origin attrib
6420714
@JonasKunz
Merge remote-tracking branch 'otel/HEAD' into span-start-end-metrics
24a7a0a
@JonasKunz JonasKunz changed the title Implement span ended and live health metrics Implement span started and live health metrics Jul 3, 2025
@JonasKunz
JonasKunz marked this pull request as ready for review July 3, 2025 09:38
@JonasKunz

JonasKunz commented Jul 3, 2025

Copy link
Copy Markdown
Contributor Author

Ready for review again, as the spec changes from this merged semconv PR have now been applied:

  • The otel.sdk.span.ended metric was replaced with otel.sdk.span.started
  • otel.sdk.span.live was changed to not be collected for non-recording spans
  • Added a new otel.span.parent.origin to otel.sdk.span.started. This allows us to derive many cool insights, such as:
    • average number of spans per trace
    • effective trace sampling rate (versus the effective span-sampling rate)
    • effective trace sampling rate for traces starting in the current service
    • effective trace sampling rate for traces with a remote parent
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JonasKunz JonasKunz mentioned this pull request Jul 17, 2025
Implement semconv span processor health metrics #7441
Closed
JonasKunz added 4 commits July 17, 2025 16:09
@JonasKunz
Merge remote-tracking branch 'otel/main' into span-start-end-metrics
823133c
# Conflicts:
#	docs/apidiffs/current_vs_latest/opentelemetry-sdk-trace.txt
#	sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkTracerProviderBuilder.java
@JonasKunz
Merge remote-tracking branch 'otel/HEAD' into span-start-end-metrics
7c2cb54
# Conflicts:
#	docs/apidiffs/current_vs_latest/opentelemetry-sdk-trace.txt
@JonasKunz
Run jApiCmp
ebc1410
@JonasKunz
Fix toString tests for renamed internal property
e05ea4b
@jack-berg jack-berg mentioned this pull request Dec 11, 2025
Implement SDK metrics for trace #7895
Merged
@JonasKunz

JonasKunz commented Dec 12, 2025

Copy link
Copy Markdown
Contributor Author

Closing in favor of #7895.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JonasKunz JonasKunz closed this Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@jack-berg jack-berg Awaiting requested review from jack-berg

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@JonasKunz @jack-berg
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.