Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade hyper and otel dependencies #97

Merged
merged 5 commits into from
Aug 2, 2024
Merged
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
8 changes: 7 additions & 1 deletion opentelemetry-datadog/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## vNext

## v0.12.0

### Changed

- Bump opentelemetry and opentelemetry_sdk version to 0.24
- Bump hyper to version 1

## v0.10.0

### Added
Expand All @@ -17,7 +24,6 @@
- allow send all traces to `datadog-agent` with `agent-sampling` feature.
- allow `datadog-agent` generate metrics from spans for [APM](https://docs.datadoghq.com/tracing/metrics/).


## v0.9.0

### Changed
Expand Down
24 changes: 12 additions & 12 deletions opentelemetry-datadog/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
[package]
name = "opentelemetry-datadog"
version = "0.11.0"
version = "0.12.0"
description = "Datadog exporters and propagators for OpenTelemetry"
homepage = "https://github.com/open-telemetry/opentelemetry-rust-contrib/tree/main/opentelemetry-datadog"
repository = "https://github.com/open-telemetry/opentelemetry-rust-contrib/tree/main/opentelemetry-datadog"
readme = "README.md"
categories = [
"development-tools::debugging",
"development-tools::profiling",
]
categories = ["development-tools::debugging", "development-tools::profiling"]
keywords = ["opentelemetry", "tracing"]
license = "Apache-2.0"
edition = "2021"
Expand All @@ -30,17 +27,17 @@ intern-std = []
[dependencies]
indexmap = "2.0"
once_cell = "1.12"
opentelemetry = { version = "0.23", features = ["trace"] }
opentelemetry_sdk = { version = "0.23", features = ["trace"] }
opentelemetry-http = {version = "0.12" }
opentelemetry = { version = "0.24", features = ["trace"] }
opentelemetry_sdk = { version = "0.24", features = ["trace"] }
opentelemetry-http = { version = "0.13" }
opentelemetry-semantic-conventions = { workspace = true }
rmp = "0.8"
url = "2.2"
reqwest = { version = "0.11", default-features = false, optional = true }
reqwest = { version = "0.12", default-features = false, optional = true }
surf = { version = "2.0", default-features = false, optional = true }
thiserror = "1.0"
itertools = "0.11"
http = "0.2"
http = "1"
futures-core = "0.3"
ryu = "1"
itoa = "1"
Expand All @@ -51,10 +48,13 @@ async-trait = "0.1"
base64 = "0.13"
bytes = "1"
futures-util = { version = "0.3", default-features = false, features = ["io"] }
isahc = "1.4"
opentelemetry_sdk = {version = "0.23", features = ["trace", "testing"] }
opentelemetry_sdk = { version = "0.24", features = ["trace", "testing"] }
criterion = "0.5"
rand = "0.8"
hyper = "1"
hyper-util = { version = "0.1.6", features = ["client", "full"] }
hyperlocal = "0.9.1"
http-body-util = "0.1.2"

[[bench]]
name = "datadog_exporter"
Expand Down
8 changes: 1 addition & 7 deletions opentelemetry-datadog/benches/datadog_exporter.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::{
borrow::Cow,
time::{Duration, SystemTime},
};
use std::time::{Duration, SystemTime};

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use http::Request;
Expand All @@ -14,7 +11,6 @@ use opentelemetry_http::HttpClient;
use opentelemetry_sdk::{
export::trace::{SpanData, SpanExporter},
trace::{SpanEvents, SpanLinks},
Resource,
};
use rand::seq::SliceRandom;
use rand::{rngs::ThreadRng, thread_rng, RngCore};
Expand Down Expand Up @@ -154,7 +150,6 @@ fn get_span(trace_id: u128, parent_span_id: u64, span_id: u64, rng: &mut ThreadR
];
let events = SpanEvents::default();
let links = SpanLinks::default();
let resource = Resource::new(vec![KeyValue::new("host.name", "test")]);
let instrumentation_lib = InstrumentationLibrary::builder("component").build();

SpanData {
Expand All @@ -169,7 +164,6 @@ fn get_span(trace_id: u128, parent_span_id: u64, span_id: u64, rng: &mut ThreadR
events,
links,
status: Status::Ok,
resource: Cow::Owned(resource),
instrumentation_lib,
}
}
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-datadog/examples/agent_sampling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
.with_service_name("agent-sampling-demo")
.with_api_version(ApiVersion::Version05)
.with_trace_config(
trace::config()
trace::Config::default()
.with_sampler(AgentBasedSampler)
.with_id_generator(RandomIdGenerator::default()),
)
Expand Down
25 changes: 13 additions & 12 deletions opentelemetry-datadog/src/exporter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
api_version: ApiVersion,
mapping: Mapping,
unified_tags: UnifiedTags,
resource: Option<Resource>,
}

