Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion docs/apidiffs/current_vs_latest/opentelemetry-sdk-trace.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
Comparing source compatibility of opentelemetry-sdk-trace-1.58.0-SNAPSHOT.jar against opentelemetry-sdk-trace-1.57.0.jar
No changes.
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.trace.export.BatchSpanProcessorBuilder (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.trace.export.BatchSpanProcessorBuilder setInternalTelemetryVersion(io.opentelemetry.sdk.common.InternalTelemetryVersion)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.trace.export.BatchSpanProcessorBuilder setMeterProvider(java.util.function.Supplier<io.opentelemetry.api.metrics.MeterProvider>)
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.trace.export.SimpleSpanProcessorBuilder (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.trace.export.SimpleSpanProcessorBuilder setMeterProvider(java.util.function.Supplier<io.opentelemetry.api.metrics.MeterProvider>)
*** 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 setMeterProvider(java.util.function.Supplier<io.opentelemetry.api.metrics.MeterProvider>)
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ static void configureTracerProvider(
List<Closeable> closeables) {

tracerProviderBuilder.setSpanLimits(configureSpanLimits(config));
tracerProviderBuilder.setMeterProvider(() -> meterProvider);

String sampler = config.getString("otel.traces.sampler", PARENTBASED_ALWAYS_ON);
tracerProviderBuilder.setSampler(
Expand Down Expand Up @@ -80,7 +81,8 @@ static List<SpanProcessor> configureSpanProcessors(
for (String simpleProcessorExporterNames : simpleProcessorExporterNames) {
SpanExporter exporter = exportersByNameCopy.remove(simpleProcessorExporterNames);
if (exporter != null) {
SpanProcessor spanProcessor = SimpleSpanProcessor.create(exporter);
SpanProcessor spanProcessor =
SimpleSpanProcessor.builder(exporter).setMeterProvider(() -> meterProvider).build();
closeables.add(spanProcessor);
spanProcessors.add(spanProcessor);
}
Expand All @@ -101,7 +103,7 @@ static List<SpanProcessor> configureSpanProcessors(
static BatchSpanProcessor configureBatchSpanProcessor(
ConfigProperties config, SpanExporter exporter, MeterProvider meterProvider) {
BatchSpanProcessorBuilder builder =
BatchSpanProcessor.builder(exporter).setMeterProvider(meterProvider);
BatchSpanProcessor.builder(exporter).setMeterProvider(() -> meterProvider);

Duration scheduleDelay = config.getDuration("otel.bsp.schedule.delay");
if (scheduleDelay != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
import io.opentelemetry.sdk.trace.export.BatchSpanProcessorBuilder;
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessorBuilder;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import java.time.Duration;
import java.util.Map;
Expand Down Expand Up @@ -50,7 +51,7 @@ public SpanProcessor create(SpanProcessorModel model, DeclarativeConfigContext c
}
MeterProvider meterProvider = context.getMeterProvider();
if (meterProvider != null) {
builder.setMeterProvider(meterProvider);
builder.setMeterProvider(() -> meterProvider);
}

return context.addCloseable(builder.build());
Expand All @@ -62,7 +63,12 @@ public SpanProcessor create(SpanProcessorModel model, DeclarativeConfigContext c
FileConfigUtil.requireNonNull(
simpleModel.getExporter(), "simple span processor exporter");
SpanExporter spanExporter = SpanExporterFactory.getInstance().create(exporterModel, context);
return context.addCloseable(SimpleSpanProcessor.create(spanExporter));
SimpleSpanProcessorBuilder builder = SimpleSpanProcessor.builder(spanExporter);
MeterProvider meterProvider = context.getMeterProvider();
if (meterProvider != null) {
builder.setMeterProvider(() -> meterProvider);
}
return context.addCloseable(builder.build());
}

Map.Entry<String, Object> keyValue =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,15 +337,15 @@ void create_Configured() throws NoSuchFieldException, IllegalAccessException {
.extracting("meterProviderSharedState")
.isEqualTo(sharedState);

// Lazily initialized
assertThat(sdk)
.extracting("tracerProvider")
.extracting("delegate")
.extracting("sharedState")
.extracting("activeSpanProcessor")
.extracting("worker")
.extracting("processedSpansCounter")
.extracting("sdkMeter")
.extracting("meterProviderSharedState")
.isEqualTo(sharedState);
.extracting("spanProcessorInstrumentation")
.extracting("processedSpans")
.isNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ private SemConvAttributes() {}
AttributeKey.longKey("rpc.grpc.status_code");
public static final AttributeKey<Long> HTTP_RESPONSE_STATUS_CODE =
AttributeKey.longKey("http.response.status_code");

public static final AttributeKey<String> OTEL_SPAN_PARENT_ORIGIN =
AttributeKey.stringKey("otel.span.parent.origin");
public static final AttributeKey<String> OTEL_SPAN_SAMPLING_RESULT =
AttributeKey.stringKey("otel.span.sampling_result");
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,10 @@ void testAttributeKeys() {
.isEqualTo(RpcIncubatingAttributes.RPC_GRPC_STATUS_CODE);
assertThat(SemConvAttributes.HTTP_RESPONSE_STATUS_CODE)
.isEqualTo(HttpAttributes.HTTP_RESPONSE_STATUS_CODE);

assertThat(SemConvAttributes.OTEL_SPAN_PARENT_ORIGIN)
.isEqualTo(OtelIncubatingAttributes.OTEL_SPAN_PARENT_ORIGIN);
assertThat(SemConvAttributes.OTEL_SPAN_SAMPLING_RESULT)
.isEqualTo(OtelIncubatingAttributes.OTEL_SPAN_SAMPLING_RESULT);
}
}
15 changes: 12 additions & 3 deletions sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkSpan.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ final class SdkSpan implements ReadWriteSpan {
private final InstrumentationScopeInfo instrumentationScopeInfo;
// The start time of the span.
private final long startEpochNanos;
// Callback to run when span ends to record metrics.
private final Runnable recordEndMetrics;

// Lock used to internally guard the mutable state of this instance
private final Object lock = new Object();

Expand Down Expand Up @@ -132,7 +135,8 @@ private SdkSpan(
@Nullable AttributesMap attributes,
@Nullable List<LinkData> links,
int totalRecordedLinks,
long startEpochNanos) {
long startEpochNanos,
Runnable recordEndMetrics) {
this.context = context;
this.instrumentationScopeInfo = instrumentationScopeInfo;
this.parentSpanContext = parentSpanContext;
Expand All @@ -148,6 +152,7 @@ private SdkSpan(
this.startEpochNanos = startEpochNanos;
this.attributes = attributes;
this.spanLimits = spanLimits;
this.recordEndMetrics = recordEndMetrics;
}

/**
Expand All @@ -163,6 +168,7 @@ private SdkSpan(
* @param resource the resource associated with this span.
* @param attributes the attributes set during span creation.
* @param links the links set during span creation, may be truncated. The list MUST be immutable.
* @param recordEndMetrics a {@link Runnable} to run when the span is ended to record metrics.
* @return a new and started span.
*/
static SdkSpan startSpan(
Expand All @@ -180,7 +186,8 @@ static SdkSpan startSpan(
@Nullable AttributesMap attributes,
@Nullable List<LinkData> links,
int totalRecordedLinks,
long userStartEpochNanos) {
long userStartEpochNanos,
Runnable recordEndMetrics) {
boolean createdAnchoredClock;
AnchoredClock clock;
if (parentSpan instanceof SdkSpan) {
Expand Down Expand Up @@ -219,7 +226,8 @@ static SdkSpan startSpan(
attributes,
links,
totalRecordedLinks,
startEpochNanos);
startEpochNanos,
recordEndMetrics);
// Call onStart here instead of calling in the constructor to make sure the span is completely
// initialized.
if (spanProcessor.isStartRequired()) {
Expand Down Expand Up @@ -557,6 +565,7 @@ private void endInternal(long endEpochNanos) {
spanEndingThread = Thread.currentThread();
hasEnded = EndState.ENDING;
}
recordEndMetrics.run();
if (spanProcessor instanceof ExtendedSpanProcessor) {
ExtendedSpanProcessor extendedSpanProcessor = (ExtendedSpanProcessor) spanProcessor;
if (extendedSpanProcessor.isOnEndingRequired()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ public Span startSpan() {
/* remote= */ false,
tracerSharedState.isIdGeneratorSafeToSkipIdValidation());

Runnable recordEndSpanMetrics =
tracerSharedState.getTracerMetrics().startSpan(parentSpanContext, samplingDecision);

if (!isRecording(samplingDecision)) {
return Span.wrap(spanContext);
}
Expand Down Expand Up @@ -232,7 +235,8 @@ public Span startSpan() {
recordedAttributes,
currentLinks,
totalNumberOfLinksAdded,
startEpochNanos);
startEpochNanos,
recordEndSpanMetrics);
}

private AttributesMap attributes() {
Expand Down
Loading
Loading