Skip to content
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

Merged
merged 12 commits into from
Apr 18, 2023

Conversation

tqwewe
Copy link
Contributor

@tqwewe tqwewe commented Apr 3, 2023

Closes #1015

Uses Cow<'static, str> instead of &'static str for some functions.

I initially tried impl Into<Cow<'static, str>> for the types, but it seemed to complicate things when used with the Option for version and schema_url.

@tqwewe tqwewe requested a review from a team April 3, 2023 04:20
@tqwewe tqwewe marked this pull request as draft April 5, 2023 04:28
@codecov
Copy link

codecov bot commented Apr 7, 2023

Codecov Report

Patch coverage: 29.8% and project coverage change: -0.1 ⚠️

Comparison is base (3597479) 57.2% compared to head (58534bd) 57.2%.

Additional details and impacted files
@@           Coverage Diff           @@
##            main   #1018     +/-   ##
=======================================
- Coverage   57.2%   57.2%   -0.1%     
=======================================
  Files        143     143             
  Lines      17464   17471      +7     
=======================================
- Hits        9999    9997      -2     
- Misses      7465    7474      +9     
Impacted Files Coverage Δ
opentelemetry-api/src/global/metrics.rs 0.0% <0.0%> (ø)
opentelemetry-api/src/global/trace.rs 28.6% <0.0%> (ø)
opentelemetry-api/src/metrics/meter.rs 38.3% <0.0%> (ø)
opentelemetry-api/src/metrics/noop.rs 5.6% <0.0%> (ø)
opentelemetry-api/src/trace/mod.rs 87.2% <ø> (ø)
opentelemetry-api/src/trace/noop.rs 52.7% <0.0%> (ø)
...elemetry-contrib/src/trace/exporter/jaeger_json.rs 0.0% <0.0%> (ø)
opentelemetry-datadog/src/exporter/mod.rs 24.1% <0.0%> (ø)
opentelemetry-jaeger/src/exporter/config/mod.rs 82.0% <0.0%> (ø)
opentelemetry-prometheus/src/lib.rs 84.6% <ø> (ø)
... and 9 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@tqwewe tqwewe marked this pull request as ready for review April 10, 2023 13:21
name: &'static str,
version: Option<&'static str>,
schema_url: Option<&'static str>,
name: Cow<'static, str>,
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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 :)

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Can we use meter_provider().meter(name.into()) to avoid the extra Nones?

@@ -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>>,
Copy link
Contributor

@lzchen lzchen Apr 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove impl Into??

_version: Option<&'static str>,
_schema_url: Option<&'static str>,
_name: Cow<'static, str>,
_version: Option<Cow<'static, str>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious as to why we are removing the & for version and schema_url? Are we allowing accepting of both String and &str for these fields?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 Cow<'static, str>, which means it can be an owned string if the version is not static (eg might come from user input, io, etc).

_name: impl Into<Cow<'static, str>>,
_version: Option<&'static str>,
_schema_url: Option<&'static str>,
_name: Cow<'static, str>,
Copy link
Contributor

@lzchen lzchen Apr 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the implications of using Cow<'static, str> over impl Into<Cow<'static, str>> from a user standpoint?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MeterProvider::meter should not use &'static str
4 participants