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

span record method does not record attribute as u16 #3104

Open
pitoniak32 opened this issue Oct 12, 2024 · 2 comments
Open

span record method does not record attribute as u16 #3104

pitoniak32 opened this issue Oct 12, 2024 · 2 comments

Comments

@pitoniak32
Copy link

pitoniak32 commented Oct 12, 2024

Bug Report

Version

❯ cargo tree | rg tracing
│   │   └── tracing v0.1.40
│   │       ├── tracing-attributes v0.1.27 (proc-macro)
│   │       └── tracing-core v0.1.32
│   │   │   └── tracing v0.1.40 (*)
│   │   └── tracing v0.1.40 (*)
│   │   └── tracing v0.1.40 (*)
│   └── tracing v0.1.40 (*)
│   │       │   └── tracing v0.1.40 (*)
│   │       └── tracing v0.1.40 (*)
│   └── tracing v0.1.40 (*)
├── tracing v0.1.40 (*)
├── tracing-log v0.2.0
│   └── tracing-core v0.1.32 (*)
├── tracing-opentelemetry v0.27.0
│   ├── tracing v0.1.40 (*)
│   ├── tracing-core v0.1.32 (*)
│   ├── tracing-log v0.2.0 (*)
│   └── tracing-subscriber v0.3.18
│       ├── tracing v0.1.40 (*)
│       ├── tracing-core v0.1.32 (*)
│       └── tracing-log v0.2.0 (*)
└── tracing-subscriber v0.3.18 (*)

Platform

Linux d 5.15.153.1-microsoft-standard-WSL2 #1 SMP Fri Mar 29 23:14:13 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Description

I am seeing the incorrect type for an integer attribute / tag values that are exported to an external tracing backend (Jaeger).

I tried this code:

tracing::info_span!("request",
    { HTTP_RESPONSE_STATUS_CODE } = None::<u16>,
)

span.record(
    HTTP_RESPONSE_STATUS_CODE,
    response.status().as_u16(), // this returns a u16 `pub fn as_u16(&self) -> u16`
);

I expected to see the type of the http.response.status_code field to be an integer.

Screenshot 2024-10-12 124601

Instead, it was a string.

Screenshot 2024-10-12 124417

if I use an integer directly it will be the correct type:

tracing::info_span!("request",
    { HTTP_RESPONSE_STATUS_CODE } = None::<u16>,
)

span.record(
    HTTP_RESPONSE_STATUS_CODE,
    400,
);
@pitoniak32 pitoniak32 changed the title span record does not record attribute as u16 span record method does not record attribute as u16 Oct 12, 2024
@pitoniak32
Copy link
Author

(facepalm 😅) I found a work around for the issue. If you as i64 the value, it shows as an integer in the trace backends.

where I stumbled on the fix

I am still wondering if this is expected behavior?

tracing::info_span!("request",
    { HTTP_RESPONSE_STATUS_CODE } = None::<u16>,
)

span.record(
    HTTP_RESPONSE_STATUS_CODE,
    response.status().as_u16() as i64,
);

@pitoniak32
Copy link
Author

I am still wondering if this is expected behavior?

If it is, I would like to open a PR adding a little documentation to the span.record method to give an example of how to record integer types.

Thank you all again for the amazing work that you do!

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

No branches or pull requests

1 participant