Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb committed Nov 25, 2024
1 parent 1119549 commit 3b56ddd
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 26 deletions.
1 change: 0 additions & 1 deletion opentelemetry-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ async-trait = { workspace = true, optional = true }
futures-channel = "0.3"
futures-executor = { workspace = true }
futures-util = { workspace = true, features = ["std", "sink", "async-await-macro"] }
once_cell = { workspace = true }
percent-encoding = { version = "2.0", optional = true }
rand = { workspace = true, features = ["std", "std_rng","small_rng"], optional = true }
glob = { version = "0.3.1", optional =true}
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-sdk/src/logs/log_emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ use std::{
},
};

use once_cell::sync::Lazy;
use std::sync::LazyLock;

// a no nop logger provider used as placeholder when the provider is shutdown
static NOOP_LOGGER_PROVIDER: Lazy<LoggerProvider> = Lazy::new(|| LoggerProvider {
static NOOP_LOGGER_PROVIDER: LazyLock<LoggerProvider> = LazyLock::new(|| LoggerProvider {
inner: Arc::new(LoggerProviderInner {
processors: Vec::new(),
resource: Resource::empty(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{f64::consts::LOG2_E, mem::replace, ops::DerefMut, sync::Mutex, time::SystemTime};

use once_cell::sync::Lazy;
use opentelemetry::{otel_debug, KeyValue};
use std::sync::LazyLock;

use crate::metrics::{
data::{self, Aggregation},
Expand Down Expand Up @@ -166,7 +166,7 @@ fn scale_change(max_size: i32, bin: i32, start_bin: i32, length: i32) -> u32 {
}

/// Constants used in calculating the logarithm index.
static SCALE_FACTORS: Lazy<[f64; 21]> = Lazy::new(|| {
static SCALE_FACTORS: LazyLock<[f64; 21]> = LazyLock::new(|| {
[
LOG2_E * 2f64.powi(0),
LOG2_E * 2f64.powi(1),
Expand Down
6 changes: 3 additions & 3 deletions opentelemetry-sdk/src/metrics/internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ use std::sync::{Arc, RwLock};
use aggregate::is_under_cardinality_limit;
pub(crate) use aggregate::{AggregateBuilder, ComputeAggregation, Measure};
pub(crate) use exponential_histogram::{EXPO_MAX_SCALE, EXPO_MIN_SCALE};
use once_cell::sync::Lazy;
use opentelemetry::{otel_warn, KeyValue};
use std::sync::LazyLock;

pub(crate) static STREAM_OVERFLOW_ATTRIBUTES: Lazy<Vec<KeyValue>> =
Lazy::new(|| vec![KeyValue::new("otel.metric.overflow", "true")]);
pub(crate) static STREAM_OVERFLOW_ATTRIBUTES: LazyLock<Vec<KeyValue>> =
LazyLock::new(|| vec![KeyValue::new("otel.metric.overflow", "true")]);

pub(crate) trait Aggregator {
/// A static configuration that is needed in order to initialize aggregator.
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-sdk/src/propagation/baggage.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use once_cell::sync::Lazy;
use opentelemetry::{
baggage::{BaggageExt, KeyValueMetadata},
otel_warn,
Expand All @@ -7,10 +6,11 @@ use opentelemetry::{
};
use percent_encoding::{percent_decode_str, utf8_percent_encode, AsciiSet, CONTROLS};
use std::iter;
use std::sync::LazyLock;

static BAGGAGE_HEADER: &str = "baggage";
const FRAGMENT: &AsciiSet = &CONTROLS.add(b' ').add(b'"').add(b';').add(b',').add(b'=');
static BAGGAGE_FIELDS: Lazy<[String; 1]> = Lazy::new(|| [BAGGAGE_HEADER.to_owned()]);
static BAGGAGE_FIELDS: LazyLock<[String; 1]> = LazyLock::new(|| [BAGGAGE_HEADER.to_owned()]);

/// Propagates name-value pairs in [W3C Baggage] format.
///
Expand Down
6 changes: 3 additions & 3 deletions opentelemetry-sdk/src/propagation/trace_context.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
//! # W3C Trace Context Propagator
//!
use once_cell::sync::Lazy;
use opentelemetry::{
propagation::{text_map_propagator::FieldIter, Extractor, Injector, TextMapPropagator},
trace::{SpanContext, SpanId, TraceContextExt, TraceFlags, TraceId, TraceState},
Context,
};
use std::str::FromStr;
use std::sync::LazyLock;

const SUPPORTED_VERSION: u8 = 0;
const MAX_VERSION: u8 = 254;
const TRACEPARENT_HEADER: &str = "traceparent";
const TRACESTATE_HEADER: &str = "tracestate";

static TRACE_CONTEXT_HEADER_FIELDS: Lazy<[String; 2]> =
Lazy::new(|| [TRACEPARENT_HEADER.to_owned(), TRACESTATE_HEADER.to_owned()]);
static TRACE_CONTEXT_HEADER_FIELDS: LazyLock<[String; 2]> =
LazyLock::new(|| [TRACEPARENT_HEADER.to_owned(), TRACESTATE_HEADER.to_owned()]);

/// Propagates `SpanContext`s in [W3C TraceContext] format under `traceparent` and `tracestate` header.
///
Expand Down
18 changes: 5 additions & 13 deletions opentelemetry-sdk/src/trace/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,20 @@ use crate::trace::{
};
use crate::Resource;
use crate::{export::trace::SpanExporter, trace::SpanProcessor};
use once_cell::sync::{Lazy, OnceCell};
use opentelemetry::trace::TraceError;
use opentelemetry::InstrumentationScope;
use opentelemetry::{otel_debug, trace::TraceResult};
use std::borrow::Cow;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::sync::{LazyLock, OnceLock};

use super::IdGenerator;

static PROVIDER_RESOURCE: OnceCell<Resource> = OnceCell::new();
static PROVIDER_RESOURCE: OnceLock<Resource> = OnceLock::new();

// a no nop tracer provider used as placeholder when the provider is shutdown
static NOOP_TRACER_PROVIDER: Lazy<TracerProvider> = Lazy::new(|| TracerProvider {
static NOOP_TRACER_PROVIDER: LazyLock<TracerProvider> = LazyLock::new(|| TracerProvider {
inner: Arc::new(TracerProviderInner {
processors: Vec::new(),
config: Config {
Expand Down Expand Up @@ -392,16 +392,8 @@ impl Builder {
// For the uncommon case where there are multiple tracer providers with different resource
// configurations, users can optionally provide their own borrowed static resource.
if matches!(config.resource, Cow::Owned(_)) {
config.resource = match PROVIDER_RESOURCE.try_insert(config.resource.into_owned()) {
Ok(static_resource) => Cow::Borrowed(static_resource),
Err((prev, new)) => {
if prev == &new {
Cow::Borrowed(prev)
} else {
Cow::Owned(new)
}
}
}
let owned_resource = config.resource.clone().into_owned();
config.resource = Cow::Borrowed(PROVIDER_RESOURCE.get_or_init(|| owned_resource));
}

// Create a new vector to hold the modified processors
Expand Down

0 comments on commit 3b56ddd

Please sign in to comment.