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

Allow ref counted keys and values #821

Merged
merged 2 commits into from Jun 25, 2022

Conversation

jtescher
Copy link
Member

This updates attribute Key and Value inner types from Cow<'static, str> to a new private OtelString enum to support static, owned, or ref counted values.

Resolves #809

This updates attribute `Key` and `Value` inner types from `Cow<'static, str>`
to a new private `OtelString` enum to support static, owned, or ref counted
values.
@codecov
Copy link

codecov bot commented Jun 22, 2022

Codecov Report

Merging #821 (39b86a7) into main (532333f) will increase coverage by 0.0%.
The diff coverage is 75.9%.

@@          Coverage Diff          @@
##            main    #821   +/-   ##
=====================================
  Coverage   69.8%   69.8%           
=====================================
  Files        110     110           
  Lines       9072    9148   +76     
=====================================
+ Hits        6333    6388   +55     
- Misses      2739    2760   +21     
Impacted Files Coverage Δ
opentelemetry-api/src/lib.rs 100.0% <ø> (ø)
opentelemetry-jaeger/src/lib.rs 93.0% <ø> (ø)
opentelemetry-sdk/src/export/metrics/stdout.rs 0.0% <ø> (ø)
opentelemetry-zipkin/src/lib.rs 100.0% <ø> (ø)
opentelemetry/src/lib.rs 100.0% <ø> (ø)
opentelemetry-api/src/common.rs 80.4% <73.1%> (-4.9%) ⬇️
opentelemetry-datadog/src/exporter/model/v03.rs 85.4% <100.0%> (ø)
opentelemetry-datadog/src/exporter/model/v05.rs 82.3% <100.0%> (ø)
opentelemetry-dynatrace/src/transform/metrics.rs 83.6% <100.0%> (ø)
opentelemetry-sdk/src/propagation/baggage.rs 96.4% <100.0%> (ø)
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e33859f...39b86a7. Read the comment docs.

Copy link
Contributor

@TommyCpp TommyCpp left a comment

Choose a reason for hiding this comment

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

I think to pin the indexmap to =1.8 should fix the MSRV. I will spend some time and see if we can remove the indexmap as a dependency. Some context of this change can be found in #799

@@ -34,7 +34,7 @@ serde_json = { version = "1", optional = true}
futures = {version = "0.3", optional = true}
async-trait = {version = "0.1", optional = true}
tokio = { version = "1.0", features = ["fs", "io-util"], optional = true }
async-std = { version = "1.6", optional = true }
async-std = { version = "1.10", optional = true }
Copy link
Contributor

Choose a reason for hiding this comment

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

Although it probably won't break the MSRV, we should probably pin this to 1.10 to be consistent with other crates?

Copy link
Member Author

Choose a reason for hiding this comment

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

This was only to get CI passing. Still have to resolve the MSRV issues on main.

);

impl From<Vec<&'static str>> for Array {
/// Convenience method for creating a `Value` from a `&'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.

The comments here are slightly wrong/misleading IMO.

Are these conversions especially common across the other crates? It feels like these might make it easy to do something relatively inefficient, so maybe we should leave the conversion to particular call sites?

Copy link
Member Author

Choose a reason for hiding this comment

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

Happy to remove them


impl StringValue {
/// Returns a string slice to this value
pub fn as_str(&self) -> &str {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably also implement AsRef<str>.

"process.command_args",
Value::Array(Array::String(cmd_arg_val)),
),
KeyValue::new("process.command_args", Value::Array(cmd_arg_val.into())),
Copy link
Contributor

Choose a reason for hiding this comment

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

For example here we first allocate a Vec<String> and then cmd_arg_val.into() will allocate a new Vec<StringValue>, redoing the outer allocation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed

@jtescher jtescher merged commit f07ad27 into open-telemetry:main Jun 25, 2022
@jtescher jtescher deleted the otel-strings branch June 25, 2022 21:21
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.

Allow using Arc<str> in key-value strings
3 participants