Skip to content

Commit

Permalink
depend on api or sdk explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
shaun-cox committed Aug 9, 2023
1 parent 1d4db15 commit 09bd144
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 84 deletions.
13 changes: 6 additions & 7 deletions opentelemetry-contrib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ 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 }
base64 = { version = "0.21", optional = true }
once_cell = "1.17.1"
opentelemetry = { version = "0.20", path = "../opentelemetry", features = ["trace"] }
opentelemetry_api = { version = "0.20", path = "../opentelemetry-api" }
opentelemetry-semantic-conventions = { version = "0.12", path = "../opentelemetry-semantic-conventions", optional = true }
serde_json = { version = "1", optional = true }
Expand All @@ -43,5 +42,5 @@ futures-core = { version = "0.3", optional = true }
futures-util = { version = "0.3", optional = true }

[dev-dependencies]
base64 = "0.13"
opentelemetry = { path = "../opentelemetry", features = ["trace", "testing"] }
base64 = "0.21"
opentelemetry_sdk = { path = "../opentelemetry-sdk", features = ["trace", "testing"] }
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
11 changes: 6 additions & 5 deletions opentelemetry-jaeger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ hyper = { version = "0.14", default-features = false, features = ["client"], opt
hyper-tls = { version = "0.5.0", default-features = false, optional = true }
isahc = { version = "1.4", default-features = false, optional = true }
js-sys = { version = "0.3", optional = true }
opentelemetry = { version = "0.20", default-features = false, features = ["trace"], path = "../opentelemetry" }
opentelemetry_api = { version = "0.20", default-features = false, features = ["trace"], path = "../opentelemetry-api" }
opentelemetry_sdk = { version = "0.20", default-features = false, features = ["trace"], path = "../opentelemetry-sdk" }
opentelemetry-http = { version = "0.9", path = "../opentelemetry-http", optional = true }
opentelemetry-semantic-conventions = { version = "0.12", path = "../opentelemetry-semantic-conventions" }
pin-project-lite = { version = "0.2", optional = true }
Expand All @@ -53,7 +54,7 @@ futures-util = { version = "0.3", default-features = false, features = ["std", "
tokio = { version = "1.0", features = ["net", "sync"] }
bytes = "1"
futures-executor = "0.3"
opentelemetry = { default-features = false, features = ["trace", "testing"], path = "../opentelemetry" }
opentelemetry_sdk = { default-features = false, features = ["trace", "testing"], path = "../opentelemetry-sdk" }

[dependencies.web-sys]
version = "0.3.4"
Expand Down Expand Up @@ -102,7 +103,7 @@ wasm_collector_client = [
"wasm-bindgen-futures",
"web-sys",
]
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"]
integration_test = ["tonic", "prost", "prost-types", "rt-tokio", "collector_client", "hyper_collector_client", "hyper_tls_collector_client", "reqwest_collector_client", "surf_collector_client", "isahc_collector_client"]
29 changes: 16 additions & 13 deletions opentelemetry-jaeger/src/exporter/config/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ use crate::exporter::config::{
};
use crate::exporter::uploader::{AsyncUploader, SyncUploader, Uploader};
use crate::{Error, Exporter, JaegerTraceRuntime};
use opentelemetry::sdk;
use opentelemetry::sdk::trace::{BatchConfig, Config, TracerProvider};
use opentelemetry::trace::TraceError;
use opentelemetry_api::trace::TraceError;
use opentelemetry_sdk::trace::{BatchSpanProcessor, Tracer};
use opentelemetry_sdk::{
self,
trace::{BatchConfig, Config, TracerProvider},
};
use std::borrow::BorrowMut;
use std::sync::Arc;
use std::{env, net};
Expand Down Expand Up @@ -74,8 +77,8 @@ const DEFAULT_AGENT_ENDPOINT_PORT: &str = "6831";
#[derive(Debug)]
pub struct AgentPipeline {
transformation_config: TransformationConfig,
trace_config: Option<sdk::trace::Config>,
batch_config: Option<sdk::trace::BatchConfig>,
trace_config: Option<Config>,
batch_config: Option<BatchConfig>,
agent_endpoint: Result<Vec<net::SocketAddr>, crate::Error>,
max_packet_size: usize,
auto_split_batch: bool,
Expand Down Expand Up @@ -235,12 +238,12 @@ impl AgentPipeline {
///
/// let pipeline = opentelemetry_jaeger::new_agent_pipeline()
/// .with_trace_config(
/// sdk::trace::Config::default()
/// Config::default()
/// .with_resource(Resource::new(vec![KeyValue::new("service.name", "my-service")]))
/// );
///
/// ```
pub fn with_trace_config(mut self, config: sdk::trace::Config) -> Self {
pub fn with_trace_config(mut self, config: Config) -> Self {
self.set_trace_config(config);
self
}
Expand All @@ -253,7 +256,7 @@ impl AgentPipeline {
/// # Examples
/// Set max queue size.
/// ```rust
/// use opentelemetry::sdk::trace::BatchConfig;
/// use opentelemetry::BatchConfig;
///
/// let pipeline = opentelemetry_jaeger::new_agent_pipeline()
/// .with_batch_processor_config(
Expand All @@ -270,7 +273,7 @@ impl AgentPipeline {
///
/// The exporter will send each span to the agent upon the span ends.
pub fn build_simple(mut self) -> Result<TracerProvider, TraceError> {
let mut builder = sdk::trace::TracerProvider::builder();
let mut builder = TracerProvider::builder();

let (config, process) = build_config_and_process(
self.trace_config.take(),
Expand Down Expand Up @@ -304,7 +307,7 @@ impl AgentPipeline {
where
R: JaegerTraceRuntime,
{
let mut builder = sdk::trace::TracerProvider::builder();
let mut builder = TracerProvider::builder();

let export_instrument_library = self.transformation_config.export_instrument_library;
// build sdk trace config and jaeger process.
Expand All @@ -316,7 +319,7 @@ impl AgentPipeline {
let batch_config = self.batch_config.take();
let uploader = self.build_async_agent_uploader(runtime.clone())?;
let exporter = Exporter::new(process.into(), export_instrument_library, uploader);
let batch_processor = sdk::trace::BatchSpanProcessor::builder(exporter, runtime)
let batch_processor = BatchSpanProcessor::builder(exporter, runtime)
.with_batch_config(batch_config.unwrap_or_default())
.build();

Expand All @@ -330,7 +333,7 @@ impl AgentPipeline {
/// tracer provider.
///
/// The tracer name is `opentelemetry-jaeger`. The tracer version will be the version of this crate.
pub fn install_simple(self) -> Result<sdk::trace::Tracer, TraceError> {
pub fn install_simple(self) -> Result<Tracer, TraceError> {
let tracer_provider = self.build_simple()?;
install_tracer_provider_and_get_tracer(tracer_provider)
}
Expand All @@ -339,7 +342,7 @@ impl AgentPipeline {
/// tracer provider.
///
/// The tracer name is `opentelemetry-jaeger`. The tracer version will be the version of this crate.
pub fn install_batch<R>(self, runtime: R) -> Result<sdk::trace::Tracer, TraceError>
pub fn install_batch<R>(self, runtime: R) -> Result<Tracer, TraceError>
where
R: JaegerTraceRuntime,
{
Expand Down
24 changes: 12 additions & 12 deletions opentelemetry-jaeger/src/exporter/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
//! [jaeger deployment guide]: https://www.jaegertracing.io/docs/1.31/deployment

use crate::Process;
use opentelemetry::trace::{TraceError, TracerProvider};
use opentelemetry::{global, sdk, KeyValue};
use opentelemetry_api::{global, trace::TraceError, KeyValue};
use opentelemetry_sdk::trace::{BatchConfig, Config, Tracer, TracerProvider};
use opentelemetry_semantic_conventions as semcov;

/// Config a exporter that sends the spans to a [jaeger agent](https://www.jaegertracing.io/docs/1.31/deployment/#agent).
Expand Down Expand Up @@ -42,9 +42,9 @@ trait HasRequiredConfig {
where
T: FnOnce(&mut TransformationConfig);

fn set_trace_config(&mut self, config: sdk::trace::Config);
fn set_trace_config(&mut self, config: Config);

fn set_batch_config(&mut self, config: sdk::trace::BatchConfig);
fn set_batch_config(&mut self, config: BatchConfig);
}

// To reduce the overhead of copying service name in every spans. We convert resource into jaeger tags
Expand All @@ -53,9 +53,9 @@ trait HasRequiredConfig {
// There are multiple ways to set the service name. A `service.name` tag will be always added
// to the process tags.
fn build_config_and_process(
config: Option<sdk::trace::Config>,
config: Option<Config>,
service_name_opt: Option<String>,
) -> (sdk::trace::Config, Process) {
) -> (Config, Process) {
let config = config.unwrap_or_default();

let service_name = service_name_opt.unwrap_or_else(|| {
Expand Down Expand Up @@ -86,9 +86,8 @@ fn build_config_and_process(
mod tests {
use crate::exporter::config::build_config_and_process;
use crate::new_agent_pipeline;
use opentelemetry::sdk::trace::Config;
use opentelemetry::sdk::Resource;
use opentelemetry::KeyValue;
use opentelemetry_api::KeyValue;
use opentelemetry_sdk::{trace::Config, Resource};
use std::env;

#[test]
Expand Down Expand Up @@ -118,9 +117,10 @@ mod tests {
}

pub(crate) fn install_tracer_provider_and_get_tracer(
tracer_provider: sdk::trace::TracerProvider,
) -> Result<sdk::trace::Tracer, TraceError> {
let tracer = tracer_provider.versioned_tracer(
tracer_provider: TracerProvider,
) -> Result<Tracer, TraceError> {
let tracer = opentelemetry_api::trace::TracerProvider::versioned_tracer(
&tracer_provider,
"opentelemetry-jaeger",
Some(env!("CARGO_PKG_VERSION")),
Some(semcov::SCHEMA_URL),
Expand Down
49 changes: 25 additions & 24 deletions opentelemetry-jaeger/src/exporter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,30 @@ use std::convert::TryFrom;

use self::runtime::JaegerTraceRuntime;
use self::thrift::jaeger;
use crate::exporter::uploader::Uploader;
use futures_core::future::BoxFuture;
use opentelemetry_api::{
trace::{Event, Link, SpanKind, Status},
InstrumentationLibrary, Key, KeyValue,
};
use opentelemetry_sdk::{
export::{
trace::{ExportResult, SpanData, SpanExporter},
ExportError,
},
trace::{EvictedHashMap, EvictedQueue},
};
use std::convert::TryInto;
use std::fmt::Display;
use std::io;
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, ToSocketAddrs};
use std::sync::Arc;
use std::time::{Duration, SystemTime};

#[cfg(feature = "isahc_collector_client")]
#[allow(unused_imports)] // this is actually used to configure authentication
use isahc::prelude::Configurable;

use opentelemetry::sdk::export::ExportError;
use opentelemetry::{
sdk,
sdk::export::trace,
trace::{Event, Link, SpanKind, Status},
Key, KeyValue,
};

use crate::exporter::uploader::Uploader;
use std::time::{Duration, SystemTime};

/// Instrument Library name MUST be reported in Jaeger Span tags with the following key
const INSTRUMENTATION_LIBRARY_NAME: &str = "otel.library.name";

Expand Down Expand Up @@ -78,8 +80,8 @@ pub struct Process {
pub tags: Vec<KeyValue>,
}

impl trace::SpanExporter for Exporter {
fn export(&mut self, batch: Vec<trace::SpanData>) -> BoxFuture<'static, trace::ExportResult> {
impl SpanExporter for Exporter {
fn export(&mut self, batch: Vec<SpanData>) -> BoxFuture<'static, ExportResult> {
let mut jaeger_spans: Vec<jaeger::Span> = Vec::with_capacity(batch.len());
let process = self.process.clone();

Expand All @@ -99,7 +101,7 @@ impl trace::SpanExporter for Exporter {
}
}

fn links_to_references(links: sdk::trace::EvictedQueue<Link>) -> Option<Vec<jaeger::SpanRef>> {
fn links_to_references(links: EvictedQueue<Link>) -> Option<Vec<jaeger::SpanRef>> {
if !links.is_empty() {
let refs = links
.iter()
Expand All @@ -125,10 +127,7 @@ fn links_to_references(links: sdk::trace::EvictedQueue<Link>) -> Option<Vec<jaeg
}

/// Convert spans to jaeger thrift span for exporting.
fn convert_otel_span_into_jaeger_span(
span: trace::SpanData,
export_instrument_lib: bool,
) -> jaeger::Span {
fn convert_otel_span_into_jaeger_span(span: SpanData, export_instrument_lib: bool) -> jaeger::Span {
let trace_id_bytes = span.span_context.trace_id().to_bytes();
let (high, low) = trace_id_bytes.split_at(8);
let trace_id_high = i64::from_be_bytes(high.try_into().unwrap());
Expand Down Expand Up @@ -166,8 +165,8 @@ fn convert_otel_span_into_jaeger_span(
}

fn build_span_tags(
attrs: sdk::trace::EvictedHashMap,
instrumentation_lib: Option<sdk::InstrumentationLibrary>,
attrs: EvictedHashMap,
instrumentation_lib: Option<InstrumentationLibrary>,
status: Status,
kind: SpanKind,
) -> Vec<jaeger::Tag> {
Expand Down Expand Up @@ -255,7 +254,7 @@ impl UserOverrides {
}
}

fn events_to_logs(events: sdk::trace::EvictedQueue<Event>) -> Option<Vec<jaeger::Log>> {
fn events_to_logs(events: EvictedQueue<Event>) -> Option<Vec<jaeger::Log>> {
if events.is_empty() {
None
} else {
Expand Down Expand Up @@ -358,9 +357,11 @@ mod tests {
use super::SPAN_KIND;
use crate::exporter::thrift::jaeger::Tag;
use crate::exporter::{build_span_tags, OTEL_STATUS_CODE, OTEL_STATUS_DESCRIPTION};
use opentelemetry::sdk::trace::EvictedHashMap;
use opentelemetry::trace::{SpanKind, Status};
use opentelemetry::KeyValue;
use opentelemetry_api::{
trace::{SpanKind, Status},
KeyValue,
};
use opentelemetry_sdk::trace::EvictedHashMap;

fn assert_tag_contains(tags: Vec<Tag>, key: &'static str, expect_val: &'static str) {
assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-jaeger/src/exporter/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
))]
use crate::exporter::addrs_and_family;
use async_trait::async_trait;
use opentelemetry::{runtime::RuntimeChannel, sdk::trace::BatchMessage};
use opentelemetry_sdk::{runtime::RuntimeChannel, trace::BatchMessage};
use std::net::ToSocketAddrs;

/// Jaeger Trace Runtime is an extension to [`RuntimeChannel`].
Expand Down
5 changes: 2 additions & 3 deletions opentelemetry-jaeger/src/exporter/thrift/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//! Thrift generated Jaeger client
//!
//! Definitions: <https://github.com/uber/jaeger-idl/blob/master/thrift/>
use std::time::{Duration, SystemTime};

use opentelemetry::trace::Event;
use opentelemetry::{Key, KeyValue, Value};
use opentelemetry_api::{trace::Event, Key, KeyValue, Value};
use std::time::{Duration, SystemTime};

pub(crate) mod agent;
pub(crate) mod jaeger;
Expand Down
Loading

0 comments on commit 09bd144

Please sign in to comment.