Skip to content

Commit e09392d

Browse files
authored
feat(otlp,sdk): add schema_url to tracer. (open-telemetry#743)
* feat(otlp,sdk): add schema_url to tracer. * feat(sdk, dynatrace, prometheus, api, datadog, zipkin, proto): add schema_url to InstrumentationLibrary. * fix: address comments.
1 parent 104d66d commit e09392d

File tree

25 files changed

+122
-37
lines changed

25 files changed

+122
-37
lines changed

opentelemetry-api/src/common.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,17 +272,22 @@ pub struct InstrumentationLibrary {
272272
pub name: Cow<'static, str>,
273273
/// instrumentation library version, can be empty
274274
pub version: Option<Cow<'static, str>>,
275+
/// [Schema url] of spans and their events.
276+
///
277+
/// [Schema url]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/schemas/overview.md#schema-url
278+
pub schema_url: Option<Cow<'static, str>>,
275279
}
276280

277281
impl InstrumentationLibrary {
278282
/// Create an InstrumentationLibrary from name and version.
279-
pub fn new<T>(name: T, version: Option<T>) -> InstrumentationLibrary
283+
pub fn new<T>(name: T, version: Option<T>, schema_url: Option<T>) -> InstrumentationLibrary
280284
where
281285
T: Into<Cow<'static, str>>,
282286
{
283287
InstrumentationLibrary {
284288
name: name.into(),
285289
version: version.map(Into::into),
290+
schema_url: schema_url.map(Into::into),
286291
}
287292
}
288293
}

opentelemetry-api/src/global/metrics.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@ pub struct GlobalMeterProvider {
1414
}
1515

1616
impl MeterProvider for GlobalMeterProvider {
17-
fn meter(&self, name: &'static str, version: Option<&'static str>) -> Meter {
18-
self.provider.meter(name, version)
17+
fn meter(
18+
&self,
19+
name: &'static str,
20+
version: Option<&'static str>,
21+
schema_url: Option<&'static str>,
22+
) -> Meter {
23+
self.provider.meter(name, version, schema_url)
1924
}
2025
}
2126

@@ -58,10 +63,14 @@ pub fn meter_provider() -> GlobalMeterProvider {
5863
///
5964
/// This is a more convenient way of expressing `global::meter_provider().meter(name)`.
6065
pub fn meter(name: &'static str) -> Meter {
61-
meter_provider().meter(name, None)
66+
meter_provider().meter(name, None, None)
6267
}
6368

6469
/// Creates a [`Meter`] with the name and version.
65-
pub fn meter_with_version(name: &'static str, version: &'static str) -> Meter {
66-
meter_provider().meter(name, Some(version))
70+
pub fn meter_with_version(
71+
name: &'static str,
72+
version: &'static str,
73+
schema_url: &'static str,
74+
) -> Meter {
75+
meter_provider().meter(name, Some(version), Some(schema_url))
6776
}

opentelemetry-api/src/metrics/config.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,23 @@ impl InstrumentConfig {
1616
InstrumentConfig {
1717
description: None,
1818
unit: None,
19-
instrumentation_library: InstrumentationLibrary::new(instrumentation_name, None),
19+
instrumentation_library: InstrumentationLibrary::new(instrumentation_name, None, None),
2020
}
2121
}
2222

2323
/// Create a new config with instrumentation name and optional version
2424
pub fn with_instrumentation<T: Into<Cow<'static, str>>>(
2525
instrumentation_name: T,
2626
instrumentation_version: Option<T>,
27+
schema_url: Option<T>,
2728
) -> Self {
2829
InstrumentConfig {
2930
description: None,
3031
unit: None,
3132
instrumentation_library: InstrumentationLibrary::new(
3233
instrumentation_name,
3334
instrumentation_version,
35+
schema_url,
3436
),
3537
}
3638
}

opentelemetry-api/src/metrics/counter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ impl<'a, T> CounterBuilder<'a, T> {
6767
name,
6868
meter.instrumentation_library().name,
6969
meter.instrumentation_library().version,
70+
meter.instrumentation_library().schema_url,
7071
InstrumentKind::Counter,
7172
number_kind,
7273
),

opentelemetry-api/src/metrics/descriptor.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ impl Descriptor {
2121
name: String,
2222
instrumentation_name: T,
2323
instrumentation_version: Option<T>,
24+
schema_url: Option<T>,
2425
instrument_kind: InstrumentKind,
2526
number_kind: NumberKind,
2627
) -> Self {
@@ -32,8 +33,11 @@ impl Descriptor {
3233
instrumentation_version.as_ref().hash(&mut hasher);
3334
instrument_kind.hash(&mut hasher);
3435
number_kind.hash(&mut hasher);
35-
let config =
36-
InstrumentConfig::with_instrumentation(instrumentation_name, instrumentation_version);
36+
let config = InstrumentConfig::with_instrumentation(
37+
instrumentation_name,
38+
instrumentation_version.map(Into::into),
39+
schema_url.map(Into::into),
40+
);
3741

3842
Descriptor {
3943
name,
@@ -80,11 +84,6 @@ impl Descriptor {
8084
self.config.instrumentation_name()
8185
}
8286

83-
/// The version of library that provided instrumentation for this instrument. Optional
84-
pub fn instrumentation_version(&self) -> Option<Cow<'static, str>> {
85-
self.config.instrumentation_version()
86-
}
87-
8887
/// Instrumentation library reference
8988
pub fn instrumentation_library(&self) -> &InstrumentationLibrary {
9089
&self.config.instrumentation_library

opentelemetry-api/src/metrics/histogram.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ impl<'a, T> HistogramBuilder<'a, T> {
6767
name,
6868
meter.instrumentation_library().name,
6969
meter.instrumentation_library().version,
70+
meter.instrumentation_library().schema_url,
7071
InstrumentKind::Histogram,
7172
number_kind,
7273
),

opentelemetry-api/src/metrics/meter.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::borrow::Cow;
12
use std::fmt;
23
use std::sync::Arc;
34

@@ -23,6 +24,7 @@ pub trait MeterProvider: fmt::Debug {
2324
&self,
2425
instrumentation_name: &'static str,
2526
instrumentation_version: Option<&'static str>,
27+
schema_url: Option<&'static str>,
2628
) -> Meter;
2729
}
2830

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

4951
impl Meter {
5052
/// Create a new named meter from a sdk implemented core
51-
pub fn new<T: Into<&'static str>>(
53+
pub fn new<T: Into<Cow<'static, str>>>(
5254
instrumentation_name: T,
5355
instrumentation_version: Option<T>,
56+
schema_url: Option<T>,
5457
core: Arc<dyn sdk_api::MeterCore + Send + Sync>,
5558
) -> Self {
5659
Meter {
5760
instrumentation_library: InstrumentationLibrary::new(
5861
instrumentation_name.into(),
5962
instrumentation_version.map(Into::into),
63+
schema_url.map(Into::into),
6064
),
6165
core,
6266
}

opentelemetry-api/src/metrics/noop.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::any::Any;
1818
use std::sync::Arc;
1919

2020
lazy_static::lazy_static! {
21-
static ref NOOP_DESCRIPTOR: Descriptor = Descriptor::new(String::new(), "noop", None, InstrumentKind::Counter, NumberKind::U64);
21+
static ref NOOP_DESCRIPTOR: Descriptor = Descriptor::new(String::new(), "noop", None, None, InstrumentKind::Counter, NumberKind::U64);
2222
}
2323

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

3737
impl MeterProvider for NoopMeterProvider {
38-
fn meter(&self, name: &'static str, version: Option<&'static str>) -> Meter {
39-
Meter::new(name, version, Arc::new(NoopMeterCore::new()))
38+
fn meter(
39+
&self,
40+
name: &'static str,
41+
version: Option<&'static str>,
42+
schema_url: Option<&'static str>,
43+
) -> Meter {
44+
Meter::new(name, version, schema_url, Arc::new(NoopMeterCore::new()))
4045
}
4146
}
4247

opentelemetry-api/src/metrics/observer.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ impl<'a, T> SumObserverBuilder<'a, T> {
113113
name,
114114
meter.instrumentation_library().name,
115115
meter.instrumentation_library().version,
116+
meter.instrumentation_library().schema_url,
116117
InstrumentKind::SumObserver,
117118
number_kind,
118119
),
@@ -206,6 +207,7 @@ impl<'a, T> UpDownSumObserverBuilder<'a, T> {
206207
name,
207208
meter.instrumentation_library().name,
208209
meter.instrumentation_library().version,
210+
meter.instrumentation_library().schema_url,
209211
InstrumentKind::UpDownSumObserver,
210212
number_kind,
211213
),
@@ -298,6 +300,7 @@ impl<'a, T> ValueObserverBuilder<'a, T> {
298300
name,
299301
meter.instrumentation_library().name,
300302
meter.instrumentation_library().version,
303+
meter.instrumentation_library().schema_url,
301304
InstrumentKind::ValueObserver,
302305
number_kind,
303306
),

opentelemetry-api/src/metrics/registry.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,13 @@ pub fn meter_provider(core: Arc<dyn MeterCore + Send + Sync>) -> RegistryMeterPr
2020
pub struct RegistryMeterProvider(Arc<dyn MeterCore + Send + Sync>);
2121

2222
impl MeterProvider for RegistryMeterProvider {
23-
fn meter(&self, name: &'static str, version: Option<&'static str>) -> Meter {
24-
Meter::new(name, version, self.0.clone())
23+
fn meter(
24+
&self,
25+
name: &'static str,
26+
version: Option<&'static str>,
27+
schema_url: Option<&'static str>,
28+
) -> Meter {
29+
Meter::new(name, version, schema_url, self.0.clone())
2530
}
2631
}
2732

0 commit comments

Comments
 (0)