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

opentelemetry-api/src/metrics/up_down_counter.rs

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

opentelemetry-api/src/metrics/value_recorder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ impl<'a, T> ValueRecorderBuilder<'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-datadog/src/exporter/model/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ pub(crate) mod tests {
118118
status_code: StatusCode::Ok,
119119
status_message: "".into(),
120120
resource: None,
121-
instrumentation_lib: InstrumentationLibrary::new("component", None),
121+
instrumentation_lib: InstrumentationLibrary::new("component", None, None),
122122
}
123123
}
124124

opentelemetry-dynatrace/src/transform/metrics.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@ mod tests {
776776
"test_array".to_string(),
777777
"test",
778778
None,
779+
None,
779780
InstrumentKind::Counter,
780781
NumberKind::I64,
781782
);
@@ -867,6 +868,7 @@ mod tests {
867868
"test_sum".to_string(),
868869
"test",
869870
None,
871+
None,
870872
InstrumentKind::Counter,
871873
NumberKind::I64,
872874
);
@@ -978,6 +980,7 @@ mod tests {
978980
"test_last_value".to_string(),
979981
"test",
980982
None,
983+
None,
981984
InstrumentKind::ValueObserver,
982985
NumberKind::I64,
983986
);
@@ -1044,6 +1047,7 @@ mod tests {
10441047
"test_min_max_sum_count".to_string(),
10451048
"test",
10461049
None,
1050+
None,
10471051
InstrumentKind::UpDownSumObserver,
10481052
NumberKind::I64,
10491053
);
@@ -1112,6 +1116,7 @@ mod tests {
11121116
"test_histogram".to_string(),
11131117
"test",
11141118
None,
1119+
None,
11151120
InstrumentKind::Histogram,
11161121
NumberKind::I64,
11171122
);

opentelemetry-otlp/src/metric.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,16 @@ impl Exporter for MetricsExporter {
315315
record.resource().clone().into(),
316316
InstrumentationLibrary::new(
317317
record.descriptor().instrumentation_name(),
318-
record.descriptor().instrumentation_version(),
318+
record
319+
.descriptor()
320+
.instrumentation_library()
321+
.version
322+
.clone(),
323+
record
324+
.descriptor()
325+
.instrumentation_library()
326+
.schema_url
327+
.clone(),
319328
),
320329
metrics,
321330
));

opentelemetry-otlp/src/transform/metrics.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ mod tests {
483483
"test".to_string(),
484484
"test",
485485
None,
486+
None,
486487
InstrumentKind::Counter,
487488
NumberKind::I64,
488489
);
@@ -527,6 +528,7 @@ mod tests {
527528
"test".to_string(),
528529
"test",
529530
None,
531+
None,
530532
InstrumentKind::ValueObserver,
531533
NumberKind::I64,
532534
);
@@ -578,6 +580,7 @@ mod tests {
578580
"test".to_string(),
579581
"test",
580582
None,
583+
None,
581584
InstrumentKind::UpDownSumObserver,
582585
NumberKind::I64,
583586
);
@@ -626,6 +629,7 @@ mod tests {
626629
"test".to_string(),
627630
"test",
628631
None,
632+
None,
629633
InstrumentKind::Histogram,
630634
NumberKind::I64,
631635
);
@@ -713,7 +717,7 @@ mod tests {
713717
ResourceWrapper::from(Resource::new(kvs.into_iter().map(|(k, v)| {
714718
opentelemetry::KeyValue::new(k.to_string(), v.to_string())
715719
}))),
716-
InstrumentationLibrary::new(name, version),
720+
InstrumentationLibrary::new(name, version, None),
717721
get_metric_with_name(
718722
metric_name,
719723
vec![(attributes, start_time, end_time, value)],

opentelemetry-prometheus/tests/integration_test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn free_unused_instruments() {
1515
let mut expected = Vec::new();
1616

1717
{
18-
let meter = exporter.provider().unwrap().meter("test", None);
18+
let meter = exporter.provider().unwrap().meter("test", None, None);
1919
let counter = meter.f64_counter("counter").init();
2020

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

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

71-
let meter = exporter.provider().unwrap().meter("test", None);
71+
let meter = exporter.provider().unwrap().meter("test", None, None);
7272

7373
let up_down_counter = meter.f64_up_down_counter("updowncounter").init();
7474
let counter = meter.f64_counter("counter").init();
@@ -120,7 +120,7 @@ fn test_sanitization() {
120120
"Test Service",
121121
)]))
122122
.init();
123-
let meter = exporter.provider().unwrap().meter("test", None);
123+
let meter = exporter.provider().unwrap().meter("test", None, None);
124124

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

0 commit comments

Comments
 (0)