-
Notifications
You must be signed in to change notification settings - Fork 910
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
Allow configuring MDC key names for trace_id, span_id, trace_flags #9390
Comments
Related discussion: #8402 |
hey @philsttr, can you give a bit of context around why you can't rename them (and remove trace flags) in the encoder? thx e.g.
|
A couple possibilities:
|
Hi, as another example, say I want to use Elasticsearch as a backend for app log data. In this scenario, it would be common for me to employ the Elastic ECS Encoder to format my log statements. The Elastic ECS Encoder will dump all MDC args as is to the JSON log line; there is no configuration option to rename certain MDC arguments. The Elasticsearch backend wants "trace_id" to be "trace.id" and "span_id" to be "span.id" to connect the dots from the log lines to the trace data, per ECS conventions. To make this work today, I currently need to rename these fields on ingest. Ideally, we could rename them at the source to follow ECS conventions... Given the existing choice of naming, a configurable option probably makes sense. thoughts? |
it seems like there's enough interest in this feature that we'd accept it if someone wishes to contribute it. the most complicated part will probably be agreeing on configuration property names two concerns with this proposal:
|
Hi ! Here I would suggest to have the following configuration options:
When one of these keys is empty, it means the field should not be injected in the MDC. |
Since this is common to multiple instrumentations, and I see the
|
👍 |
Hi @trask, |
hi @pavelvodrazka! if you'd like to send a PR that would be great |
I will reopen this pr, We can work together. |
Hi @AlchemyDing, |
Sorry, I suddenly realized that the original branch was deleted by me, so PR cannot be reopened. I will restore it tomorrow. Do you think it's okay? |
@pavelvodrazka Continue in PR |
@AlchemyDing Is there anything missing in your PR? I ported the changes from your old PR yesterday and my instrumented app with Logback and Logstash encoder worked fine. I was able to change the MDC keys without any trouble. I only see failed checks:
|
The failure of |
So am I correct that nothing needs to be done with this PR at this time other than a review by the OTel team? |
@pavelvodrazka If you are interested, you can provide suggestions for the code. |
I took a look yesterday and i looked good to me. @trask Can you please also take a look? |
it looks like the main open issue on the PR is that it needs tests |
Is your feature request related to a problem? Please describe.
The MDC keys used for
trace_id,
span_id
, andtrace_flags
are currently hardcoded in LoggingContextConstants.Sometimes applications have different standards for MDC key names. Such as using abbreviated names, camelCase, or a prefix.
For example, using abbreviated names or camelCase can save logging costs when billions of log messages are sent to a cloud logging provider that bills by data volume.
Describe the solution you'd like
I'd like the ability to configure the MDC keys used for the
trace_id,
span_id
, andtrace_flags
fields.As a stretch goal, I would also like the ability to turn off the
trace_flags
MDC key.Perhaps something like a property containing key value pairs, with keys being the current names, and values being the new name (or empty for exclusion).
For example, to rename
trace_id
andspan_id
, and excludetrace_flags
(or equivalent for the
log4j-mdc
,logback-mdc
, andlog4j-context-data
instrumentations)Describe alternatives you've considered
Some log encoders (such as those provided by logstash-logback-encoder) allow renaming or excluding MDC keys.
But many log encoders do not have this feature.
Additional context
No response
The text was updated successfully, but these errors were encountered: