Skip to content

Commit 02574ef

Browse files
Rename InstrumentationLibrary to InstrumentationScope and make cheaply clonable
1 parent 00160e9 commit 02574ef

File tree

48 files changed

+319
-440
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+319
-440
lines changed

opentelemetry-appender-log/src/lib.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,10 @@
9797
use log::{Level, Metadata, Record};
9898
use opentelemetry::{
9999
logs::{AnyValue, LogRecord, Logger, LoggerProvider, Severity},
100-
InstrumentationLibrary, Key,
100+
InstrumentationScope, Key,
101101
};
102102
#[cfg(feature = "experimental_metadata_attributes")]
103103
use opentelemetry_semantic_conventions::attribute::{CODE_FILEPATH, CODE_LINENO, CODE_NAMESPACE};
104-
use std::sync::Arc;
105104

106105
pub struct OpenTelemetryLogBridge<P, L>
107106
where
@@ -170,13 +169,12 @@ where
170169
L: Logger + Send + Sync,
171170
{
172171
pub fn new(provider: &P) -> Self {
173-
let library = Arc::new(
174-
InstrumentationLibrary::builder("opentelemetry-log-appender")
175-
.with_version(env!("CARGO_PKG_VERSION"))
176-
.build(),
177-
);
172+
let scope = InstrumentationScope::builder("opentelemetry-log-appender")
173+
.with_version(env!("CARGO_PKG_VERSION"))
174+
.build();
175+
178176
OpenTelemetryLogBridge {
179-
logger: provider.library_logger(library),
177+
logger: provider.library_logger(scope),
180178
_phantom: Default::default(),
181179
}
182180
}

opentelemetry-appender-tracing/benches/logs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use async_trait::async_trait;
1717
use criterion::{criterion_group, criterion_main, Criterion};
1818
use opentelemetry::logs::LogResult;
19-
use opentelemetry::{InstrumentationLibrary, KeyValue};
19+
use opentelemetry::{InstrumentationScope, KeyValue};
2020
use opentelemetry_appender_tracing::layer as tracing_layer;
2121
use opentelemetry_sdk::export::logs::{LogBatch, LogExporter};
2222
use opentelemetry_sdk::logs::{LogProcessor, LogRecord, LoggerProvider};
@@ -55,7 +55,7 @@ impl NoopProcessor {
5555
}
5656

5757
impl LogProcessor for NoopProcessor {
58-
fn emit(&self, _: &mut LogRecord, _: &InstrumentationLibrary) {
58+
fn emit(&self, _: &mut LogRecord, _: &InstrumentationScope) {
5959
// no-op
6060
}
6161

opentelemetry-appender-tracing/src/layer.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use opentelemetry::{
22
logs::{AnyValue, LogRecord, Logger, LoggerProvider, Severity},
3-
InstrumentationLibrary, Key,
3+
InstrumentationScope, Key,
44
};
5-
use std::{borrow::Cow, sync::Arc};
5+
use std::borrow::Cow;
66
use tracing_core::Level;
77
#[cfg(feature = "experimental_metadata_attributes")]
88
use tracing_core::Metadata;
@@ -136,14 +136,12 @@ where
136136
L: Logger + Send + Sync,
137137
{
138138
pub fn new(provider: &P) -> Self {
139-
let library = Arc::new(
140-
InstrumentationLibrary::builder(INSTRUMENTATION_LIBRARY_NAME)
141-
.with_version(Cow::Borrowed(env!("CARGO_PKG_VERSION")))
142-
.build(),
143-
);
139+
let scope = InstrumentationScope::builder(INSTRUMENTATION_LIBRARY_NAME)
140+
.with_version(Cow::Borrowed(env!("CARGO_PKG_VERSION")))
141+
.build();
144142

145143
OpenTelemetryTracingBridge {
146-
logger: provider.library_logger(library),
144+
logger: provider.library_logger(scope),
147145
_phantom: Default::default(),
148146
}
149147
}

opentelemetry-otlp/examples/basic-otlp-http/src/main.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use opentelemetry::{
33
global,
44
metrics::MetricsError,
55
trace::{TraceContextExt, TraceError, Tracer},
6-
InstrumentationLibrary, KeyValue,
6+
InstrumentationScope, KeyValue,
77
};
88
use opentelemetry_appender_tracing::layer::OpenTelemetryTracingBridge;
99
use opentelemetry_otlp::Protocol;
@@ -13,7 +13,7 @@ use opentelemetry_sdk::{
1313
logs::{self as sdklogs},
1414
Resource,
1515
};
16-
use std::{error::Error, sync::Arc};
16+
use std::error::Error;
1717
use tracing::info;
1818
use tracing_subscriber::prelude::*;
1919
use tracing_subscriber::EnvFilter;
@@ -121,14 +121,13 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
121121
.init();
122122

123123
let common_scope_attributes = vec![KeyValue::new("scope-key", "scope-value")];
124-
let library = Arc::new(
125-
InstrumentationLibrary::builder("basic")
126-
.with_version("1.0")
127-
.with_attributes(common_scope_attributes)
128-
.build(),
129-
);
130-
let tracer = global::library_tracer(library.clone());
131-
let meter = global::library_meter(library);
124+
let scope = InstrumentationScope::builder("basic")
125+
.with_version("1.0")
126+
.with_attributes(common_scope_attributes)
127+
.build();
128+
129+
let tracer = global::library_tracer(scope.clone());
130+
let meter = global::library_meter(scope);
132131

133132
let counter = meter
134133
.u64_counter("test_counter")

opentelemetry-otlp/examples/basic-otlp/src/main.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
use once_cell::sync::Lazy;
22
use opentelemetry::logs::LogError;
33
use opentelemetry::metrics::MetricsError;
4-
use opentelemetry::trace::{TraceContextExt, TraceError, Tracer, TracerProvider};
4+
use opentelemetry::trace::{TraceContextExt, TraceError, Tracer};
55
use opentelemetry::KeyValue;
6-
use opentelemetry::{global, InstrumentationLibrary};
6+
use opentelemetry::{global, InstrumentationScope};
77
use opentelemetry_appender_tracing::layer::OpenTelemetryTracingBridge;
88
use opentelemetry_otlp::{ExportConfig, WithExportConfig};
99
use opentelemetry_sdk::trace::Config;
1010
use opentelemetry_sdk::{runtime, trace as sdktrace, Resource};
1111
use std::error::Error;
12-
use std::sync::Arc;
1312
use tracing::info;
1413
use tracing_subscriber::prelude::*;
1514
use tracing_subscriber::EnvFilter;
@@ -110,14 +109,13 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
110109
.init();
111110

112111
let common_scope_attributes = vec![KeyValue::new("scope-key", "scope-value")];
113-
let library = Arc::new(
114-
InstrumentationLibrary::builder("basic")
115-
.with_version("1.0")
116-
.with_attributes(common_scope_attributes)
117-
.build(),
118-
);
119-
let tracer = global::tracer_provider().library_tracer(library.clone());
120-
let meter = global::library_meter(library);
112+
let scope = InstrumentationScope::builder("basic")
113+
.with_version("1.0")
114+
.with_attributes(common_scope_attributes)
115+
.build();
116+
117+
let tracer = global::library_tracer(scope.clone());
118+
let meter = global::library_meter(scope);
121119

122120
let counter = meter
123121
.u64_counter("test_counter")

opentelemetry-otlp/tests/integration_test/expected/serialized_traces.json

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"spanId": "cd7cf7bf939930b7",
2727
"traceState": "",
2828
"parentSpanId": "d58cf2d702a061e0",
29-
"flags": 0,
29+
"flags": 1,
3030
"name": "Sub operation...",
3131
"kind": 1,
3232
"startTimeUnixNano": "1703985537070566698",
@@ -55,40 +55,13 @@
5555
"message": "",
5656
"code": 0
5757
}
58-
}
59-
],
60-
"schemaUrl": ""
61-
}
62-
],
63-
"schemaUrl": ""
64-
},
65-
{
66-
"resource": {
67-
"attributes": [
68-
{
69-
"key": "service.name",
70-
"value": {
71-
"stringValue": "basic-otlp-tracing-example"
72-
}
73-
}
74-
],
75-
"droppedAttributesCount": 0
76-
},
77-
"scopeSpans": [
78-
{
79-
"scope": {
80-
"name": "ex.com/basic",
81-
"version": "",
82-
"attributes": [],
83-
"droppedAttributesCount": 0
84-
},
85-
"spans": [
58+
},
8659
{
8760
"traceId": "9b458af7378cba65253d7042d34fc72e",
8861
"spanId": "d58cf2d702a061e0",
8962
"traceState": "",
9063
"parentSpanId": "",
91-
"flags": 0,
64+
"flags": 1,
9265
"name": "operation",
9366
"kind": 1,
9467
"startTimeUnixNano": "1703985537070558635",
@@ -112,12 +85,6 @@
11285
"value": {
11386
"intValue": "100"
11487
}
115-
},
116-
{
117-
"key": "number/int",
118-
"value": {
119-
"intValue": "100"
120-
}
12188
}
12289
],
12390
"droppedAttributesCount": 0

opentelemetry-proto/src/transform/common.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ pub mod tonic {
4444

4545
impl
4646
From<(
47-
opentelemetry_sdk::InstrumentationLibrary,
47+
opentelemetry_sdk::InstrumentationScope,
4848
Option<Cow<'static, str>>,
4949
)> for InstrumentationScope
5050
{
5151
fn from(
5252
data: (
53-
opentelemetry_sdk::InstrumentationLibrary,
53+
opentelemetry_sdk::InstrumentationScope,
5454
Option<Cow<'static, str>>,
5555
),
5656
) -> Self {
@@ -66,7 +66,7 @@ pub mod tonic {
6666
InstrumentationScope {
6767
name: library.name.into_owned(),
6868
version: library.version.map(Cow::into_owned).unwrap_or_default(),
69-
attributes: Attributes::from(library.attributes).0,
69+
attributes: Attributes::from(library.attributes.into_owned()).0,
7070
..Default::default()
7171
}
7272
}
@@ -75,13 +75,13 @@ pub mod tonic {
7575

7676
impl
7777
From<(
78-
&opentelemetry_sdk::InstrumentationLibrary,
78+
&opentelemetry_sdk::InstrumentationScope,
7979
Option<Cow<'static, str>>,
8080
)> for InstrumentationScope
8181
{
8282
fn from(
8383
data: (
84-
&opentelemetry_sdk::InstrumentationLibrary,
84+
&opentelemetry_sdk::InstrumentationScope,
8585
Option<Cow<'static, str>>,
8686
),
8787
) -> Self {
@@ -101,7 +101,7 @@ pub mod tonic {
101101
.as_ref()
102102
.map(ToString::to_string)
103103
.unwrap_or_default(),
104-
attributes: Attributes::from(library.attributes.clone()).0,
104+
attributes: Attributes::from(library.attributes.clone().into_owned()).0,
105105
..Default::default()
106106
}
107107
}

opentelemetry-proto/src/transform/logs.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub mod tonic {
142142
From<(
143143
(
144144
&opentelemetry_sdk::logs::LogRecord,
145-
&opentelemetry::InstrumentationLibrary,
145+
&opentelemetry::InstrumentationScope,
146146
),
147147
&ResourceAttributesWithSchema,
148148
)> for ResourceLogs
@@ -151,7 +151,7 @@ pub mod tonic {
151151
data: (
152152
(
153153
&opentelemetry_sdk::logs::LogRecord,
154-
&opentelemetry::InstrumentationLibrary,
154+
&opentelemetry::InstrumentationScope,
155155
),
156156
&ResourceAttributesWithSchema,
157157
),
@@ -188,7 +188,7 @@ pub mod tonic {
188188
Cow<'static, str>,
189189
Vec<(
190190
&opentelemetry_sdk::logs::LogRecord,
191-
&opentelemetry::InstrumentationLibrary,
191+
&opentelemetry::InstrumentationScope,
192192
)>,
193193
>,
194194
(log_record, instrumentation)| {
@@ -234,19 +234,19 @@ pub mod tonic {
234234
mod tests {
235235
use crate::transform::common::tonic::ResourceAttributesWithSchema;
236236
use opentelemetry::logs::LogRecord as _;
237-
use opentelemetry::InstrumentationLibrary;
237+
use opentelemetry::InstrumentationScope;
238238
use opentelemetry_sdk::{export::logs::LogBatch, logs::LogRecord, Resource};
239239
use std::time::SystemTime;
240240

241241
fn create_test_log_data(
242242
instrumentation_name: &str,
243243
_message: &str,
244-
) -> (LogRecord, InstrumentationLibrary) {
244+
) -> (LogRecord, InstrumentationScope) {
245245
let mut logrecord = LogRecord::default();
246246
logrecord.set_timestamp(SystemTime::now());
247247
logrecord.set_observed_timestamp(SystemTime::now());
248248
let instrumentation =
249-
InstrumentationLibrary::builder(instrumentation_name.to_string()).build();
249+
InstrumentationScope::builder(instrumentation_name.to_string()).build();
250250
(logrecord, instrumentation)
251251
}
252252

opentelemetry-proto/src/transform/trace.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ pub mod tonic {
101101
schema_url: resource.schema_url.clone().unwrap_or_default(),
102102
scope_spans: vec![ScopeSpans {
103103
schema_url: source_span
104-
.instrumentation_lib
104+
.instrumentation_scope
105105
.schema_url
106106
.as_ref()
107107
.map(ToString::to_string)
108108
.unwrap_or_default(),
109-
scope: Some((source_span.instrumentation_lib, None).into()),
109+
scope: Some((source_span.instrumentation_scope, None).into()),
110110
spans: vec![Span {
111111
trace_id: source_span.span_context.trace_id().to_bytes().to_vec(),
112112
span_id: source_span.span_context.span_id().to_bytes().to_vec(),
@@ -158,9 +158,9 @@ pub mod tonic {
158158
// Group spans by their instrumentation library
159159
let scope_map = spans.iter().fold(
160160
HashMap::new(),
161-
|mut scope_map: HashMap<&opentelemetry_sdk::InstrumentationLibrary, Vec<&SpanData>>,
161+
|mut scope_map: HashMap<&opentelemetry_sdk::InstrumentationScope, Vec<&SpanData>>,
162162
span| {
163-
let instrumentation = &span.instrumentation_lib;
163+
let instrumentation = &span.instrumentation_scope;
164164
scope_map.entry(instrumentation).or_default().push(span);
165165
scope_map
166166
},
@@ -202,7 +202,7 @@ mod tests {
202202
use opentelemetry_sdk::export::trace::SpanData;
203203
use opentelemetry_sdk::resource::Resource;
204204
use opentelemetry_sdk::trace::{SpanEvents, SpanLinks};
205-
use opentelemetry_sdk::InstrumentationLibrary;
205+
use opentelemetry_sdk::InstrumentationScope;
206206
use std::borrow::Cow;
207207
use std::time::{Duration, SystemTime};
208208

@@ -227,7 +227,7 @@ mod tests {
227227
events: SpanEvents::default(),
228228
links: SpanLinks::default(),
229229
status: Status::Unset,
230-
instrumentation_lib: InstrumentationLibrary::builder(instrumentation_name).build(),
230+
instrumentation_scope: InstrumentationScope::builder(instrumentation_name).build(),
231231
}
232232
}
233233

opentelemetry-sdk/benches/batch_span_processor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn get_span_data() -> Vec<SpanData> {
3232
events: SpanEvents::default(),
3333
links: SpanLinks::default(),
3434
status: Status::Unset,
35-
instrumentation_lib: Default::default(),
35+
instrumentation_scope: Default::default(),
3636
})
3737
.collect::<Vec<SpanData>>()
3838
}

0 commit comments

Comments
 (0)