Skip to content

Commit

Permalink
depend on api or sdk explicitly as first step
Browse files Browse the repository at this point in the history
  • Loading branch information
shaun-cox committed Aug 10, 2023
1 parent 1d4db15 commit 9431dcd
Show file tree
Hide file tree
Showing 27 changed files with 179 additions and 188 deletions.
10 changes: 5 additions & 5 deletions opentelemetry-contrib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ default = []
base64_format = ["base64", "binary_propagator"]
binary_propagator = []
jaeger_json_exporter = ["serde_json", "futures-core", "futures-util", "async-trait", "opentelemetry-semantic-conventions"]
rt-tokio = ["tokio", "opentelemetry/rt-tokio"]
rt-tokio-current-thread = ["tokio", "opentelemetry/rt-tokio-current-thread"]
rt-async-std = ["async-std", "opentelemetry/rt-async-std"]
rt-tokio = ["tokio", "opentelemetry_sdk/rt-tokio"]
rt-tokio-current-thread = ["tokio", "opentelemetry_sdk/rt-tokio-current-thread"]
rt-async-std = ["async-std", "opentelemetry_sdk/rt-async-std"]

[dependencies]
async-std = { version = "1.10", optional = true }
async-trait = { version = "0.1", optional = true }
base64 = { version = "0.13", optional = true }
once_cell = "1.17.1"
opentelemetry = { version = "0.20", path = "../opentelemetry", features = ["trace"] }
opentelemetry_api = { version = "0.20", path = "../opentelemetry-api" }
opentelemetry_sdk = { version = "0.20", path = "../opentelemetry-sdk" }
opentelemetry-semantic-conventions = { version = "0.12", path = "../opentelemetry-semantic-conventions", optional = true }
serde_json = { version = "1", optional = true }
tokio = { version = "1.0", features = ["fs", "io-util"], optional = true }
Expand All @@ -44,4 +44,4 @@ futures-util = { version = "0.3", optional = true }

