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

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

Closed
pitoniak32 opened this issue Aug 24, 2024 · 2 comments
Labels
enhancement New feature or request triage:todo Needs to be traiged.

Comments

@pitoniak32
Copy link

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 pitoniak32 added enhancement New feature or request triage:todo Needs to be traiged. labels Aug 24, 2024
@lalitb
Copy link
Member

lalitb commented Aug 26, 2024

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.

@pitoniak32
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request triage:todo Needs to be traiged.
Projects
None yet
Development

No branches or pull requests

2 participants