opentelemetry-rust icon indicating copy to clipboard operation
opentelemetry-rust copied to clipboard

[Feature]: opentelemetry-semantic-conventions ability to directly use semantic attribute constants in tracing::Span.record

Open pitoniak32 opened this issue 1 year ago • 1 comments
trafficstars

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

pitoniak32 avatar Aug 24 '24 17:08 pitoniak32

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.

lalitb avatar Aug 26 '24 09:08 lalitb

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

pitoniak32 avatar Sep 06 '24 19:09 pitoniak32