[dev-dependencies]
base64 = "0.13"
opentelemetry = { path = "../opentelemetry", features = ["trace", "testing"] }
opentelemetry_sdk = { path = "../opentelemetry-sdk", features = ["trace", "testing"] }
44 changes: 20 additions & 24 deletions opentelemetry-contrib/src/trace/exporter/jaeger_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
use async_trait::async_trait;
use futures_core::future::BoxFuture;
use futures_util::FutureExt;
use opentelemetry::runtime::RuntimeChannel;
use opentelemetry::sdk::export::trace::{ExportResult, SpanData, SpanExporter};
use opentelemetry::sdk::trace::{BatchMessage, Tracer};
use opentelemetry::trace::{SpanId, TraceError};
use opentelemetry_api::trace::{SpanId, TraceError};
use opentelemetry_sdk::{
export::trace::{ExportResult, SpanData, SpanExporter},
runtime::RuntimeChannel,
trace::{BatchMessage, Tracer, TracerProvider},
};
use opentelemetry_semantic_conventions::SCHEMA_URL;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -40,21 +42,17 @@ impl<R: JaegerJsonRuntime> JaegerJsonExporter<R> {

/// Install the exporter using the internal provided runtime
pub fn install_batch(self) -> Tracer {
use opentelemetry::trace::TracerProvider;

let runtime = self.runtime.clone();
let provider_builder =
opentelemetry::sdk::trace::TracerProvider::builder().with_batch_exporter(self, runtime);

let provider_builder = TracerProvider::builder().with_batch_exporter(self, runtime);

Check warning on line 46 in opentelemetry-contrib/src/trace/exporter/jaeger_json.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-contrib/src/trace/exporter/jaeger_json.rs#L46

Added line #L46 was not covered by tests
let provider = provider_builder.build();

let tracer = provider.versioned_tracer(
let tracer = opentelemetry_api::trace::TracerProvider::versioned_tracer(
&provider,

Check warning on line 49 in opentelemetry-contrib/src/trace/exporter/jaeger_json.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-contrib/src/trace/exporter/jaeger_json.rs#L48-L49

Added lines #L48 - L49 were not covered by tests
"opentelemetry",
Some(env!("CARGO_PKG_VERSION")),
Some(SCHEMA_URL),
None,
);
let _ = opentelemetry::global::set_tracer_provider(provider);
let _ = opentelemetry_api::global::set_tracer_provider(provider);

Check warning on line 55 in opentelemetry-contrib/src/trace/exporter/jaeger_json.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-contrib/src/trace/exporter/jaeger_json.rs#L55

Added line #L55 was not covered by tests

tracer
}
Expand Down Expand Up @@ -120,9 +118,7 @@ impl<R: JaegerJsonRuntime> SpanExporter for JaegerJsonExporter<R> {
}
}

fn span_data_to_jaeger_json(
span: opentelemetry::sdk::export::trace::SpanData,
) -> serde_json::Value {
fn span_data_to_jaeger_json(span: SpanData) -> serde_json::Value {

Check warning on line 121 in opentelemetry-contrib/src/trace/exporter/jaeger_json.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-contrib/src/trace/exporter/jaeger_json.rs#L121

Added line #L121 was not covered by tests
let events = span
.events
.iter()
Expand Down Expand Up @@ -203,13 +199,13 @@ fn span_data_to_jaeger_json(
})
}

fn opentelemetry_value_to_json(value: &opentelemetry::Value) -> (&str, serde_json::Value) {
fn opentelemetry_value_to_json(value: &opentelemetry_api::Value) -> (&str, serde_json::Value) {

Check warning on line 202 in opentelemetry-contrib/src/trace/exporter/jaeger_json.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-contrib/src/trace/exporter/jaeger_json.rs#L202

Added line #L202 was not covered by tests
match value {
opentelemetry::Value::Bool(b) => ("bool", serde_json::json!(b)),
opentelemetry::Value::I64(i) => ("int64", serde_json::json!(i)),
opentelemetry::Value::F64(f) => ("float64", serde_json::json!(f)),
opentelemetry::Value::String(s) => ("string", serde_json::json!(s.as_str())),
v @ opentelemetry::Value::Array(_) => ("string", serde_json::json!(v.to_string())),
opentelemetry_api::Value::Bool(b) => ("bool", serde_json::json!(b)),
opentelemetry_api::Value::I64(i) => ("int64", serde_json::json!(i)),
opentelemetry_api::Value::F64(f) => ("float64", serde_json::json!(f)),
opentelemetry_api::Value::String(s) => ("string", serde_json::json!(s.as_str())),
v @ opentelemetry_api::Value::Array(_) => ("string", serde_json::json!(v.to_string())),

Check warning on line 208 in opentelemetry-contrib/src/trace/exporter/jaeger_json.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-contrib/src/trace/exporter/jaeger_json.rs#L204-L208

Added lines #L204 - L208 were not covered by tests
}
}

Expand All @@ -226,7 +222,7 @@ pub trait JaegerJsonRuntime: RuntimeChannel<BatchMessage> + std::fmt::Debug {

#[cfg(feature = "rt-tokio")]
#[async_trait]
impl JaegerJsonRuntime for opentelemetry::runtime::Tokio {
impl JaegerJsonRuntime for opentelemetry_sdk::runtime::Tokio {
async fn create_dir(&self, path: &Path) -> ExportResult {
if tokio::fs::metadata(path).await.is_err() {
tokio::fs::create_dir_all(path)
Expand Down Expand Up @@ -256,7 +252,7 @@ impl JaegerJsonRuntime for opentelemetry::runtime::Tokio {

#[cfg(feature = "rt-tokio-current-thread")]
#[async_trait]
impl JaegerJsonRuntime for opentelemetry::runtime::TokioCurrentThread {
impl JaegerJsonRuntime for opentelemetry_sdk::runtime::TokioCurrentThread {
async fn create_dir(&self, path: &Path) -> ExportResult {
if tokio::fs::metadata(path).await.is_err() {
tokio::fs::create_dir_all(path)
Expand Down Expand Up @@ -286,7 +282,7 @@ impl JaegerJsonRuntime for opentelemetry::runtime::TokioCurrentThread {

#[cfg(feature = "rt-async-std")]
#[async_trait]
impl JaegerJsonRuntime for opentelemetry::runtime::AsyncStd {
impl JaegerJsonRuntime for opentelemetry_sdk::runtime::AsyncStd {
async fn create_dir(&self, path: &Path) -> ExportResult {
if async_std::fs::metadata(path).await.is_err() {
async_std::fs::create_dir_all(path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use crate::trace::propagator::binary::binary_propagator::BinaryFormat;

use base64::{decode, encode};
use opentelemetry::trace::SpanContext;
use opentelemetry_api::trace::SpanContext;

/// Used to serialize and deserialize `SpanContext`s to and from a base64
/// representation.
Expand Down Expand Up @@ -43,7 +43,7 @@ where
mod tests {
use super::*;
use crate::trace::propagator::binary::binary_propagator::BinaryPropagator;
use opentelemetry::trace::{SpanId, TraceFlags, TraceId, TraceState};
use opentelemetry_api::trace::{SpanId, TraceFlags, TraceId, TraceState};

#[rustfmt::skip]
fn to_base64_data() -> Vec<(SpanContext, String)> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//!
//! `BinaryFormat` MUST expose the APIs that serializes values into bytes,
//! and deserializes values from bytes.
use opentelemetry::trace::{SpanContext, SpanId, TraceFlags, TraceId, TraceState};
use opentelemetry_api::trace::{SpanContext, SpanId, TraceFlags, TraceId, TraceState};
use std::convert::TryInto;

/// Used to serialize and deserialize `SpanContext`s to and from a binary
Expand Down Expand Up @@ -88,7 +88,7 @@ impl BinaryFormat for BinaryPropagator {
#[cfg(test)]
mod tests {
use super::*;
use opentelemetry::trace::TraceState;
use opentelemetry_api::trace::TraceState;

#[rustfmt::skip]
fn to_bytes_data() -> Vec<(SpanContext, [u8; 29])> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
//!
//! [w3c trace-context docs]: https://w3c.github.io/trace-context/#traceresponse-header
use once_cell::sync::Lazy;
use opentelemetry::trace::{SpanContext, SpanId, TraceId, TraceState};
use opentelemetry_api::{
propagation::{text_map_propagator::FieldIter, Extractor, Injector, TextMapPropagator},
trace::{TraceContextExt, TraceFlags},
trace::{SpanContext, SpanId, TraceContextExt, TraceFlags, TraceId, TraceState},
Context,
};

Expand Down Expand Up @@ -132,11 +131,11 @@ impl TextMapPropagator for TraceContextResponsePropagator {
#[cfg(test)]
mod tests {
use super::*;
use opentelemetry::{testing::trace::TestSpan, trace::TraceState};
use opentelemetry_api::{
propagation::{Extractor, TextMapPropagator},
trace::{SpanContext, SpanId, TraceId},
};
use opentelemetry_api::{testing::trace::TestSpan, trace::TraceState};
use std::{collections::HashMap, str::FromStr};

#[rustfmt::skip]
Expand Down
9 changes: 5 additions & 4 deletions opentelemetry-datadog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ reqwest-client = ["reqwest", "opentelemetry-http/reqwest"]
surf-client = ["surf", "opentelemetry-http/surf"]

[dependencies]
indexmap = "1.8"
indexmap = "2.0"
once_cell = "1.12"
opentelemetry = { version = "0.20", path = "../opentelemetry", features = ["trace"] }
opentelemetry_api = { version = "0.20", path = "../opentelemetry-api", features = ["trace"] }
opentelemetry_sdk = { version = "0.20", path = "../opentelemetry-sdk", features = ["trace"] }
opentelemetry-http = { version = "0.9", path = "../opentelemetry-http" }
opentelemetry-semantic-conventions = { version = "0.12", path = "../opentelemetry-semantic-conventions" }
rmp = "0.8"
url = "2.2"
reqwest = { version = "0.11", default-features = false, optional = true }
surf = { version = "2.0", default-features = false, optional = true }
thiserror = "1.0"
itertools = "0.10"
itertools = "0.11"
http = "0.2"
futures-core = "0.3"

Expand All @@ -44,7 +45,7 @@ base64 = "0.13"
bytes = "1"
futures-util = { version = "0.3", features = ["io"] }
isahc = "1.4"
opentelemetry = { path = "../opentelemetry", features = ["trace", "testing"] }
opentelemetry_sdk = { path = "../opentelemetry-sdk", features = ["trace", "testing"] }

[[example]]
name = "datadog"
Expand Down
5 changes: 2 additions & 3 deletions opentelemetry-datadog/examples/datadog.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use opentelemetry::global;
use opentelemetry::global::shutdown_tracer_provider;
use opentelemetry::{
use opentelemetry_api::{
global::{self, shutdown_tracer_provider},
trace::{Span, TraceContextExt, Tracer},
Key,
};
Expand Down
48 changes: 23 additions & 25 deletions opentelemetry-datadog/src/exporter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,23 @@ mod model;
pub use model::ApiVersion;
pub use model::Error;
pub use model::FieldMappingFn;
use opentelemetry::runtime::RuntimeChannel;

use std::borrow::Cow;
use std::fmt::{Debug, Formatter};

use crate::exporter::model::FieldMapping;
use futures_core::future::BoxFuture;
use http::{Method, Request, Uri};
use itertools::Itertools;
use opentelemetry::sdk::export::trace;
use opentelemetry::sdk::export::trace::SpanData;
use opentelemetry::sdk::resource::ResourceDetector;
use opentelemetry::sdk::resource::SdkProvidedResourceDetector;
use opentelemetry::sdk::trace::{BatchMessage, Config};
use opentelemetry::sdk::Resource;
use opentelemetry::trace::TraceError;
use opentelemetry::{global, sdk, trace::TracerProvider, KeyValue};
use opentelemetry_api::{global, trace::TraceError, KeyValue};
use opentelemetry_http::{HttpClient, ResponseExt};
use opentelemetry_sdk::{
export::trace::{ExportResult, SpanData, SpanExporter},
resource::{ResourceDetector, SdkProvidedResourceDetector},
runtime::RuntimeChannel,
trace::{BatchMessage, Config, Tracer, TracerProvider},
Resource,
};
use opentelemetry_semantic_conventions as semcov;
use std::borrow::Cow;
use std::fmt::{Debug, Formatter};
use std::sync::Arc;
use std::time::Duration;
use url::Url;
Expand Down Expand Up @@ -143,7 +141,7 @@ pub fn new_pipeline() -> DatadogPipelineBuilder {
/// Builder for `ExporterConfig` struct.
pub struct DatadogPipelineBuilder {
agent_endpoint: String,
trace_config: Option<sdk::trace::Config>,
trace_config: Option<Config>,
api_version: ApiVersion,
client: Option<Arc<dyn HttpClient>>,
mapping: Mapping,
Expand Down Expand Up @@ -283,14 +281,14 @@ impl DatadogPipelineBuilder {
}

/// Install the Datadog trace exporter pipeline using a simple span processor.
pub fn install_simple(mut self) -> Result<sdk::trace::Tracer, TraceError> {
pub fn install_simple(mut self) -> Result<Tracer, TraceError> {

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L284 was not covered by tests
let (config, service_name) = self.build_config_and_service_name();
let exporter = self.build_exporter_with_service_name(service_name)?;
let mut provider_builder =
sdk::trace::TracerProvider::builder().with_simple_exporter(exporter);
let mut provider_builder = TracerProvider::builder().with_simple_exporter(exporter);

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L287 was not covered by tests
provider_builder = provider_builder.with_config(config);
let provider = provider_builder.build();
let tracer = provider.versioned_tracer(
let tracer = opentelemetry_api::trace::TracerProvider::versioned_tracer(
&provider,

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

View check run for this annotation

Codecov / codecov/patch

opentelemetry-datadog/src/exporter/mod.rs#L290-L291

Added lines #L290 - L291 were not covered by tests
"opentelemetry-datadog",
Some(env!("CARGO_PKG_VERSION")),
Some(semcov::SCHEMA_URL),
Expand All @@ -305,14 +303,14 @@ impl DatadogPipelineBuilder {
pub fn install_batch<R: RuntimeChannel<BatchMessage>>(
mut self,
runtime: R,
) -> Result<sdk::trace::Tracer, TraceError> {
) -> Result<Tracer, TraceError> {

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L306 was not covered by tests
let (config, service_name) = self.build_config_and_service_name();
let exporter = self.build_exporter_with_service_name(service_name)?;
let mut provider_builder =
sdk::trace::TracerProvider::builder().with_batch_exporter(exporter, runtime);
let mut provider_builder = TracerProvider::builder().with_batch_exporter(exporter, runtime);

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L309 was not covered by tests
provider_builder = provider_builder.with_config(config);
let provider = provider_builder.build();
let tracer = provider.versioned_tracer(
let tracer = opentelemetry_api::trace::TracerProvider::versioned_tracer(
&provider,

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

View check run for this annotation

Codecov / codecov/patch

opentelemetry-datadog/src/exporter/mod.rs#L312-L313

Added lines #L312 - L313 were not covered by tests
"opentelemetry-datadog",
Some(env!("CARGO_PKG_VERSION")),
Some(semcov::SCHEMA_URL),
Expand Down Expand Up @@ -358,7 +356,7 @@ impl DatadogPipelineBuilder {
}

/// Assign the SDK trace configuration
pub fn with_trace_config(mut self, config: sdk::trace::Config) -> Self {
pub fn with_trace_config(mut self, config: Config) -> Self {

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L359 was not covered by tests
self.trace_config = Some(config);
self
}
Expand Down Expand Up @@ -411,14 +409,14 @@ fn group_into_traces(spans: Vec<SpanData>) -> Vec<Vec<SpanData>> {
async fn send_request(
client: Arc<dyn HttpClient>,
request: http::Request<Vec<u8>>,
) -> trace::ExportResult {
) -> ExportResult {

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L412 was not covered by tests
let _ = client.send(request).await?.error_for_status()?;
Ok(())
}

impl trace::SpanExporter for DatadogExporter {
impl SpanExporter for DatadogExporter {
/// Export spans to datadog-agent
fn export(&mut self, batch: Vec<SpanData>) -> BoxFuture<'static, trace::ExportResult> {
fn export(&mut self, batch: Vec<SpanData>) -> BoxFuture<'static, ExportResult> {

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L419 was not covered by tests
let request = match self.build_request(batch) {
Ok(req) => req,
Err(err) => return Box::pin(std::future::ready(Err(err))),
Expand Down
17 changes: 10 additions & 7 deletions opentelemetry-datadog/src/exporter/model/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::exporter::ModelConfig;
use http::uri;
use opentelemetry::sdk::export::{
use opentelemetry_sdk::export::{
trace::{self, SpanData},
ExportError,
};
Expand Down Expand Up @@ -189,12 +189,15 @@ impl ApiVersion {
#[cfg(test)]
pub(crate) mod tests {
use super::*;
use opentelemetry::sdk::InstrumentationLibrary;
use opentelemetry::sdk::{self, Resource};
use opentelemetry::{
use opentelemetry_api::{
trace::{SpanContext, SpanId, SpanKind, Status, TraceFlags, TraceId, TraceState},
Key, KeyValue,
};
use opentelemetry_sdk::{
self,
trace::{EvictedHashMap, EvictedQueue},
InstrumentationLibrary, Resource,
};
use std::borrow::Cow;
use std::time::{Duration, SystemTime};

Expand All @@ -215,11 +218,11 @@ pub(crate) mod tests {
let end_time = start_time.checked_add(Duration::from_secs(1)).unwrap();

let capacity = 3;
let mut attributes = sdk::trace::EvictedHashMap::new(capacity, capacity as usize);
let mut attributes = EvictedHashMap::new(capacity, capacity as usize);
attributes.insert(Key::new("span.type").string("web"));

let events = sdk::trace::EvictedQueue::new(capacity);
let links = sdk::trace::EvictedQueue::new(capacity);
let events = EvictedQueue::new(capacity);
let links = EvictedQueue::new(capacity);
let resource = Resource::new(vec![KeyValue::new("host.name", "test")]);

trace::SpanData {
Expand Down
8 changes: 3 additions & 5 deletions opentelemetry-datadog/src/exporter/model/v03.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use crate::exporter::model::{Error, SAMPLING_PRIORITY_KEY};
use crate::exporter::ModelConfig;
use opentelemetry::sdk::export::trace;
use opentelemetry::sdk::export::trace::SpanData;
use opentelemetry::trace::Status;
use opentelemetry::{Key, Value};
use opentelemetry_api::{trace::Status, Key, Value};
use opentelemetry_sdk::export::trace::SpanData;
use std::time::SystemTime;

pub(crate) fn encode<S, N, R>(
model_config: &ModelConfig,
traces: Vec<Vec<trace::SpanData>>,
traces: Vec<Vec<SpanData>>,
get_service_name: S,
get_name: N,
get_resource: R,
Expand Down
Loading

0 comments on commit 9431dcd

Please sign in to comment.