impl DatadogExporter {
Expand All @@ -86,6 +87,7 @@
api_version,
mapping,
unified_tags,
resource: None,
}
}

Expand All @@ -100,6 +102,7 @@
traces,
&self.mapping,
&self.unified_tags,
self.resource.as_ref(),

Check warning on line 105 in opentelemetry-datadog/src/exporter/mod.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-datadog/src/exporter/mod.rs#L105

Added line #L105 was not covered by tests
)?;
let req = Request::builder()
.method(Method::POST)
Expand Down Expand Up @@ -219,10 +222,9 @@
));
cfg
} else {
Config {
resource: Cow::Owned(Resource::empty()),
..Default::default()
}
let mut cfg = Config::default();
cfg.resource = Cow::Owned(Resource::empty());
cfg
};
(config, service_name)
} else {
Expand All @@ -231,14 +233,10 @@
.get(semcov::resource::SERVICE_NAME.into())
.unwrap()
.to_string();
(
Config {
// use a empty resource to prevent TracerProvider to assign a service name.
resource: Cow::Owned(Resource::empty()),
..Default::default()
},
service_name,
)
let mut cfg = Config::default();
// use a empty resource to prevent TracerProvider to assign a service name.
cfg.resource = Cow::Owned(Resource::empty());
(cfg, service_name)
}
}

Expand Down Expand Up @@ -438,6 +436,9 @@
let client = self.client.clone();
Box::pin(send_request(client, request))
}
fn set_resource(&mut self, resource: &Resource) {
self.resource = Some(resource.clone());
}
}

