Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public static void onEnter(@Advice.Argument(value = 0, readOnly = false) String[
+ "datadog.trace.api.telemetry.ConfigInversionMetricCollectorImpl$ConfigInversionMetric:build_time,"
+ "datadog.trace.api.telemetry.NoOpConfigInversionMetricCollector:build_time,"
+ "datadog.trace.api.telemetry.OtelEnvMetricCollectorImpl:build_time,"
+ "datadog.trace.api.telemetry.OtelSpiCollector:build_time,"
+ "datadog.trace.api.profiling.ProfilingEnablement:build_time,"
+ "datadog.trace.bootstrap.config.provider.ConfigConverter:build_time,"
+ "datadog.trace.bootstrap.config.provider.ConfigConverter$ValueOfLookup:build_time,"
Expand Down
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) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Enqueue SPI detections before draining

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 👍 / 👎.

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);
}
}
}
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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import datadog.telemetry.metric.IastMetricPeriodicAction;
import datadog.telemetry.metric.LLMObsMetricPeriodicAction;
import datadog.telemetry.metric.OtelEnvMetricPeriodicAction;
import datadog.telemetry.metric.OtelSpiMetricPeriodicAction;
import datadog.telemetry.metric.WafMetricPeriodicAction;
import datadog.telemetry.products.ProductChangeAction;
import datadog.telemetry.rum.RumPeriodicAction;
Expand Down Expand Up @@ -57,6 +58,7 @@ static Thread createTelemetryRunnable(
if (telemetryMetricsEnabled) {
actions.add(new CoreMetricsPeriodicAction());
actions.add(new OtelEnvMetricPeriodicAction());
actions.add(new OtelSpiMetricPeriodicAction());
actions.add(new ConfigInversionMetricPeriodicAction());
actions.add(new IntegrationPeriodicAction());
actions.add(new WafMetricPeriodicAction());
Expand Down
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();
}
}
Loading