-
Notifications
You must be signed in to change notification settings - Fork 902
Implement span started and live health metrics #7430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
e3b403d
393786e
8ffc6c7
54d80c0
be0d766
74fdbae
44cccc8
6f4b0af
f42b0ad
6420714
24a7a0a
823133c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
Comparing source compatibility of opentelemetry-sdk-trace-1.52.0-SNAPSHOT.jar against opentelemetry-sdk-trace-1.51.0.jar | ||
No changes. | ||
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.trace.SdkTracerProviderBuilder (not serializable) | ||
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0 | ||
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.trace.SdkTracerProviderBuilder setInternalTelemetry(io.opentelemetry.sdk.common.InternalTelemetryVersion) | ||
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.trace.SdkTracerProviderBuilder setMeterProvider(java.util.function.Supplier<io.opentelemetry.api.metrics.MeterProvider>) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.trace; | ||
|
||
import io.opentelemetry.api.common.AttributeKey; | ||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.api.trace.Span; | ||
import io.opentelemetry.api.trace.SpanContext; | ||
import io.opentelemetry.api.trace.StatusCode; | ||
import io.opentelemetry.sdk.trace.internal.metrics.SpanMetrics; | ||
import java.util.concurrent.TimeUnit; | ||
import javax.annotation.Nullable; | ||
import javax.annotation.concurrent.Immutable; | ||
|
||
/** | ||
* Span implementation used from {@link io.opentelemetry.sdk.trace.SdkTracer} when starting a span | ||
* which is not recording. All operations are noop, except for {@link #end()}, which ensures health | ||
JonasKunz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* metrics are still collected. | ||
*/ | ||
@Immutable | ||
final class NonRecordingSpan implements Span { | ||
|
||
private final SpanContext spanContext; | ||
private final SpanMetrics.Recording metricRecording; | ||
|
||
NonRecordingSpan(SpanContext spanContext, SpanMetrics.Recording metricRecording) { | ||
this.spanContext = spanContext; | ||
this.metricRecording = metricRecording; | ||
} | ||
|
||
@Override | ||
public Span setAttribute(String key, @Nullable String value) { | ||
return this; | ||
} | ||
|
||
@Override | ||
public Span setAttribute(String key, long value) { | ||
return this; | ||
} | ||
|
||
@Override | ||
public Span setAttribute(String key, double value) { | ||
return this; | ||
} | ||
|
||
@Override | ||
public Span setAttribute(String key, boolean value) { | ||
return this; | ||
} | ||
|
||
@Override | ||
public <T> Span setAttribute(AttributeKey<T> key, @Nullable T value) { | ||
return this; | ||
} | ||
|
||
@Override | ||
public Span setAllAttributes(Attributes attributes) { | ||
return this; | ||
} | ||
|
||
@Override | ||
public Span addEvent(String name) { | ||
return this; | ||
} | ||
|
||
@Override | ||
public Span addEvent(String name, long timestamp, TimeUnit unit) { | ||
return this; | ||
} | ||
|
||
@Override | ||
public Span addEvent(String name, Attributes attributes) { | ||
return this; | ||
} | ||
|
||
@Override | ||
public Span addEvent(String name, Attributes attributes, long timestamp, TimeUnit unit) { | ||
return this; | ||
} | ||
|
||
@Override | ||
public Span setStatus(StatusCode statusCode) { | ||
return this; | ||
} | ||
|
||
@Override | ||
public Span setStatus(StatusCode statusCode, String description) { | ||
return this; | ||
} | ||
|
||
@Override | ||
public Span recordException(Throwable exception) { | ||
return this; | ||
} | ||
|
||
@Override | ||
public Span recordException(Throwable exception, Attributes additionalAttributes) { | ||
return this; | ||
} | ||
|
||
@Override | ||
public Span updateName(String name) { | ||
return this; | ||
} | ||
|
||
@Override | ||
public void end() { | ||
metricRecording.recordSpanEnd(); | ||
} | ||
|
||
@Override | ||
public void end(long timestamp, TimeUnit unit) { | ||
end(); | ||
} | ||
|
||
@Override | ||
public SpanContext getSpanContext() { | ||
return spanContext; | ||
} | ||
|
||
@Override | ||
public boolean isRecording() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "NonRecordingSpan{" + spanContext + '}'; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,18 +5,22 @@ | |
|
||
package io.opentelemetry.sdk.trace; | ||
|
||
import io.opentelemetry.api.metrics.MeterProvider; | ||
import io.opentelemetry.api.trace.Tracer; | ||
import io.opentelemetry.api.trace.TracerBuilder; | ||
import io.opentelemetry.api.trace.TracerProvider; | ||
import io.opentelemetry.sdk.common.Clock; | ||
import io.opentelemetry.sdk.common.CompletableResultCode; | ||
import io.opentelemetry.sdk.common.InstrumentationScopeInfo; | ||
import io.opentelemetry.sdk.common.InternalTelemetryVersion; | ||
import io.opentelemetry.sdk.internal.ComponentRegistry; | ||
import io.opentelemetry.sdk.internal.ExceptionAttributeResolver; | ||
import io.opentelemetry.sdk.internal.ScopeConfigurator; | ||
import io.opentelemetry.sdk.resources.Resource; | ||
import io.opentelemetry.sdk.trace.internal.SdkTracerProviderUtil; | ||
import io.opentelemetry.sdk.trace.internal.TracerConfig; | ||
import io.opentelemetry.sdk.trace.internal.metrics.SemConvSpanMetrics; | ||
import io.opentelemetry.sdk.trace.internal.metrics.SpanMetrics; | ||
import io.opentelemetry.sdk.trace.samplers.Sampler; | ||
import java.io.Closeable; | ||
import java.util.List; | ||
|
@@ -54,7 +58,9 @@ | |
Sampler sampler, | ||
List<SpanProcessor> spanProcessors, | ||
ScopeConfigurator<TracerConfig> tracerConfigurator, | ||
ExceptionAttributeResolver exceptionAttributeResolver) { | ||
ExceptionAttributeResolver exceptionAttributeResolver, | ||
InternalTelemetryVersion internalTelemetryVersion, | ||
Supplier<MeterProvider> meterProviderSupplier) { | ||
this.sharedState = | ||
new TracerSharedState( | ||
clock, | ||
|
@@ -63,7 +69,8 @@ | |
spanLimitsSupplier, | ||
sampler, | ||
spanProcessors, | ||
exceptionAttributeResolver); | ||
exceptionAttributeResolver, | ||
createSpanMetrics(internalTelemetryVersion, meterProviderSupplier)); | ||
this.tracerSdkComponentRegistry = | ||
new ComponentRegistry<>( | ||
instrumentationScopeInfo -> | ||
|
@@ -74,6 +81,19 @@ | |
this.tracerConfigurator = tracerConfigurator; | ||
} | ||
|
||
private static SpanMetrics createSpanMetrics( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's follow the pattern of
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed in 6f4b0af. However, I kept |
||
InternalTelemetryVersion internalTelemetryVersion, | ||
Supplier<MeterProvider> meterProviderSupplier) { | ||
switch (internalTelemetryVersion) { | ||
case LEGACY: | ||
return SpanMetrics.noop(); | ||
case LATEST: | ||
return new SemConvSpanMetrics(meterProviderSupplier); | ||
} | ||
throw new IllegalStateException( | ||
"Unhandled telemetry schema version: " + internalTelemetryVersion); | ||
} | ||
|
||
private TracerConfig getTracerConfig(InstrumentationScopeInfo instrumentationScopeInfo) { | ||
TracerConfig tracerConfig = tracerConfigurator.apply(instrumentationScopeInfo); | ||
return tracerConfig == null ? TracerConfig.defaultConfig() : tracerConfig; | ||
|
Uh oh!
There was an error while loading. Please reload this page.