Skip to content

Commit

Permalink
fix: Fix the array encoding length of datadog version 05 exporter (#1002
Browse files Browse the repository at this point in the history
)

* Fix the array encoding of datadog version 05 exporter

* Fix type for array length

* Fix unit test

* Fix unit test correctly

* opentelemetry-datadog: Add missing Headers

* Version
* Language

* fix: format

---------

Co-authored-by: Harold Dost <h.dost@criteo.com>
Co-authored-by: Zhongyang Wu <zhongyang.wu@outlook.com>
  • Loading branch information
3 people committed Mar 25, 2023
1 parent 01dade6 commit 8cc3ee3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
9 changes: 9 additions & 0 deletions opentelemetry-datadog/src/exporter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ const DEFAULT_AGENT_ENDPOINT: &str = "http://127.0.0.1:8126";
/// Header name used to inform the Datadog agent of the number of traces in the payload
const DATADOG_TRACE_COUNT_HEADER: &str = "X-Datadog-Trace-Count";

/// Header name use to inform datadog as to what version
const DATADOG_META_LANG_HEADER: &str = "Datadog-Meta-Lang";
const DATADOG_META_TRACER_VERSION_HEADER: &str = "Datadog-Meta-Tracer-Version";

// Struct to hold the mapping between Opentelemetry spans and datadog spans.
pub struct Mapping {
resource: Option<FieldMapping>,
Expand Down Expand Up @@ -101,6 +105,11 @@ impl DatadogExporter {
.uri(self.request_url.clone())
.header(http::header::CONTENT_TYPE, self.api_version.content_type())
.header(DATADOG_TRACE_COUNT_HEADER, trace_count)
.header(DATADOG_META_LANG_HEADER, "rust")
.header(
DATADOG_META_TRACER_VERSION_HEADER,
env!("CARGO_PKG_VERSION"),
)
.body(data)
.map_err::<Error, _>(Into::into)?;

Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-datadog/src/exporter/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ pub(crate) mod tests {

assert_eq!(encoded.as_str(), "kp6jd2VirHNlcnZpY2VfbmFtZaljb21wb25lbnSocmVzb3VyY2WpaG9zdC5uYW\
1lpHRlc3Snc2VydmljZax0ZXN0LXNlcnZpY2WjZW52qHRlc3QtZW52p3ZlcnNpb26sdGVzdC12ZXJzaW9uqXNwYW4udH\
lwZbVfc2FtcGxpbmdfcHJpb3JpdHlfdjGRkZ3OAAAAAc4AAAACzgAAAAPPAAAAAAAAAAfPAAAAAAAAAGPPAAAAAAAAAA\
lwZbVfc2FtcGxpbmdfcHJpb3JpdHlfdjGRkZzOAAAAAc4AAAACzgAAAAPPAAAAAAAAAAfPAAAAAAAAAGPPAAAAAAAAAA\
HTAAAAAAAAAADTAAAAADuaygDSAAAAAIXOAAAABM4AAAAFzgAAAAbOAAAAB84AAAAIzgAAAAnOAAAACs4AAAALzgAAAA\
zOAAAAAIHOAAAADcsAAAAAAAAAAM4AAAAA");

Expand Down
6 changes: 4 additions & 2 deletions opentelemetry-datadog/src/exporter/model/v05.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ use std::time::SystemTime;

use super::unified_tags::{UnifiedTagField, UnifiedTags};

const SPAN_NUM_ELEMENTS: u32 = 12;

// Protocol documentation sourced from https://github.com/DataDog/datadog-agent/blob/c076ea9a1ffbde4c76d35343dbc32aecbbf99cb9/pkg/trace/api/version.go
//
// The payload is an array containing exactly 2 elements:
// The payload is an array containing exactly 12 elements:
//
// 1. An array of all unique strings present in the payload (a dictionary referred to by index).
// 2. An array of traces, where each trace is an array of spans. A span is encoded as an array having
Expand Down Expand Up @@ -154,7 +156,7 @@ where
};

// Datadog span name is OpenTelemetry component name - see module docs for more information
rmp::encode::write_array_len(&mut encoded, 13)?;
rmp::encode::write_array_len(&mut encoded, SPAN_NUM_ELEMENTS)?;
rmp::encode::write_u32(
&mut encoded,
interner.intern(get_service_name(&span, model_config)),
Expand Down

0 comments on commit 8cc3ee3

Please sign in to comment.