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
21 changes: 20 additions & 1 deletion datadog-opentelemetry/src/ddtrace_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ use opentelemetry_semantic_conventions::resource::SERVICE_NAME;

static SERVICE_NAME_KEY: Key = Key::from_static_str(SERVICE_NAME);

/// Chunk-level tag marking whether the trace chunk was exported through OTLP. Set to "false" on
/// the first span of every chunk exported natively to the Datadog agent.
const SDK_OTLP_EXPORT_KEY: &str = "_dd.sdk.otlp_export";

/// The OTLP receiver in the agent only receives sampled spans
/// because others are dropped in the process. In this spirit, we check for the sampling
/// decision taken by the datadog sampler, and if it is missing assign AUTO_KEEP/AUTO_DROP
Expand Down Expand Up @@ -50,19 +54,34 @@ where
// and then handing off groups of span data?
span_data
.into_iter()
.map(|s| {
.enumerate()
.map(|(i, s)| {
let trace_flags = s.span_context.trace_flags();
let sdk_span = SdkSpan::from_sdk_span_data(s);
let mut dd_span = otel_span_to_dd_span(&sdk_span, otel_resource);
otel_sampling_to_dd_sampling(trace_flags, &mut dd_span);

add_config_metadata(&mut dd_span, cached_config, otel_resource);

// Traces are only exported natively today. When OTLP trace export is added, pass
// the export mode in and skip this tag for OTLP.
if i == 0 {
add_native_export_marker(&mut dd_span);
}

dd_span
})
.collect()
}

/// Mark the span as exported natively to the Datadog agent. Set on the first span of each chunk.
fn add_native_export_marker(dd_span: &mut DdSpan) {
dd_span.meta.insert(
SpanStr::from_static_str(SDK_OTLP_EXPORT_KEY),
SpanStr::from_static_str("false"),
);
}

fn add_config_metadata<'a>(
dd_span: &mut DdSpan<'a>,
cached_config: &'a CachedConfig,
Expand Down
1 change: 1 addition & 0 deletions datadog-opentelemetry/src/span_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ impl Export<BufferedSpan> for SpanDataExport {
let dd_trace_chunks = trace_chunks
.iter()
.map(|chunk| {
// When OTLP trace export is added, pass the export mode here too.
ddtrace_transform::otel_trace_chunk_to_dd_trace_chunk(
&self.cached_config,
chunk.iter().map(|b| &b.0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"parent_id": 987654321098765432,
"type": "web",
"meta": {
"_dd.sdk.otlp_export": "false",
"baggage.user.id": "alice",
"otel.scope.name": "test",
"otel.status_code": "Unset",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"type": "web",
"meta": {
"_dd.p.dm": "-0",
"_dd.sdk.otlp_export": "false",
"baggage.user.id": "alice",
"otel.scope.name": "test",
"otel.status_code": "Unset",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"parent_id": 987654321098765432,
"type": "web",
"meta": {
"_dd.sdk.otlp_export": "false",
"baggage.user.id": "alice",
"otel.scope.name": "test",
"otel.status_code": "Unset",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"_dd.p.dm": "-4",
"_dd.p.usr.id": "baz64",
"_dd.parent_id": "00f067aa0ba902b7",
"_dd.sdk.otlp_export": "false",
"otel.scope.name": "test",
"otel.status_code": "Unset",
"otel.trace_id": "80f198ee56343ba864fe8b2a57d3eff7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"type": "web",
"meta": {
"_dd.p.dm": "-0",
"_dd.sdk.otlp_export": "false",
"otel.scope.name": "test",
"otel.status_code": "Unset",
"otel.trace_id": "6a2912f7000000003fef098aa6d0543f",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"type": "web",
"meta": {
"_dd.p.dm": "-0",
"_dd.sdk.otlp_export": "false",
"otel.scope.name": "test",
"otel.status_code": "Unset",
"otel.trace_id": "6a2aa1fc00000000d8864be77751666b",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"type": "web",
"meta": {
"_dd.p.dm": "-0",
"_dd.sdk.otlp_export": "false",
"otel.scope.name": "test",
"otel.status_code": "Unset",
"otel.trace_id": "6a2960bc00000000dcfe3384505b6fc5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"type": "web",
"meta": {
"_dd.p.dm": "-0",
"_dd.sdk.otlp_export": "false",
"otel.scope.name": "test",
"otel.status_code": "Unset",
"otel.trace_id": "6a2960bb0000000075bbcd986de6224f",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"meta": {
"_dd.p.dm": "-3",
"_dd.p.ksr": "1",
"_dd.sdk.otlp_export": "false",
"otel.scope.name": "test",
"otel.status_code": "Unset",
"otel.trace_id": "6a432ae900000000fadb9ed3e75ee6b8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"meta": {
"_dd.p.dm": "-11",
"_dd.p.ksr": "1",
"_dd.sdk.otlp_export": "false",
"otel.scope.name": "test",
"otel.status_code": "Unset",
"otel.trace_id": "69b9879800000000e3b9155ba22b8a52",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"meta": {
"_dd.p.dm": "-3",
"_dd.p.ksr": "1",
"_dd.sdk.otlp_export": "false",
"otel.scope.name": "test",
"otel.status_code": "Unset",
"otel.trace_id": "69b9879600000000dce1993a9f43a1cb",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"type": "http",
"meta": {
"_dd.p.dm": "-0",
"_dd.sdk.otlp_export": "false",
"otel.scope.name": "test",
"otel.status_code": "Unset",
"otel.trace_id": "6aba787f0000000007c8917e6af0d112",
Expand Down Expand Up @@ -36,6 +37,7 @@
"type": "http",
"meta": {
"_dd.p.dm": "-0",
"_dd.sdk.otlp_export": "false",
"otel.scope.name": "test",
"otel.status_code": "Unset",
"otel.trace_id": "6aba787f00000000303e0c3036d79def",
Expand Down Expand Up @@ -63,6 +65,7 @@
"type": "http",
"meta": {
"_dd.p.dm": "-0",
"_dd.sdk.otlp_export": "false",
"otel.scope.name": "test",
"otel.status_code": "Unset",
"otel.trace_id": "6aba787f00000000f2753b76f5399802",
Expand Down Expand Up @@ -90,6 +93,7 @@
"type": "http",
"meta": {
"_dd.p.dm": "-0",
"_dd.sdk.otlp_export": "false",
"otel.scope.name": "test",
"otel.status_code": "Unset",
"otel.trace_id": "6aba787f0000000074460ea23f9fc49f",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"type": "custom",
"meta": {
"_dd.p.dm": "-0",
"_dd.sdk.otlp_export": "false",
"otel.scope.name": "test_trace_writer_synchronous_mode",
"otel.status_code": "Unset",
"otel.trace_id": "69b9879600000000b6685c281043fd5b",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"error": 1,
"meta": {
"_dd.p.dm": "-0",
"_dd.sdk.otlp_export": "false",
"_dd.span_events.has_exception": "true",
"code.file.path": "datadog-opentelemetry/tests/integration_tests/tracing_api.rs",
"code.module.name": "tests::integration_tests::tracing_api",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"meta": {
"_dd.origin": "my_origin",
"_dd.p.foo": "bar",
"_dd.sdk.otlp_export": "false",
"code.file.path": "datadog-opentelemetry/tests/integration_tests/tracing_api.rs",
"code.module.name": "tests::integration_tests::tracing_api",
"otel.scope.name": "test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"type": "custom",
"meta": {
"_dd.p.dm": "-0",
"_dd.sdk.otlp_export": "false",
"code.file.path": "datadog-opentelemetry/tests/integration_tests/tracing_api.rs",
"code.module.name": "tests::integration_tests::tracing_api",
"otel.scope.name": "test",
Expand Down
Loading