opentelemetry-rust
opentelemetry-rust copied to clipboard
[Feature]: opentelemetry-semantic-conventions ability to directly use semantic attribute constants in tracing::Span.record
Related Problems?
I have been searching for the best way to use the semantic attribute constants when creating spans without manually typing out the values in the span macro.
I have only been able to get my desired behavior by manually typing the keys:
tracing::info_span!(
"request",
http.request.method = request.method().to_string(),
http.route = matched_path,
http.response.status_code = Empty,
url.path = request.uri().path(),
url.query = request.uri().query(),
network.protocol.name = version.get(0).map(|v| v.to_lowercase()),
network.protocol.version = version.get(1),
)
I would ideally like to be able to use the available attribute constants when creating a span, so that if one of the conventions is deprecated I will see when I update. But I know it would require updates to the tracing macros.
ex:
tracing::info_span!("request", HTTP_REQUEST_METHOD = request.method().to_string())
Describe the solution you'd like:
I guess the solution I am looking for would be a recommended way to leverage the constants when creating spans. Or maybe some examples of how the attributes should be used.
Considered Alternatives
No response
Additional Context
No response
Specifying constants as field names - I believe this is valid question, probably better to be asked in the tokio tracing repo? There are no examples with tracing integration in this repo for reason mentioned here - https://github.com/open-telemetry/opentelemetry-rust/issues/1571.
Just to add, regarding HTTP semantic conventions (as you added that in example), these semantic conventions are stable , and so won't get deprecated in future.
Specifying constants as field names - I believe this is valid question, probably better to be asked in the tokio tracing repo? There are no examples with tracing integration in this repo for reason mentioned here - #1571.
Just to add, regarding HTTP semantic conventions (as you added that in example), these semantic conventions are stable , and so won't get deprecated in future.
Thank you for the reply! That makes sense, I will close this issue.
Also just in case someone else stumbles on this, I found a solution that works for creating new spans. but not for tracing::info!(...), etc
tracing::info_span!("request", { HTTP_REQUEST_METHOD } = request.method().to_string())