rust_tracy_client icon indicating copy to clipboard operation
rust_tracy_client copied to clipboard

Disable ansi for tracing_tracy

Open TheCodeLamp opened this issue 1 year ago • 2 comments

I don't believe tracy can display ansi characters so it's just added characters that obfuscate span names. I saw that ansi support for tracing_subscriber is a feature flag so it might only be possible to disable this if that flag is turned on. But it seems it's possible to set the .with_ansi(false) on a fmt layer even without the ansi flag enabled.

It's possible to disable this by setting the NO_COLOR env flag, but I feel like the tracing layer shouldn't submit color characters by default.

Relevant issue: #72

Maybe relevant links?: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/struct.Layer.html#method.with_ansi https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/struct.Layer.html#method.set_ansi

TheCodeLamp avatar Nov 05 '24 08:11 TheCodeLamp

Fundamentally this is happening because TracyFields is likely the same type as the fields saved to extensions by some other layer that goes out of their way to enable ansi and format the text with the escape codes enabled. The tracy layer then just picks up the cached value.

Otherwise tracy layer with DefaultConfig should not produce ansi escapes.

We could change TracyFields to be its own unique type, but that would lead to reformatting the same messages multiple times for each layer, which is suboptimal too.

While I agree that it would be ideal that tracy worked correctly at all times, this can already be handled by the users by implementing their own Config that returns a different Formatter (new-)type as well. That way they can opt into double work if they wish. Or they could re-order the layers as seen in #72 so that ANSI-less formatter goes first -- but that would then conversely make other layers output tracy-formatted text (without ANSI colour.)

nagisa avatar Nov 05 '24 10:11 nagisa

Thank you for your response. I was suspecting that this was something that was difficult to implement. For my use case just disabling all color using NO_COLOR is ideal as I don't directly touch the tracy layer (I use bevy), and when I profile I can live without color. I hope this helps someone with a similar issue though.

TheCodeLamp avatar Nov 05 '24 10:11 TheCodeLamp