-
Notifications
You must be signed in to change notification settings - Fork 451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: use Cow<'static, str>
instead of &'static str
#1018
Changes from all commits
c6f5b7b
7c52c95
84d0348
2511a48
94ed92d
d593706
e9d23e6
b94023e
3a4c393
ac5b4b3
0cb1d87
58534bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
use crate::metrics::{self, Meter, MeterProvider}; | ||
use core::fmt; | ||
use once_cell::sync::Lazy; | ||
use std::sync::{Arc, RwLock}; | ||
use std::{ | ||
borrow::Cow, | ||
sync::{Arc, RwLock}, | ||
}; | ||
|
||
/// The global `Meter` provider singleton. | ||
static GLOBAL_METER_PROVIDER: Lazy<RwLock<GlobalMeterProvider>> = Lazy::new(|| { | ||
|
@@ -26,9 +29,9 @@ impl fmt::Debug for GlobalMeterProvider { | |
impl MeterProvider for GlobalMeterProvider { | ||
fn versioned_meter( | ||
&self, | ||
name: &'static str, | ||
version: Option<&'static str>, | ||
schema_url: Option<&'static str>, | ||
name: Cow<'static, str>, | ||
version: Option<Cow<'static, str>>, | ||
schema_url: Option<Cow<'static, str>>, | ||
) -> Meter { | ||
self.provider.versioned_meter(name, version, schema_url) | ||
} | ||
|
@@ -72,8 +75,8 @@ pub fn meter_provider() -> GlobalMeterProvider { | |
/// If the name is an empty string, the provider will use a default name. | ||
/// | ||
/// This is a more convenient way of expressing `global::meter_provider().meter(name, None, None)`. | ||
pub fn meter(name: &'static str) -> Meter { | ||
meter_provider().versioned_meter(name, None, None) | ||
pub fn meter(name: impl Into<Cow<'static, str>>) -> Meter { | ||
meter_provider().versioned_meter(name.into(), None, None) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Can we use |
||
} | ||
|
||
/// Creates a [`Meter`] with the name, version and schema url. | ||
|
@@ -86,13 +89,13 @@ pub fn meter(name: &'static str) -> Meter { | |
/// # Example | ||
/// ```rust | ||
/// use opentelemetry_api::global::meter_with_version; | ||
/// let meter = meter_with_version("io.opentelemetry", Some("0.17"), Some("https://opentelemetry.io/schemas/1.2.0")); | ||
/// let meter = meter_with_version("io.opentelemetry", Some("0.17".into()), Some("https://opentelemetry.io/schemas/1.2.0".into())); | ||
/// ``` | ||
/// | ||
pub fn meter_with_version( | ||
name: &'static str, | ||
version: Option<&'static str>, | ||
schema_url: Option<&'static str>, | ||
name: impl Into<Cow<'static, str>>, | ||
version: Option<Cow<'static, str>>, | ||
schema_url: Option<Cow<'static, str>>, | ||
) -> Meter { | ||
meter_provider().versioned_meter(name, version, schema_url) | ||
meter_provider().versioned_meter(name.into(), version, schema_url) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -291,8 +291,8 @@ pub trait ObjectSafeTracerProvider { | |
fn versioned_tracer_boxed( | ||
&self, | ||
name: Cow<'static, str>, | ||
version: Option<&'static str>, | ||
schema_url: Option<&'static str>, | ||
version: Option<Cow<'static, str>>, | ||
schema_url: Option<Cow<'static, str>>, | ||
) -> Box<dyn ObjectSafeTracer + Send + Sync>; | ||
} | ||
|
||
|
@@ -306,8 +306,8 @@ where | |
fn versioned_tracer_boxed( | ||
&self, | ||
name: Cow<'static, str>, | ||
version: Option<&'static str>, | ||
schema_url: Option<&'static str>, | ||
version: Option<Cow<'static, str>>, | ||
schema_url: Option<Cow<'static, str>>, | ||
) -> Box<dyn ObjectSafeTracer + Send + Sync> { | ||
Box::new(self.versioned_tracer(name, version, schema_url)) | ||
} | ||
|
@@ -349,13 +349,13 @@ impl trace::TracerProvider for GlobalTracerProvider { | |
/// Create a versioned tracer using the global provider. | ||
fn versioned_tracer( | ||
&self, | ||
name: impl Into<Cow<'static, str>>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove |
||
version: Option<&'static str>, | ||
schema_url: Option<&'static str>, | ||
name: Cow<'static, str>, | ||
version: Option<Cow<'static, str>>, | ||
schema_url: Option<Cow<'static, str>>, | ||
) -> Self::Tracer { | ||
BoxedTracer( | ||
self.provider | ||
.versioned_tracer_boxed(name.into(), version, schema_url), | ||
.versioned_tracer_boxed(name, version, schema_url), | ||
) | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,9 +31,9 @@ impl trace::TracerProvider for NoopTracerProvider { | |
/// Returns a new `NoopTracer` instance. | ||
fn versioned_tracer( | ||
&self, | ||
_name: impl Into<Cow<'static, str>>, | ||
_version: Option<&'static str>, | ||
_schema_url: Option<&'static str>, | ||
_name: Cow<'static, str>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What would be the implications of using |
||
_version: Option<Cow<'static, str>>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious as to why we are removing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes previously it only allowed for static strings, but here it allows for |
||
_schema_url: Option<Cow<'static, str>>, | ||
) -> Self::Tracer { | ||
NoopTracer::new() | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the reason for not using
impl Into<Cow<'static, str>>
again?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can use impl Into here, but not for the Option types unfortunately, as you cannot convert &str into
Option<Cow<...>>
.So the best i can do is just the first parameter for name. Would you like me to make this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think to be consistent with trace that would be good :)