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

Support using event targets as labels #16

Open
abonander opened this issue May 9, 2023 · 4 comments
Open

Support using event targets as labels #16

abonander opened this issue May 9, 2023 · 4 comments

Comments

@abonander
Copy link

I had a hell of a time figuring out how to actually filter events by target in Grafana, because it appears they're not provided as labels: https://github.com/hrxi/tracing-loki/blob/master/src/lib.rs#L241

Having dug into Loki more, I understand why this choice was made (as it may exceed cardinality limits) but I would at least like to have the option.

Renaming target to _target also just makes it more annoying to use the json parser, as I have to do | json target="_target" instead of just | json target.

@hrxi
Copy link
Owner

hrxi commented May 10, 2023

Having dug into Loki more, I understand why this choice was made (as it may exceed cardinality limits) but I would at least like to have the option.

As you found out in the docs, it's probably something one shouldn't really do. I find it hard to justify working towards that if I don't see the use case. Can you explain why you want it after having read the docs?

@abonander
Copy link
Author

In use-cases where the cardinality of the target field is controlled, this could be incredibly useful.

Honestly, the more flexible solution would be to support a callback that can add arbitrary labels to a single event, given its metadata.

@hrxi
Copy link
Owner

hrxi commented May 12, 2023

In use-cases where the cardinality of the target field is controlled, this could be incredibly useful.

And you do have such a use case, it's not entirely hypothetical?

Honestly, the more flexible solution would be to support a callback that can add arbitrary labels to a single event, given its metadata.

Currently, the code exploits that the labels never change during the runtime. Changing this assumption is probably going to cost a bit of performance. This means that there should be a clear use case.

@blastrock
Copy link

I second this issue, and would even go further. I would like to have a way to specify any field in the builder to be sent as label. Something like:

    let (layer, task) = tracing_loki::builder()
        .label("host", "mine")?
        .extra_field("pid", format!("{}", process::id()))?
        .export_field_as_label("target")
        .export_field_as_label("my_custom_field")
        .build_url(Url::parse("http://127.0.0.1:3100").unwrap())?;

    // ...

    info!(my_custom_field="one", "test"); 

Sometimes I need to filter the logs with custom fields to debug an application, and there are a lot of logs and filtering on a field is very slow. Since it's my application, I fully control the cardinality of those labels. I think this would be a very useful feature, and it lets the developer have the control on whether they want to pay the price for more indexes for faster look ups.

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

3 participants