Skip to content

Commit 6dc848c

Browse files
committed
Non-public classes
1 parent 968ca7b commit 6dc848c

5 files changed

Lines changed: 185 additions & 177 deletions

File tree

docs/apidiffs/current_vs_latest/opentelemetry-sdk-trace.txt

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,7 @@ Comparing source compatibility of opentelemetry-sdk-trace-1.57.0-SNAPSHOT.jar ag
22
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.trace.export.BatchSpanProcessorBuilder (not serializable)
33
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
44
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.trace.export.BatchSpanProcessorBuilder setInternalTelemetryVersion(io.opentelemetry.sdk.common.InternalTelemetryVersion)
5-
+++ NEW CLASS: PUBLIC(+) STATIC(+) FINAL(+) io.opentelemetry.sdk.trace.export.SpanProcessorMetrics$LegacyProcessorMetrics (not serializable)
6-
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
7-
+++ NEW INTERFACE: io.opentelemetry.sdk.trace.export.SpanProcessorMetrics
8-
+++ NEW SUPERCLASS: java.lang.Object
9-
+++ NEW METHOD: PUBLIC(+) void buildQueueCapacityMetric(long)
10-
+++ NEW METHOD: PUBLIC(+) void buildQueueSizeMetric(io.opentelemetry.sdk.trace.export.SpanProcessorMetrics$LongCallable)
11-
+++ NEW METHOD: PUBLIC(+) void dropSpans(int)
12-
+++ NEW METHOD: PUBLIC(+) void finishSpans(int, java.lang.String)
135
+++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) STATIC(+) io.opentelemetry.sdk.trace.export.SpanProcessorMetrics$LongCallable (not serializable)
146
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
157
+++ NEW SUPERCLASS: java.lang.Object
168
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) long get()
17-
+++ NEW CLASS: PUBLIC(+) STATIC(+) FINAL(+) io.opentelemetry.sdk.trace.export.SpanProcessorMetrics$SemConvSpanProcessorMetrics (not serializable)
18-
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
19-
+++ NEW INTERFACE: io.opentelemetry.sdk.trace.export.SpanProcessorMetrics
20-
+++ NEW SUPERCLASS: java.lang.Object
21-
+++ NEW METHOD: PUBLIC(+) void buildQueueCapacityMetric(long)
22-
+++ NEW METHOD: PUBLIC(+) void buildQueueSizeMetric(io.opentelemetry.sdk.trace.export.SpanProcessorMetrics$LongCallable)
23-
+++ NEW METHOD: PUBLIC(+) void dropSpans(int)
24-
+++ NEW METHOD: PUBLIC(+) void finishSpans(int, java.lang.String)

sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkTracerMetrics.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
* SDK metrics exported for started and ended spans as defined in the <a
2121
* href="https://opentelemetry.io/docs/specs/semconv/otel/sdk-metrics/#span-metrics">semantic
2222
* conventions</a>.
23-
*
24-
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
25-
* at any time.
2623
*/
2724
final class SdkTracerMetrics {
2825

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.sdk.trace.export;
7+
8+
import io.opentelemetry.api.common.AttributeKey;
9+
import io.opentelemetry.api.common.Attributes;
10+
import io.opentelemetry.api.metrics.LongCounter;
11+
import io.opentelemetry.api.metrics.Meter;
12+
import io.opentelemetry.api.metrics.MeterProvider;
13+
import javax.annotation.Nullable;
14+
15+
/** Span processor metrics defined before they were standardized in semconv. */
16+
final class LegacySpanProcessorMetrics implements SpanProcessorMetrics {
17+
private static final AttributeKey<String> SPAN_PROCESSOR_TYPE_LABEL =
18+
AttributeKey.stringKey("processorType");
19+
private static final AttributeKey<Boolean> SPAN_PROCESSOR_DROPPED_LABEL =
20+
AttributeKey.booleanKey("dropped");
21+
// Legacy metrics are only created for batch span processor.
22+
private static final String SPAN_PROCESSOR_TYPE_VALUE = BatchSpanProcessor.class.getSimpleName();
23+
24+
private final Meter meter;
25+
private final Attributes standardAttrs;
26+
private final Attributes droppedAttrs;
27+
28+
private final LongCounter processedSpans;
29+
30+
LegacySpanProcessorMetrics(MeterProvider meterProvider) {
31+
meter = meterProvider.get("io.opentelemetry.sdk.trace");
32+
33+
processedSpans =
34+
meter
35+
.counterBuilder("processedSpans")
36+
.setUnit("1")
37+
.setDescription(
38+
"The number of spans processed by the BatchSpanProcessor. "
39+
+ "[dropped=true if they were dropped due to high throughput]")
40+
.build();
41+
42+
standardAttrs =
43+
Attributes.of(
44+
SPAN_PROCESSOR_TYPE_LABEL,
45+
SPAN_PROCESSOR_TYPE_VALUE,
46+
SPAN_PROCESSOR_DROPPED_LABEL,
47+
false);
48+
droppedAttrs =
49+
Attributes.of(
50+
SPAN_PROCESSOR_TYPE_LABEL,
51+
SPAN_PROCESSOR_TYPE_VALUE,
52+
SPAN_PROCESSOR_DROPPED_LABEL,
53+
true);
54+
}
55+
56+
/** Records metrics for spans dropped because a queue is full. */
57+
@Override
58+
public void dropSpans(int count) {
59+
processedSpans.add(count, droppedAttrs);
60+
}
61+
62+
@Override
63+
public void finishSpans(int count, @Nullable String error) {
64+
// Legacy metrics only record when no error.
65+
if (error != null) {
66+
processedSpans.add(count, standardAttrs);
67+
}
68+
}
69+
70+
@Override
71+
public void buildQueueCapacityMetric(long capacity) {
72+
// No capacity metric when legacy.
73+
}
74+
75+
/** Registers a metric for processor queue size. */
76+
@Override
77+
public void buildQueueSizeMetric(LongCallable queueSize) {
78+
meter
79+
.gaugeBuilder("queueSize")
80+
.ofLongs()
81+
.setDescription("The number of items queued")
82+
.setUnit("1")
83+
.buildWithCallback(
84+
result ->
85+
result.record(
86+
queueSize.get(),
87+
Attributes.of(SPAN_PROCESSOR_TYPE_LABEL, SPAN_PROCESSOR_TYPE_VALUE)));
88+
}
89+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.sdk.trace.export;
7+
8+
import io.opentelemetry.api.common.Attributes;
9+
import io.opentelemetry.api.metrics.LongCounter;
10+
import io.opentelemetry.api.metrics.Meter;
11+
import io.opentelemetry.api.metrics.MeterProvider;
12+
import io.opentelemetry.sdk.internal.ComponentId;
13+
import io.opentelemetry.sdk.internal.SemConvAttributes;
14+
import javax.annotation.Nullable;
15+
16+
/**
17+
* SDK metrics exported for span processors as defined in the <a
18+
* href="https://opentelemetry.io/docs/specs/semconv/otel/sdk-metrics/#span-metrics">semantic
19+
* conventions</a>.
20+
*/
21+
final class SemConvSpanProcessorMetrics implements SpanProcessorMetrics {
22+
23+
private final Meter meter;
24+
private final Attributes standardAttrs;
25+
private final Attributes droppedAttrs;
26+
27+
private final LongCounter processedSpans;
28+
29+
SemConvSpanProcessorMetrics(ComponentId componentId, MeterProvider meterProvider) {
30+
meter = meterProvider.get("io.opentelemetry.sdk.trace");
31+
32+
standardAttrs =
33+
Attributes.of(
34+
SemConvAttributes.OTEL_COMPONENT_TYPE,
35+
componentId.getTypeName(),
36+
SemConvAttributes.OTEL_COMPONENT_NAME,
37+
componentId.getComponentName());
38+
droppedAttrs =
39+
Attributes.of(
40+
SemConvAttributes.OTEL_COMPONENT_TYPE,
41+
componentId.getTypeName(),
42+
SemConvAttributes.OTEL_COMPONENT_NAME,
43+
componentId.getComponentName(),
44+
SemConvAttributes.ERROR_TYPE,
45+
"queue_full");
46+
47+
processedSpans =
48+
meter
49+
.counterBuilder("otel.sdk.processor.span.processed")
50+
.setUnit("span")
51+
.setDescription(
52+
"The number of spans for which the processing has finished, either successful or failed.")
53+
.build();
54+
}
55+
56+
@Override
57+
public void dropSpans(int count) {
58+
processedSpans.add(count, droppedAttrs);
59+
}
60+
61+
/** Record metrics for spans processed, possibly with an error. */
62+
@Override
63+
public void finishSpans(int count, @Nullable String error) {
64+
if (error == null) {
65+
processedSpans.add(count, standardAttrs);
66+
return;
67+
}
68+
69+
Attributes attributes =
70+
standardAttrs.toBuilder().put(SemConvAttributes.ERROR_TYPE, error).build();
71+
processedSpans.add(count, attributes);
72+
}
73+
74+
/** Registers a metric for processor queue capacity. */
75+
@Override
76+
public void buildQueueCapacityMetric(long capacity) {
77+
meter
78+
.upDownCounterBuilder("otel.sdk.processor.span.queue.capacity")
79+
.setUnit("span")
80+
.setDescription(
81+
"The maximum number of spans the queue of a given instance of an SDK span processor can hold. ")
82+
.buildWithCallback(m -> m.record(capacity, standardAttrs));
83+
}
84+
85+
/** Registers a metric for processor queue size. */
86+
@Override
87+
public void buildQueueSizeMetric(LongCallable getSize) {
88+
meter
89+
.upDownCounterBuilder("otel.sdk.processor.span.queue.size")
90+
.setUnit("span")
91+
.setDescription(
92+
"The number of spans in the queue of a given instance of an SDK span processor.")
93+
.buildWithCallback(m -> m.record(getSize.get(), standardAttrs));
94+
}
95+
}

0 commit comments

Comments
 (0)