Skip to content
Draft
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
5 changes: 5 additions & 0 deletions .changesets/fix_bryn_otlp_export_dd_measured.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### OTLP trace exporter does not correctly display resources in Datadog APM view ([PR #7344](https://github.com/apollographql/router/pull/7344))

Router 2.x Datadog APM view is now fixed when using `preview_datadog_agent_sampling`. This was underreporting requests due to missing `_dd.measured` attributes.

By [@BrynCooke](https://github.com/BrynCooke) in https://github.com/apollographql/router/pull/7344
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use opentelemetry::Context;
use opentelemetry::KeyValue;
use opentelemetry::trace::SpanContext;
use opentelemetry::trace::TraceResult;
use opentelemetry_sdk::Resource;
Expand Down Expand Up @@ -36,6 +37,7 @@ impl<T: SpanProcessor> SpanProcessor for DatadogSpanProcessor<T> {
span.span_context.is_remote(),
span.span_context.trace_state().clone(),
);
span.attributes.push(KeyValue::new("_dd.measured", 1));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems to happen for both the datadog exporter, and the OTLP exporter. The datadog exporter already configures measuring separately, so is it correct to do this here? I think it is duplicate for the DD exporter and could cause confusing interference in the future, and should probably only happen in OTLP.

self.delegate.on_end(span)
}

Expand Down
18 changes: 6 additions & 12 deletions apollo-router/tests/integration/telemetry/otlp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ async fn test_untraced_request_sample_datadog_agent() -> Result<(), BoxError> {
.services(["router", "subgraph"].into())
.priority_sampled("1")
.subgraph_sampled(true)
.measured_spans(["router", "supergraph"].into())
.build()
.validate_otlp_trace(
&mut router,
Expand Down Expand Up @@ -792,20 +793,13 @@ impl Verifier for OtlpTraceSpec<'_> {
}

fn measured_span(&self, trace: &Value, name: &str) -> Result<bool, BoxError> {
let binding1 = trace.select_path(&format!(
"$..[?(@.meta.['otel.original_name'] == '{}')].metrics.['_dd.measured']",
let binding = trace.select_path(&format!(
"$..[?(@.attributes[?(@.key == 'otel.original_name' && @.value.stringValue == '{}')])].attributes[?(@.key == '_dd.measured')].value.intValue",
name
))?;
let binding2 = trace.select_path(&format!(
"$..[?(@.name == '{}')].metrics.['_dd.measured']",
name
))?;
Ok(binding1
.first()
.or(binding2.first())
.and_then(|v| v.as_f64())
.map(|v| v == 1.0)
.unwrap_or_default())

let measured = binding.first().and_then(|v| v.as_i64()).unwrap_or_default();
Ok(measured == 1)
}

async fn find_valid_metrics(&self) -> Result<(), BoxError> {
Expand Down