Skip to content
3 changes: 3 additions & 0 deletions libdd-data-pipeline/src/otlp/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ pub struct OtlpTraceConfig {
/// Protocol (for future use; currently only HttpJson is supported).
#[allow(dead_code)]
pub(crate) protocol: OtlpProtocol,
/// When `true`, does not add DD-specific per-span attributes (`service.name`,
/// `operation.name`, `resource.name`, `span.type`) to the OTLP payload.
pub otel_trace_semantics_enabled: bool,
}
12 changes: 12 additions & 0 deletions libdd-data-pipeline/src/trace_exporter/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub struct TraceExporterBuilder {
connection_timeout: Option<u64>,
otlp_endpoint: Option<String>,
otlp_headers: Vec<(String, String)>,
otel_trace_semantics_enabled: bool,
}

impl TraceExporterBuilder {
Expand Down Expand Up @@ -296,6 +297,16 @@ impl TraceExporterBuilder {
self
}

/// Enables OTel trace semantics, which does not add DD-specific per-span attributes
/// (`service.name`, `operation.name`, `resource.name`, `span.type`) to the OTLP payload.
/// This is useful when exporting to a native OTel backend that does not expect Datadog
/// semantics. The host language tracer is expected to observe this behavior by setting the
/// `DD_TRACE_OTEL_SEMANTICS_ENABLED` environment variable to `true`.
pub fn enable_otel_trace_semantics(&mut self) -> &mut Self {
self.otel_trace_semantics_enabled = true;
self
}

/// Build the [`TraceExporter`] synchronously.
///
/// Sync facade over [`Self::build_async`]; panics inside an existing tokio context.
Expand Down Expand Up @@ -452,6 +463,7 @@ impl TraceExporterBuilder {
.map(Duration::from_millis)
.unwrap_or(DEFAULT_OTLP_TIMEOUT),
protocol: OtlpProtocol::HttpJson,
otel_trace_semantics_enabled: self.otel_trace_semantics_enabled,
}
});

Expand Down
3 changes: 2 additions & 1 deletion libdd-data-pipeline/src/trace_exporter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,8 @@ impl<C: HttpClientCapability + SleepCapability + MaybeSend + Sync + 'static> Tra
r.runtime_id = self.metadata.runtime_id.clone();
r
};
let request = map_traces_to_otlp(traces, &resource_info);
let request =
map_traces_to_otlp(traces, &resource_info, config.otel_trace_semantics_enabled);
let json_body = serde_json::to_vec(&request).map_err(|e| {
error!("OTLP JSON serialization error: {e}");
TraceExporterError::Internal(InternalErrorKind::InvalidWorkerState(e.to_string()))
Expand Down
Loading
Loading