Skip to content

Commit

Permalink
Merge branch 'main' into cijothomas/utkarsh-maintainer
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyCpp authored Oct 25, 2024
2 parents f5d562a + 4c7bf58 commit d677e2e
Show file tree
Hide file tree
Showing 55 changed files with 515 additions and 829 deletions.
12 changes: 6 additions & 6 deletions opentelemetry-appender-log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,10 @@
use log::{Level, Metadata, Record};
use opentelemetry::{
logs::{AnyValue, LogRecord, Logger, LoggerProvider, Severity},
Key,
InstrumentationScope, Key,
};
#[cfg(feature = "experimental_metadata_attributes")]
use opentelemetry_semantic_conventions::attribute::{CODE_FILEPATH, CODE_LINENO, CODE_NAMESPACE};
use std::borrow::Cow;

pub struct OpenTelemetryLogBridge<P, L>
where
Expand Down Expand Up @@ -170,11 +169,12 @@ where
L: Logger + Send + Sync,
{
pub fn new(provider: &P) -> Self {
let scope = InstrumentationScope::builder("opentelemetry-log-appender")
.with_version(env!("CARGO_PKG_VERSION"))
.build();

OpenTelemetryLogBridge {
logger: provider
.logger_builder("opentelemetry-log-appender")
.with_version(Cow::Borrowed(env!("CARGO_PKG_VERSION")))
.build(),
logger: provider.logger_with_scope(scope),
_phantom: Default::default(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-appender-tracing/benches/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use async_trait::async_trait;
use criterion::{criterion_group, criterion_main, Criterion};
use opentelemetry::logs::LogResult;
use opentelemetry::{InstrumentationLibrary, KeyValue};
use opentelemetry::{InstrumentationScope, KeyValue};
use opentelemetry_appender_tracing::layer as tracing_layer;
use opentelemetry_sdk::export::logs::{LogBatch, LogExporter};
use opentelemetry_sdk::logs::{LogProcessor, LogRecord, LoggerProvider};
Expand Down Expand Up @@ -55,7 +55,7 @@ impl NoopProcessor {
}

impl LogProcessor for NoopProcessor {
fn emit(&self, _: &mut LogRecord, _: &InstrumentationLibrary) {
fn emit(&self, _: &mut LogRecord, _: &InstrumentationScope) {
// no-op
}

Expand Down
11 changes: 6 additions & 5 deletions opentelemetry-appender-tracing/src/layer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use opentelemetry::{
logs::{AnyValue, LogRecord, Logger, LoggerProvider, Severity},
Key,
InstrumentationScope, Key,
};
use std::borrow::Cow;
use tracing_core::Level;
Expand Down Expand Up @@ -136,11 +136,12 @@ where
L: Logger + Send + Sync,
{
pub fn new(provider: &P) -> Self {
let scope = InstrumentationScope::builder(INSTRUMENTATION_LIBRARY_NAME)
.with_version(Cow::Borrowed(env!("CARGO_PKG_VERSION")))
.build();

OpenTelemetryTracingBridge {
logger: provider
.logger_builder(INSTRUMENTATION_LIBRARY_NAME)
.with_version(Cow::Borrowed(env!("CARGO_PKG_VERSION")))
.build(),
logger: provider.logger_with_scope(scope),
_phantom: Default::default(),
}
}
Expand Down
19 changes: 8 additions & 11 deletions opentelemetry-otlp/examples/basic-otlp-http/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use once_cell::sync::Lazy;
use opentelemetry::{
global,
metrics::MetricsError,
trace::{TraceContextExt, TraceError, Tracer, TracerProvider as _},
KeyValue,
trace::{TraceContextExt, TraceError, Tracer},
InstrumentationScope, KeyValue,
};
use opentelemetry_appender_tracing::layer::OpenTelemetryTracingBridge;
use opentelemetry_otlp::WithExportConfig;
Expand Down Expand Up @@ -128,16 +128,13 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
.init();

let common_scope_attributes = vec![KeyValue::new("scope-key", "scope-value")];
let tracer = global::tracer_provider()
.tracer_builder("basic")
.with_attributes(common_scope_attributes.clone())
let scope = InstrumentationScope::builder("basic")
.with_version("1.0")
.with_attributes(common_scope_attributes)
.build();
let meter = global::meter_with_version(
"basic",
Some("v1.0"),
Some("schema_url"),
Some(common_scope_attributes.clone()),
);

let tracer = global::tracer_with_scope(scope.clone());
let meter = global::meter_with_scope(scope);

let counter = meter
.u64_counter("test_counter")
Expand Down
24 changes: 9 additions & 15 deletions opentelemetry-otlp/examples/basic-otlp/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use once_cell::sync::Lazy;
use opentelemetry::global;
use opentelemetry::logs::LogError;
use opentelemetry::metrics::MetricsError;
use opentelemetry::trace::{TraceError, TracerProvider};
use opentelemetry::{
trace::{TraceContextExt, Tracer},
KeyValue,
};
use opentelemetry::trace::{TraceContextExt, TraceError, Tracer};
use opentelemetry::KeyValue;
use opentelemetry::{global, InstrumentationScope};
use opentelemetry_appender_tracing::layer::OpenTelemetryTracingBridge;
use opentelemetry_otlp::{LogExporter, MetricsExporter, SpanExporter, WithExportConfig};
use opentelemetry_sdk::logs::LoggerProvider;
Expand Down Expand Up @@ -108,16 +105,13 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
.init();

let common_scope_attributes = vec![KeyValue::new("scope-key", "scope-value")];
let tracer = global::tracer_provider()
.tracer_builder("basic")
.with_attributes(common_scope_attributes.clone())
let scope = InstrumentationScope::builder("basic")
.with_version("1.0")
.with_attributes(common_scope_attributes)
.build();
let meter = global::meter_with_version(
"basic",
Some("v1.0"),
Some("schema_url"),
Some(common_scope_attributes.clone()),
);

let tracer = global::tracer_with_scope(scope.clone());
let meter = global::meter_with_scope(scope);

let counter = meter
.u64_counter("test_counter")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"spanId": "cd7cf7bf939930b7",
"traceState": "",
"parentSpanId": "d58cf2d702a061e0",
"flags": 0,
"flags": 1,
"name": "Sub operation...",
"kind": 1,
"startTimeUnixNano": "1703985537070566698",
Expand Down Expand Up @@ -55,40 +55,13 @@
"message": "",
"code": 0
}
}
],
"schemaUrl": ""
}
],
"schemaUrl": ""
},
{
"resource": {
"attributes": [
{
"key": "service.name",
"value": {
"stringValue": "basic-otlp-tracing-example"
}
}
],
"droppedAttributesCount": 0
},
"scopeSpans": [
{
"scope": {
"name": "ex.com/basic",
"version": "",
"attributes": [],
"droppedAttributesCount": 0
},
"spans": [
},
{
"traceId": "9b458af7378cba65253d7042d34fc72e",
"spanId": "d58cf2d702a061e0",
"traceState": "",
"parentSpanId": "",
"flags": 0,
"flags": 1,
"name": "operation",
"kind": 1,
"startTimeUnixNano": "1703985537070558635",
Expand All @@ -112,12 +85,6 @@
"value": {
"intValue": "100"
}
},
{
"key": "number/int",
"value": {
"intValue": "100"
}
}
],
"droppedAttributesCount": 0
Expand Down
8 changes: 4 additions & 4 deletions opentelemetry-proto/src/transform/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ pub mod tonic {

impl
From<(
opentelemetry_sdk::InstrumentationLibrary,
opentelemetry::InstrumentationScope,
Option<Cow<'static, str>>,
)> for InstrumentationScope
{
fn from(
data: (
opentelemetry_sdk::InstrumentationLibrary,
opentelemetry::InstrumentationScope,
Option<Cow<'static, str>>,
),
) -> Self {
Expand All @@ -75,13 +75,13 @@ pub mod tonic {

impl
From<(
&opentelemetry_sdk::InstrumentationLibrary,
&opentelemetry::InstrumentationScope,
Option<Cow<'static, str>>,
)> for InstrumentationScope
{
fn from(
data: (
&opentelemetry_sdk::InstrumentationLibrary,
&opentelemetry::InstrumentationScope,
Option<Cow<'static, str>>,
),
) -> Self {
Expand Down
12 changes: 6 additions & 6 deletions opentelemetry-proto/src/transform/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub mod tonic {
From<(
(
&opentelemetry_sdk::logs::LogRecord,
&opentelemetry::InstrumentationLibrary,
&opentelemetry::InstrumentationScope,
),
&ResourceAttributesWithSchema,
)> for ResourceLogs
Expand All @@ -152,7 +152,7 @@ pub mod tonic {
data: (
(
&opentelemetry_sdk::logs::LogRecord,
&opentelemetry::InstrumentationLibrary,
&opentelemetry::InstrumentationScope,
),
&ResourceAttributesWithSchema,
),
Expand Down Expand Up @@ -189,7 +189,7 @@ pub mod tonic {
Cow<'static, str>,
Vec<(
&opentelemetry_sdk::logs::LogRecord,
&opentelemetry::InstrumentationLibrary,
&opentelemetry::InstrumentationScope,
)>,
>,
(log_record, instrumentation)| {
Expand Down Expand Up @@ -235,19 +235,19 @@ pub mod tonic {
mod tests {
use crate::transform::common::tonic::ResourceAttributesWithSchema;
use opentelemetry::logs::LogRecord as _;
use opentelemetry::InstrumentationLibrary;
use opentelemetry::InstrumentationScope;
use opentelemetry_sdk::{export::logs::LogBatch, logs::LogRecord, Resource};
use std::time::SystemTime;

fn create_test_log_data(
instrumentation_name: &str,
_message: &str,
) -> (LogRecord, InstrumentationLibrary) {
) -> (LogRecord, InstrumentationScope) {
let mut logrecord = LogRecord::default();
logrecord.set_timestamp(SystemTime::now());
logrecord.set_observed_timestamp(SystemTime::now());
let instrumentation =
InstrumentationLibrary::builder(instrumentation_name.to_string()).build();
InstrumentationScope::builder(instrumentation_name.to_string()).build();
(logrecord, instrumentation)
}

Expand Down
15 changes: 7 additions & 8 deletions opentelemetry-proto/src/transform/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ pub mod tonic {
schema_url: resource.schema_url.clone().unwrap_or_default(),
scope_spans: vec![ScopeSpans {
schema_url: source_span
.instrumentation_lib
.instrumentation_scope
.schema_url
.as_ref()
.map(ToString::to_string)
.unwrap_or_default(),
scope: Some((source_span.instrumentation_lib, None).into()),
scope: Some((source_span.instrumentation_scope, None).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 Expand Up @@ -155,12 +155,11 @@ pub mod tonic {
spans: Vec<SpanData>,
resource: &ResourceAttributesWithSchema,
) -> Vec<ResourceSpans> {
// Group spans by their instrumentation library
// Group spans by their instrumentation scope
let scope_map = spans.iter().fold(
HashMap::new(),
|mut scope_map: HashMap<&opentelemetry_sdk::InstrumentationLibrary, Vec<&SpanData>>,
span| {
let instrumentation = &span.instrumentation_lib;
|mut scope_map: HashMap<&opentelemetry::InstrumentationScope, Vec<&SpanData>>, span| {
let instrumentation = &span.instrumentation_scope;
scope_map.entry(instrumentation).or_default().push(span);
scope_map
},
Expand Down Expand Up @@ -198,11 +197,11 @@ mod tests {
use opentelemetry::trace::{
SpanContext, SpanId, SpanKind, Status, TraceFlags, TraceId, TraceState,
};
use opentelemetry::InstrumentationScope;
use opentelemetry::KeyValue;
use opentelemetry_sdk::export::trace::SpanData;
use opentelemetry_sdk::resource::Resource;
use opentelemetry_sdk::trace::{SpanEvents, SpanLinks};
use opentelemetry_sdk::InstrumentationLibrary;
use std::borrow::Cow;
use std::time::{Duration, SystemTime};

Expand All @@ -227,7 +226,7 @@ mod tests {
events: SpanEvents::default(),
links: SpanLinks::default(),
status: Status::Unset,
instrumentation_lib: InstrumentationLibrary::builder(instrumentation_name).build(),
instrumentation_scope: InstrumentationScope::builder(instrumentation_name).build(),
}
}

Expand Down
6 changes: 6 additions & 0 deletions opentelemetry-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ Now:
```rust
let counter = meter.u64_counter("my_counter").build();
```
- **BREAKING**: [#2220](https://github.com/open-telemetry/opentelemetry-rust/pull/2220)
- Removed `InstrumentationLibrary` re-export and its `Scope` alias, use `opentelemetry::InstrumentationLibrary` instead.
- Unified builders across signals
- Removed deprecated `LoggerProvider::versioned_logger`, `TracerProvider::versioned_tracer`
- Removed `MeterProvider::versioned_meter`
- Replaced these methods with `LoggerProvider::logger_with_scope`, `TracerProvider::logger_with_scope`, `MeterProvider::meter_with_scope`

## v0.26.0
Released 2024-Sep-30
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/benches/batch_span_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn get_span_data() -> Vec<SpanData> {
events: SpanEvents::default(),
links: SpanLinks::default(),
status: Status::Unset,
instrumentation_lib: Default::default(),
instrumentation_scope: Default::default(),
})
.collect::<Vec<SpanData>>()
}
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-sdk/benches/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use opentelemetry::logs::{
};
use opentelemetry::trace::Tracer;
use opentelemetry::trace::TracerProvider as _;
use opentelemetry::{InstrumentationLibrary, Key};
use opentelemetry::{InstrumentationScope, Key};
use opentelemetry_sdk::logs::{LogProcessor, LogRecord, Logger, LoggerProvider};
use opentelemetry_sdk::trace;
use opentelemetry_sdk::trace::{Sampler, TracerProvider};
Expand All @@ -34,7 +34,7 @@ use opentelemetry_sdk::trace::{Sampler, TracerProvider};
struct NoopProcessor;

impl LogProcessor for NoopProcessor {
fn emit(&self, _data: &mut LogRecord, _library: &InstrumentationLibrary) {}
fn emit(&self, _data: &mut LogRecord, _scope: &InstrumentationScope) {}

fn force_flush(&self) -> LogResult<()> {
Ok(())
Expand Down
Loading

0 comments on commit d677e2e

Please sign in to comment.