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

Cannot rename fields unless they're present in every log record #6

Closed
nhairs opened this issue Mar 11, 2024 · 1 comment · Fixed by #13
Closed

Cannot rename fields unless they're present in every log record #6

nhairs opened this issue Mar 11, 2024 · 1 comment · Fixed by #13
Labels
enhancement New feature or request

Comments

@nhairs
Copy link
Owner

nhairs commented Mar 11, 2024

Original Issue: madzak/python-json-logger#171

I tried the following configuration to get field names matching the OpenTelemetry semantic conventions:

json:
  (): pythonjsonlogger.jsonlogger.JsonFormatter
  rename_fields:
    otelTraceID: trace_id
    otelSpanID: span_id
    otelServiceName: service.name
     levelname: severity
     message: body
     threadName: thread.name
     exc_type: exception.type
     exc_val: exception.message
     traceback: exception.stacktrace
     pathname: code.filepath
     lineno: code.lineno
     funcName: code.function
  format: '%(levelname)s %(name)s %(threadName)s %(message)s %(pathname)s %(lineno)s %(funcName)s'

It would not work because some of these fields were not present in every log record, but the field rename function requires cannot handle missing fields. In particular, renaming the exception related fields is impossible.

Addendum: explicitly adding these fields to format removes the error, but then they have null values where a log record does not contain an exception. Would it be possible to get fields renamed without making them mandatory?

madzak/python-json-logger#189 appears to be a duplicate

@nhairs
Copy link
Owner Author

nhairs commented Mar 11, 2024

This PR looks like a good candidate: madzak/python-json-logger#186

@nhairs nhairs added the enhancement New feature or request label Mar 11, 2024
nhairs added a commit that referenced this issue May 18, 2024
Fixes #6
Fixes #7

Changes also prevent double renaming of fields.

## Test plan

Run tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant