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

feat(otlp,sdk): add schema_url to tracer. #743

Merged
merged 3 commits into from Mar 1, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion opentelemetry-api/src/common.rs
Expand Up @@ -272,17 +272,22 @@ pub struct InstrumentationLibrary {
pub name: Cow<'static, str>,
/// instrumentation library version, can be empty
pub version: Option<Cow<'static, str>>,
/// [Schema url] of spans and their events.
///
/// [Schema url]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/schemas/overview.md#schema-url
pub schema_url: Option<Cow<'static, str>>,
}

impl InstrumentationLibrary {
/// Create an InstrumentationLibrary from name and version.
pub fn new<T>(name: T, version: Option<T>) -> InstrumentationLibrary
pub fn new<T>(name: T, version: Option<T>, schema_url: Option<T>) -> InstrumentationLibrary
where
T: Into<Cow<'static, str>>,
{
InstrumentationLibrary {
name: name.into(),
version: version.map(Into::into),
schema_url: schema_url.map(Into::into),
}
}
}
19 changes: 14 additions & 5 deletions opentelemetry-api/src/global/metrics.rs
Expand Up @@ -14,8 +14,13 @@ pub struct GlobalMeterProvider {
}

impl MeterProvider for GlobalMeterProvider {
fn meter(&self, name: &'static str, version: Option<&'static str>) -> Meter {
self.provider.meter(name, version)
fn meter(
&self,
name: &'static str,
version: Option<&'static str>,
schema_url: Option<&'static str>,
) -> Meter {
self.provider.meter(name, version, schema_url)
}
}

Expand Down Expand Up @@ -58,10 +63,14 @@ pub fn meter_provider() -> GlobalMeterProvider {
///
/// This is a more convenient way of expressing `global::meter_provider().meter(name)`.
pub fn meter(name: &'static str) -> Meter {
meter_provider().meter(name, None)
meter_provider().meter(name, None, None)
}

/// Creates a [`Meter`] with the name and version.
pub fn meter_with_version(name: &'static str, version: &'static str) -> Meter {
meter_provider().meter(name, Some(version))
pub fn meter_with_version(
name: &'static str,
version: &'static str,
schema_url: &'static str,
) -> Meter {
meter_provider().meter(name, Some(version), Some(schema_url))
}
4 changes: 3 additions & 1 deletion opentelemetry-api/src/metrics/config.rs
Expand Up @@ -16,21 +16,23 @@ impl InstrumentConfig {
InstrumentConfig {
description: None,
unit: None,
instrumentation_library: InstrumentationLibrary::new(instrumentation_name, None),
instrumentation_library: InstrumentationLibrary::new(instrumentation_name, None, None),
}
}

/// Create a new config with instrumentation name and optional version
pub fn with_instrumentation<T: Into<Cow<'static, str>>>(
instrumentation_name: T,
instrumentation_version: Option<T>,
schema_url: Option<T>,
) -> Self {
InstrumentConfig {
description: None,
unit: None,
instrumentation_library: InstrumentationLibrary::new(
instrumentation_name,
instrumentation_version,
schema_url,
),
}
}
Expand Down
1 change: 1 addition & 0 deletions opentelemetry-api/src/metrics/counter.rs
Expand Up @@ -67,6 +67,7 @@ impl<'a, T> CounterBuilder<'a, T> {
name,
meter.instrumentation_library().name,
meter.instrumentation_library().version,
meter.instrumentation_library().schema_url,
InstrumentKind::Counter,
number_kind,
),
Expand Down
13 changes: 6 additions & 7 deletions opentelemetry-api/src/metrics/descriptor.rs
Expand Up @@ -21,6 +21,7 @@ impl Descriptor {
name: String,
instrumentation_name: T,
instrumentation_version: Option<T>,
schema_url: Option<T>,
instrument_kind: InstrumentKind,
number_kind: NumberKind,
) -> Self {
Expand All @@ -32,8 +33,11 @@ impl Descriptor {
instrumentation_version.as_ref().hash(&mut hasher);
instrument_kind.hash(&mut hasher);
number_kind.hash(&mut hasher);
let config =
InstrumentConfig::with_instrumentation(instrumentation_name, instrumentation_version);
let config = InstrumentConfig::with_instrumentation(
instrumentation_name,
instrumentation_version.map(Into::into),
schema_url.map(Into::into),
);

Descriptor {
name,
Expand Down Expand Up @@ -80,11 +84,6 @@ impl Descriptor {
self.config.instrumentation_name()
}

/// The version of library that provided instrumentation for this instrument. Optional
pub fn instrumentation_version(&self) -> Option<Cow<'static, str>> {
self.config.instrumentation_version()
}

/// Instrumentation library reference
pub fn instrumentation_library(&self) -> &InstrumentationLibrary {
&self.config.instrumentation_library
Expand Down
1 change: 1 addition & 0 deletions opentelemetry-api/src/metrics/histogram.rs
Expand Up @@ -67,6 +67,7 @@ impl<'a, T> HistogramBuilder<'a, T> {
name,
meter.instrumentation_library().name,
meter.instrumentation_library().version,
meter.instrumentation_library().schema_url,
InstrumentKind::Histogram,
number_kind,
),
Expand Down
6 changes: 5 additions & 1 deletion opentelemetry-api/src/metrics/meter.rs
@@ -1,3 +1,4 @@
use std::borrow::Cow;
use std::fmt;
use std::sync::Arc;

Expand All @@ -23,6 +24,7 @@ pub trait MeterProvider: fmt::Debug {
&self,
instrumentation_name: &'static str,
instrumentation_version: Option<&'static str>,
schema_url: Option<&'static str>,
) -> Meter;
}

Expand All @@ -48,15 +50,17 @@ pub struct Meter {

impl Meter {
/// Create a new named meter from a sdk implemented core
pub fn new<T: Into<&'static str>>(
pub fn new<T: Into<Cow<'static, str>>>(
instrumentation_name: T,
instrumentation_version: Option<T>,
schema_url: Option<T>,
core: Arc<dyn sdk_api::MeterCore + Send + Sync>,
) -> Self {
Meter {
instrumentation_library: InstrumentationLibrary::new(
instrumentation_name.into(),
instrumentation_version.map(Into::into),
schema_url.map(Into::into),
),
core,
}
Expand Down
11 changes: 8 additions & 3 deletions opentelemetry-api/src/metrics/noop.rs
Expand Up @@ -18,7 +18,7 @@ use std::any::Any;
use std::sync::Arc;

lazy_static::lazy_static! {
static ref NOOP_DESCRIPTOR: Descriptor = Descriptor::new(String::new(), "noop", None, InstrumentKind::Counter, NumberKind::U64);
static ref NOOP_DESCRIPTOR: Descriptor = Descriptor::new(String::new(), "noop", None, None, InstrumentKind::Counter, NumberKind::U64);
}

/// A no-op instance of a `MetricProvider`
Expand All @@ -35,8 +35,13 @@ impl NoopMeterProvider {
}

impl MeterProvider for NoopMeterProvider {
fn meter(&self, name: &'static str, version: Option<&'static str>) -> Meter {
Meter::new(name, version, Arc::new(NoopMeterCore::new()))
fn meter(
&self,
name: &'static str,
version: Option<&'static str>,
schema_url: Option<&'static str>,
) -> Meter {
Meter::new(name, version, schema_url, Arc::new(NoopMeterCore::new()))
}
}

Expand Down
3 changes: 3 additions & 0 deletions opentelemetry-api/src/metrics/observer.rs
Expand Up @@ -113,6 +113,7 @@ impl<'a, T> SumObserverBuilder<'a, T> {
name,
meter.instrumentation_library().name,
meter.instrumentation_library().version,
meter.instrumentation_library().schema_url,
InstrumentKind::SumObserver,
number_kind,
),
Expand Down Expand Up @@ -206,6 +207,7 @@ impl<'a, T> UpDownSumObserverBuilder<'a, T> {
name,
meter.instrumentation_library().name,
meter.instrumentation_library().version,
meter.instrumentation_library().schema_url,
InstrumentKind::UpDownSumObserver,
number_kind,
),
Expand Down Expand Up @@ -298,6 +300,7 @@ impl<'a, T> ValueObserverBuilder<'a, T> {
name,
meter.instrumentation_library().name,
meter.instrumentation_library().version,
meter.instrumentation_library().schema_url,
InstrumentKind::ValueObserver,
number_kind,
),
Expand Down
9 changes: 7 additions & 2 deletions opentelemetry-api/src/metrics/registry.rs
Expand Up @@ -20,8 +20,13 @@ pub fn meter_provider(core: Arc<dyn MeterCore + Send + Sync>) -> RegistryMeterPr
pub struct RegistryMeterProvider(Arc<dyn MeterCore + Send + Sync>);

impl MeterProvider for RegistryMeterProvider {
fn meter(&self, name: &'static str, version: Option<&'static str>) -> Meter {
Meter::new(name, version, self.0.clone())
fn meter(
&self,
name: &'static str,
version: Option<&'static str>,
schema_url: Option<&'static str>,
) -> Meter {
Meter::new(name, version, schema_url, self.0.clone())
}
}

Expand Down
1 change: 1 addition & 0 deletions opentelemetry-api/src/metrics/up_down_counter.rs
Expand Up @@ -67,6 +67,7 @@ impl<'a, T> UpDownCounterBuilder<'a, T> {
name,
meter.instrumentation_library().name,
meter.instrumentation_library().version,
meter.instrumentation_library().schema_url,
InstrumentKind::UpDownCounter,
number_kind,
),
Expand Down
1 change: 1 addition & 0 deletions opentelemetry-api/src/metrics/value_recorder.rs
Expand Up @@ -67,6 +67,7 @@ impl<'a, T> ValueRecorderBuilder<'a, T> {
name,
meter.instrumentation_library().name,
meter.instrumentation_library().version,
meter.instrumentation_library().schema_url,
InstrumentKind::Histogram,
number_kind,
),
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-datadog/src/exporter/model/mod.rs
Expand Up @@ -118,7 +118,7 @@ pub(crate) mod tests {
status_code: StatusCode::Ok,
status_message: "".into(),
resource: None,
instrumentation_lib: InstrumentationLibrary::new("component", None),
instrumentation_lib: InstrumentationLibrary::new("component", None, None),
}
}

Expand Down
5 changes: 5 additions & 0 deletions opentelemetry-dynatrace/src/transform/metrics.rs
Expand Up @@ -776,6 +776,7 @@ mod tests {
"test_array".to_string(),
"test",
None,
None,
InstrumentKind::Counter,
NumberKind::I64,
);
Expand Down Expand Up @@ -867,6 +868,7 @@ mod tests {
"test_sum".to_string(),
"test",
None,
None,
InstrumentKind::Counter,
NumberKind::I64,
);
Expand Down Expand Up @@ -978,6 +980,7 @@ mod tests {
"test_last_value".to_string(),
"test",
None,
None,
InstrumentKind::ValueObserver,
NumberKind::I64,
);
Expand Down Expand Up @@ -1044,6 +1047,7 @@ mod tests {
"test_min_max_sum_count".to_string(),
"test",
None,
None,
InstrumentKind::UpDownSumObserver,
NumberKind::I64,
);
Expand Down Expand Up @@ -1112,6 +1116,7 @@ mod tests {
"test_histogram".to_string(),
"test",
None,
None,
InstrumentKind::Histogram,
NumberKind::I64,
);
Expand Down
11 changes: 10 additions & 1 deletion opentelemetry-otlp/src/metric.rs
Expand Up @@ -315,7 +315,16 @@ impl Exporter for MetricsExporter {
record.resource().clone().into(),
InstrumentationLibrary::new(
record.descriptor().instrumentation_name(),
record.descriptor().instrumentation_version(),
record
.descriptor()
.instrumentation_library()
.version
.clone(),
record
.descriptor()
.instrumentation_library()
.schema_url
.clone(),
),
metrics,
));
Expand Down
6 changes: 5 additions & 1 deletion opentelemetry-otlp/src/transform/metrics.rs
Expand Up @@ -483,6 +483,7 @@ mod tests {
"test".to_string(),
"test",
None,
None,
InstrumentKind::Counter,
NumberKind::I64,
);
Expand Down Expand Up @@ -527,6 +528,7 @@ mod tests {
"test".to_string(),
"test",
None,
None,
InstrumentKind::ValueObserver,
NumberKind::I64,
);
Expand Down Expand Up @@ -578,6 +580,7 @@ mod tests {
"test".to_string(),
"test",
None,
None,
InstrumentKind::UpDownSumObserver,
NumberKind::I64,
);
Expand Down Expand Up @@ -626,6 +629,7 @@ mod tests {
"test".to_string(),
"test",
None,
None,
InstrumentKind::Histogram,
NumberKind::I64,
);
Expand Down Expand Up @@ -713,7 +717,7 @@ mod tests {
ResourceWrapper::from(Resource::new(kvs.into_iter().map(|(k, v)| {
opentelemetry::KeyValue::new(k.to_string(), v.to_string())
}))),
InstrumentationLibrary::new(name, version),
InstrumentationLibrary::new(name, version, None),
get_metric_with_name(
metric_name,
vec![(attributes, start_time, end_time, value)],
Expand Down
8 changes: 4 additions & 4 deletions opentelemetry-prometheus/tests/integration_test.rs
Expand Up @@ -15,7 +15,7 @@ fn free_unused_instruments() {
let mut expected = Vec::new();

{
let meter = exporter.provider().unwrap().meter("test", None);
let meter = exporter.provider().unwrap().meter("test", None, None);
let counter = meter.f64_counter("counter").init();

let attributes = vec![KeyValue::new("A", "B"), KeyValue::new("C", "D")];
Expand All @@ -38,7 +38,7 @@ fn batch() {
let exporter = opentelemetry_prometheus::exporter()
.with_resource(Resource::new(vec![KeyValue::new("R", "V")]))
.init();
let meter = exporter.provider().unwrap().meter("test", None);
let meter = exporter.provider().unwrap().meter("test", None, None);
let mut expected = Vec::new();

meter.batch_observer(|batch| {
Expand Down Expand Up @@ -68,7 +68,7 @@ fn test_add() {
.with_resource(Resource::new(vec![KeyValue::new("R", "V")]))
.init();

let meter = exporter.provider().unwrap().meter("test", None);
let meter = exporter.provider().unwrap().meter("test", None, None);

let up_down_counter = meter.f64_up_down_counter("updowncounter").init();
let counter = meter.f64_counter("counter").init();
Expand Down Expand Up @@ -120,7 +120,7 @@ fn test_sanitization() {
"Test Service",
)]))
.init();
let meter = exporter.provider().unwrap().meter("test", None);
let meter = exporter.provider().unwrap().meter("test", None, None);

let histogram = meter.f64_histogram("http.server.duration").init();
let attributes = vec![
Expand Down