-
Notifications
You must be signed in to change notification settings - Fork 334
Introduce OTel SPI Metrics #11297
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
Open
mhlidd
wants to merge
2
commits into
master
Choose a base branch
from
mhlidd/add_extensions_metric
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Introduce OTel SPI Metrics #11297
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
internal-api/src/main/java/datadog/trace/api/telemetry/OtelSpiCollector.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package datadog.trace.api.telemetry; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.concurrent.ArrayBlockingQueue; | ||
| import java.util.concurrent.BlockingQueue; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** Collects telemetry about OpenTelemetry SPIs detected in the customer environment. */ | ||
| public class OtelSpiCollector implements MetricCollector<OtelSpiCollector.OtelSpiMetric> { | ||
| private static final Logger log = LoggerFactory.getLogger(OtelSpiCollector.class); | ||
| private static final String OTEL_SPI_DETECTED_METRIC_NAME = "otel.spi.detected"; | ||
| private static final String SPI_CLASS_TAG = "spi_class:"; | ||
| private static final String SOURCE_TAG = "source:"; | ||
| private static final String NAMESPACE = "tracers"; | ||
| private static final OtelSpiCollector INSTANCE = new OtelSpiCollector(); | ||
|
|
||
| private final BlockingQueue<OtelSpiMetric> metricsQueue; | ||
|
|
||
| private OtelSpiCollector() { | ||
| this.metricsQueue = new ArrayBlockingQueue<>(RAW_QUEUE_SIZE); | ||
| } | ||
|
|
||
| public static OtelSpiCollector getInstance() { | ||
| return INSTANCE; | ||
| } | ||
|
|
||
| public void recordSpiDetected(String spiFqn, String source) { | ||
| if (!metricsQueue.offer( | ||
| new OtelSpiMetric( | ||
| NAMESPACE, | ||
| true, | ||
| OTEL_SPI_DETECTED_METRIC_NAME, | ||
| "count", | ||
| 1, | ||
| SPI_CLASS_TAG + spiFqn, | ||
| SOURCE_TAG + source))) { | ||
| log.debug( | ||
| "Unable to add telemetry metric {} for spi_class={} source={}", | ||
| OTEL_SPI_DETECTED_METRIC_NAME, | ||
| spiFqn, | ||
| source); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void prepareMetrics() { | ||
| // Nothing to do here | ||
| } | ||
|
|
||
| @Override | ||
| public Collection<OtelSpiMetric> drain() { | ||
| if (this.metricsQueue.isEmpty()) { | ||
| return Collections.emptyList(); | ||
| } | ||
| List<OtelSpiMetric> drained = new ArrayList<>(this.metricsQueue.size()); | ||
| this.metricsQueue.drainTo(drained); | ||
| return drained; | ||
| } | ||
|
|
||
| public static class OtelSpiMetric extends MetricCollector.Metric { | ||
| public OtelSpiMetric( | ||
| String namespace, | ||
| boolean common, | ||
| String metricName, | ||
| String type, | ||
| Number value, | ||
| final String... tags) { | ||
| super(namespace, common, metricName, type, value, tags); | ||
| } | ||
| } | ||
| } | ||
69 changes: 69 additions & 0 deletions
69
internal-api/src/test/java/datadog/trace/api/telemetry/OtelSpiCollectorTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| package datadog.trace.api.telemetry; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertSame; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import java.util.Iterator; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class OtelSpiCollectorTest { | ||
|
|
||
| private final OtelSpiCollector collector = OtelSpiCollector.getInstance(); | ||
|
|
||
| @BeforeEach | ||
| public void clearQueue() { | ||
| collector.drain(); | ||
| } | ||
|
|
||
| @Test | ||
| public void singletonReturnsSameInstance() { | ||
| assertSame(OtelSpiCollector.getInstance(), OtelSpiCollector.getInstance()); | ||
| } | ||
|
|
||
| @Test | ||
| public void recordedMetricSurfacesOnDrain() { | ||
| collector.recordSpiDetected( | ||
| "io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider", "extensions_path"); | ||
|
|
||
| Iterator<OtelSpiCollector.OtelSpiMetric> drained = collector.drain().iterator(); | ||
| assertTrue(drained.hasNext()); | ||
| OtelSpiCollector.OtelSpiMetric metric = drained.next(); | ||
| assertEquals("tracers", metric.namespace); | ||
| assertEquals("otel.spi.detected", metric.metricName); | ||
| assertEquals("count", metric.type); | ||
| assertTrue(metric.common); | ||
| assertEquals(1, metric.value); | ||
| assertTrue( | ||
| metric.tags.contains( | ||
| "spi_class:io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider")); | ||
| assertTrue(metric.tags.contains("source:extensions_path")); | ||
| } | ||
|
|
||
| @Test | ||
| public void multipleRecordsDrainAsDistinctMetrics() { | ||
| collector.recordSpiDetected( | ||
| "io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider", "app_classpath"); | ||
| collector.recordSpiDetected( | ||
| "io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider", "app_classpath"); | ||
| collector.recordSpiDetected( | ||
| "io.opentelemetry.sdk.autoconfigure.spi.ConfigurableSamplerProvider", "extensions_path"); | ||
|
|
||
| assertEquals(3, collector.drain().size()); | ||
| } | ||
|
|
||
| @Test | ||
| public void drainWithoutRecordsReturnsEmpty() { | ||
| assertEquals(0, collector.drain().size()); | ||
| } | ||
|
|
||
| @Test | ||
| public void drainClearsQueue() { | ||
| collector.recordSpiDetected( | ||
| "io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider", | ||
| "extensions_path"); | ||
| assertEquals(1, collector.drain().size()); | ||
| assertEquals(0, collector.drain().size()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
telemetry/src/main/java/datadog/telemetry/metric/OtelSpiMetricPeriodicAction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package datadog.telemetry.metric; | ||
|
|
||
| import datadog.trace.api.telemetry.MetricCollector; | ||
| import datadog.trace.api.telemetry.OtelSpiCollector; | ||
| import edu.umd.cs.findbugs.annotations.NonNull; | ||
|
|
||
| public class OtelSpiMetricPeriodicAction extends MetricPeriodicAction { | ||
| @Override | ||
| @NonNull | ||
| public MetricCollector collector() { | ||
| return OtelSpiCollector.getInstance(); | ||
| } | ||
| } |
Oops, something went wrong.
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.
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.
In any runtime where OTel SPI providers are present, this metric will still never be emitted: I checked repo-wide (
rg recordSpiDetected) and the only callers are the new tests, so the telemetry action drains an always-empty queue. Please wire the SPI discovery/loading path to call this method before enabling the periodic action.Useful? React with 👍 / 👎.