/// Helper struct to custom the mapping between Opentelemetry spans and datadog spans.
Expand Down
21 changes: 14 additions & 7 deletions opentelemetry-datadog/src/exporter/model/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use crate::exporter::ModelConfig;
use http::uri;
use opentelemetry_sdk::export::{
trace::{self, SpanData},
ExportError,
use opentelemetry_sdk::{
export::{
trace::{self, SpanData},
ExportError,
},
Resource,
};
use std::fmt::Debug;
use url::ParseError;
Expand Down Expand Up @@ -150,6 +153,7 @@ impl ApiVersion {
traces: Vec<&[trace::SpanData]>,
mapping: &Mapping,
unified_tags: &UnifiedTags,
resource: Option<&Resource>,
) -> Result<Vec<u8>, Error> {
match self {
Self::Version03 => v03::encode(
Expand All @@ -167,6 +171,7 @@ impl ApiVersion {
Some(f) => f(span, config),
None => default_resource_mapping(span, config),
},
resource,
),
Self::Version05 => v05::encode(
model_config,
Expand All @@ -184,6 +189,7 @@ impl ApiVersion {
None => default_resource_mapping(span, config),
},
unified_tags,
resource,
),
}
}
Expand All @@ -199,9 +205,8 @@ pub(crate) mod tests {
use opentelemetry_sdk::{
self,
trace::{SpanEvents, SpanLinks},
InstrumentationLibrary, Resource,
InstrumentationLibrary,
};
use std::borrow::Cow;
use std::time::{Duration, SystemTime};

fn get_traces() -> Vec<Vec<trace::SpanData>> {
Expand All @@ -223,7 +228,6 @@ pub(crate) mod tests {
let attributes = vec![KeyValue::new("span.type", "web")];
let events = SpanEvents::default();
let links = SpanLinks::default();
let resource = Resource::new(vec![KeyValue::new("host.name", "test")]);
let instrumentation_lib = InstrumentationLibrary::builder("component").build();

trace::SpanData {
Expand All @@ -238,7 +242,6 @@ pub(crate) mod tests {
events,
links,
status: Status::Ok,
resource: Cow::Owned(resource),
instrumentation_lib,
}
}
Expand All @@ -250,11 +253,13 @@ pub(crate) mod tests {
service_name: "service_name".to_string(),
..Default::default()
};
let resource = Resource::new(vec![KeyValue::new("host.name", "test")]);
let encoded = base64::encode(ApiVersion::Version03.encode(
&model_config,
traces.iter().map(|x| &x[..]).collect(),
&Mapping::empty(),
&UnifiedTags::new(),
Some(&resource),
)?);

assert_eq!(encoded.as_str(), "kZGMpHR5cGWjd2Vip3NlcnZpY2Wsc2VydmljZV9uYW1lpG5hbWWpY29tcG9uZW\
Expand All @@ -272,6 +277,7 @@ pub(crate) mod tests {
service_name: "service_name".to_string(),
..Default::default()
};
let resource = Resource::new(vec![KeyValue::new("host.name", "test")]);

let mut unified_tags = UnifiedTags::new();
unified_tags.set_env(Some(String::from("test-env")));
Expand All @@ -283,6 +289,7 @@ pub(crate) mod tests {
traces.iter().map(|x| &x[..]).collect(),
&Mapping::empty(),
&unified_tags,
Some(&resource),
)?);

// TODO: Need someone to generate the expected result or instructions to do so.
Expand Down
12 changes: 8 additions & 4 deletions opentelemetry-datadog/src/exporter/model/v03.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::exporter::model::{Error, SAMPLING_PRIORITY_KEY};
use crate::exporter::ModelConfig;
use opentelemetry::trace::Status;
use opentelemetry_sdk::export::trace::SpanData;
use opentelemetry_sdk::Resource;
use std::time::SystemTime;

pub(crate) fn encode<S, N, R>(
Expand All @@ -10,6 +11,7 @@ pub(crate) fn encode<S, N, R>(
get_service_name: S,
get_name: N,
get_resource: R,
resource: Option<&Resource>,
) -> Result<Vec<u8>, Error>
where
for<'a> S: Fn(&'a SpanData, &'a ModelConfig) -> &'a str,
Expand Down Expand Up @@ -97,11 +99,13 @@ where
rmp::encode::write_str(&mut encoded, "meta")?;
rmp::encode::write_map_len(
&mut encoded,
(span.attributes.len() + span.resource.len()) as u32,
(span.attributes.len() + resource.map(|r| r.len()).unwrap_or(0)) as u32,
)?;
for (key, value) in span.resource.iter() {
rmp::encode::write_str(&mut encoded, key.as_str())?;
rmp::encode::write_str(&mut encoded, value.as_str().as_ref())?;
if let Some(resource) = resource {
for (key, value) in resource.iter() {
rmp::encode::write_str(&mut encoded, key.as_str())?;
rmp::encode::write_str(&mut encoded, value.as_str().as_ref())?;
}
}
for kv in span.attributes.iter() {
rmp::encode::write_str(&mut encoded, kv.key.as_str())?;
Expand Down
15 changes: 11 additions & 4 deletions opentelemetry-datadog/src/exporter/model/v05.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::exporter::{Error, ModelConfig};
use crate::propagator::DatadogTraceState;
use opentelemetry::trace::Status;
use opentelemetry_sdk::export::trace::SpanData;
use opentelemetry_sdk::Resource;
use std::time::SystemTime;

use super::unified_tags::{UnifiedTagField, UnifiedTags};
Expand Down Expand Up @@ -74,6 +75,7 @@ pub(crate) fn encode<S, N, R>(
get_name: N,
get_resource: R,
unified_tags: &UnifiedTags,
resource: Option<&Resource>,
) -> Result<Vec<u8>, Error>
where
for<'a> S: Fn(&'a SpanData, &'a ModelConfig) -> &'a str,
Expand All @@ -89,6 +91,7 @@ where
get_resource,
&traces,
unified_tags,
resource,
)?;

let mut payload = Vec::with_capacity(traces.len() * 512);
Expand Down Expand Up @@ -146,6 +149,7 @@ fn get_measuring(span: &SpanData) -> f64 {
}
}

#[allow(clippy::too_many_arguments)]
fn encode_traces<'interner, S, N, R>(
interner: &mut StringInterner<'interner>,
model_config: &'interner ModelConfig,
Expand All @@ -154,6 +158,7 @@ fn encode_traces<'interner, S, N, R>(
get_resource: R,
traces: &'interner [&[SpanData]],
unified_tags: &'interner UnifiedTags,
resource: Option<&'interner Resource>,
) -> Result<Vec<u8>, Error>
where
for<'a> S: Fn(&'a SpanData, &'a ModelConfig) -> &'a str,
Expand Down Expand Up @@ -223,13 +228,15 @@ where

rmp::encode::write_map_len(
&mut encoded,
(span.attributes.len() + span.resource.len()) as u32
(span.attributes.len() + resource.map(|r| r.len()).unwrap_or(0)) as u32
+ unified_tags.compute_attribute_size()
+ GIT_META_TAGS_COUNT,
)?;
for (key, value) in span.resource.iter() {
rmp::encode::write_u32(&mut encoded, interner.intern(key.as_str()))?;
rmp::encode::write_u32(&mut encoded, interner.intern_value(value))?;
if let Some(resource) = resource {
for (key, value) in resource.iter() {
rmp::encode::write_u32(&mut encoded, interner.intern(key.as_str()))?;
rmp::encode::write_u32(&mut encoded, interner.intern_value(value))?;
}
}

write_unified_tags(&mut encoded, interner, unified_tags)?;
Expand Down
Loading
Loading