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
Conversation
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 Report
@@ Coverage Diff @@
## main #821 +/- ##
=====================================
Coverage 69.8% 69.8%
=====================================
Files 110 110
Lines 9072 9148 +76
=====================================
+ Hits 6333 6388 +55
- Misses 2739 2760 +21
Continue to review full report at Codecov.
|
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 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 } |
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.
Although it probably won't break the MSRV, we should probably pin this to 1.10 to be consistent with other crates?
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.
This was only to get CI passing. Still have to resolve the MSRV issues on main.
opentelemetry-api/src/common.rs
Outdated
); | ||
|
||
impl From<Vec<&'static str>> for Array { | ||
/// Convenience method for creating a `Value` from a `&'static str`. |
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.
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?
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.
Happy to remove them
|
||
impl StringValue { | ||
/// Returns a string slice to this value | ||
pub fn as_str(&self) -> &str { |
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.
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())), |
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.
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.
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.
Agreed
This updates attribute
Key
andValue
inner types fromCow<'static, str>
to a new privateOtelString
enum to support static, owned, or ref counted values.Resolves #809