opentelemetry-python
opentelemetry-python copied to clipboard
Emit SeverityNumber as an integer number
Description
According to the Logs Data Model, SeverityNumber is an integer number. This PR will change the LogRecord.to_json() func to use the SeverityNumber numeric value. Previously the SeverityNumber type, which is an enum.Enum, was being represented as a string value.
Before this PR:
{
"body": "I am an error.",
"severity_number": "<SeverityNumber.ERROR: 17>", <<<--- I am NOT an integer number
"severity_text": "ERROR",
"attributes": {
"code.filepath": "/Users/doug.ramirez/code/urfcs/urfc65/code/run.py",
"code.lineno": 9
},
"timestamp": "2022-08-18T22:22:28.894490Z",
"trace_id": "0x00000000000000000000000000000000",
"span_id": "0x0000000000000000",
"trace_flags": 0,
"resource": "BoundedAttributes({'telemetry.sdk.language': 'python', 'telemetry.sdk.name': 'opentelemetry', 'telemetry.sdk.version': '1.12.0', 'net.host.name': 'Doug.Ramirez', 'net.host.ip': '127.0.0.1', 'service.name': '/Users/doug.ramirez/code/urfcs/urfc65/code/run.py', 'service.version': '6.6.6'}, maxlen=None)"
}
After this PR:
{
"body": "I am an error.",
"severity_number": 17, <<<--- I am an integer number
"severity_text": "ERROR",
"attributes": {
"code.filepath": "/Users/doug.ramirez/code/urfcs/urfc65/code/run.py",
"code.lineno": 9
},
"timestamp": "2022-08-19T21:25:44.861784Z",
"trace_id": "0x00000000000000000000000000000000",
"span_id": "0x0000000000000000",
"trace_flags": 0,
"resource": "BoundedAttributes({'telemetry.sdk.language': 'python', 'telemetry.sdk.name': 'opentelemetry', 'telemetry.sdk.version': '1.12.0', 'net.host.name': 'Doug.Ramirez', 'net.host.ip': '127.0.0.1', 'service.name': '/Users/doug.ramirez/code/urfcs/urfc65/code/run.py', 'service.version': '6.6.6'}, maxlen=None)"
}
Type of change
- [x] Bug fix (non-breaking change which fixes an issue)
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
- [x] Ran opentelemetry-api test suite
- [x] Ran opentelemetry-sdk test suite
Does This PR Require a Contrib Repo Change?
- [x] No.
Checklist:
- [x] Followed the style guidelines of this project
- [x] Changelogs have been updated
Just to reiterate, this exporter exists for debugging purpose only and in that context I think it make sense to show the way it is shown instead of plain number which one can't understand directly. For example, in tracing SpanKind is enum with 0-5 value according to data model but we show it using SpanKind.SERVER instead 2 for the same reason. The formatted values in stdout/console exporter are not guaranteed to be same type as their definition in data model. The real exporter make sure they adhere to model but not this one. We do this for all signals. The to_json was added mainly for the console exporter and seems like it is being used in different context and expectation now changed to correctly serialized json encoded values. In that case we will probably have to get rid of it to prevent the unexpected use.
P.S: Please do not use this as a substitute for official exporters (OTLP, File etc..) that exists to support the data model.
As I mentioned, this is intended for the debugging purpose of SDK. Making it an integer is not user-friendly when read by the naked eye. The same applies to an enum like SpanKind. If you want, you can contribute a JSON exporter or something similar in contrib to make it clear that the output will be JSON deserialised. I am going to close this issue, thanks. Feel free to send a PR in contrib repo.