Skip to content

Commit

Permalink
feat(otlp,sdk): add schema_url to tracer.
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyCpp committed Mar 1, 2022
1 parent 104d66d commit f78d41f
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions opentelemetry-datadog/src/exporter/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ pub(crate) mod tests {
status_message: "".into(),
resource: None,
instrumentation_lib: InstrumentationLibrary::new("component", None),
schema_url: "",
}
}

Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-proto/src/transform/traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub mod tonic {
schema_url: "".to_string(), // todo: replace with actual schema url.
instrumentation_library_spans: vec![InstrumentationLibrarySpans {
instrumentation_library: Default::default(),
schema_url: "".to_string(), // todo: replace with actual schema url.
schema_url: source_span.schema_url.into(),
spans: vec![Span {
trace_id: source_span.span_context.trace_id().to_bytes().to_vec(),
span_id: source_span.span_context.span_id().to_bytes().to_vec(),
Expand Down
1 change: 1 addition & 0 deletions opentelemetry-sdk/benches/batch_span_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ fn get_span_data() -> Vec<SpanData> {
status_message: Default::default(),
resource: None,
instrumentation_lib: Default::default(),
schema_url: "",
})
.collect::<Vec<SpanData>>()
}
Expand Down
4 changes: 4 additions & 0 deletions opentelemetry-sdk/src/export/trace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,8 @@ pub struct SpanData {
pub resource: Option<Arc<crate::Resource>>,
/// Instrumentation library that produced this span
pub instrumentation_lib: crate::InstrumentationLibrary,
/// [Schema url] of this span and it's events
///
/// [Schema url]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/schemas/overview.md#schema-url
pub schema_url: &'static str,
}
1 change: 1 addition & 0 deletions opentelemetry-sdk/src/testing/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub fn new_test_export_span_data() -> SpanData {
status_message: "".into(),
resource: config.resource,
instrumentation_lib: InstrumentationLibrary::default(),
schema_url: "",
}
}

Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-sdk/src/trace/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl opentelemetry_api::trace::TracerProvider for TracerProvider {
&self,
name: impl Into<Cow<'static, str>>,
version: Option<&'static str>,
_schema_url: Option<&'static str>,
schema_url: Option<&'static str>,
) -> Self::Tracer {
let name = name.into();
// Use default value if name is invalid empty string
Expand All @@ -92,7 +92,7 @@ impl opentelemetry_api::trace::TracerProvider for TracerProvider {
let instrumentation_lib =
InstrumentationLibrary::new(component_name, version.map(Into::into));

Tracer::new(instrumentation_lib, Arc::downgrade(&self.inner))
Tracer::new(instrumentation_lib, Arc::downgrade(&self.inner), schema_url)
}

/// Force flush all remaining spans in span processors and return results.
Expand Down
1 change: 1 addition & 0 deletions opentelemetry-sdk/src/trace/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ fn build_export_data(
status_message: data.status_message,
resource,
instrumentation_lib: tracer.instrumentation_library().clone(),
schema_url: tracer.schema_url(),
}
}

Expand Down
15 changes: 14 additions & 1 deletion opentelemetry-sdk/src/trace/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use std::sync::Weak;
#[derive(Clone)]
pub struct Tracer {
instrumentation_lib: InstrumentationLibrary,
schema_url: Option<&'static str>,
provider: Weak<TracerProviderInner>,
}

Expand All @@ -39,6 +40,7 @@ impl fmt::Debug for Tracer {
f.debug_struct("Tracer")
.field("name", &self.instrumentation_lib.name)
.field("version", &self.instrumentation_lib.version)
.field("schema_url", &self.schema_url)
.finish()
}
}
Expand All @@ -48,10 +50,12 @@ impl Tracer {
pub(crate) fn new(
instrumentation_lib: InstrumentationLibrary,
provider: Weak<TracerProviderInner>,
schema_url: Option<&'static str>,
) -> Self {
Tracer {
instrumentation_lib,
provider,
schema_url,
}
}

Expand All @@ -60,11 +64,20 @@ impl Tracer {
self.provider.upgrade().map(TracerProvider::new)
}

/// instrumentation library information of this tracer.
/// Instrumentation library information of this tracer.
pub fn instrumentation_library(&self) -> &InstrumentationLibrary {
&self.instrumentation_lib
}

/// [Schema url] of all the spans created by this tracer.
///
/// If no schema url was provided to tracer, it will return empty string
///
/// [Schema url]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/schemas/overview.md#schema-url
pub(crate) fn schema_url(&self) -> &'static str {
self.schema_url.unwrap_or("")
}

/// Make a sampling decision using the provided sampler for the span and context.
#[allow(clippy::too_many_arguments)]
fn make_sampling_decision(
Expand Down
1 change: 1 addition & 0 deletions opentelemetry-zipkin/src/exporter/model/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ mod tests {
status_message: status_msg.into(),
resource: None,
instrumentation_lib: Default::default(),
schema_url: "",
};
let local_endpoint = Endpoint::new("test".into(), None);
let span = into_zipkin_span(local_endpoint, span_data);
Expand Down

0 comments on commit f78d41f

Please sign in to comment.