File tree Expand file tree Collapse file tree 3 files changed +50
-2
lines changed
src/opentelemetry/sdk/_logs Expand file tree Collapse file tree 3 files changed +50
-2
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
25
25
([ #2383 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/2383 ) )
26
26
- [ exporter/opentelemetry-exporter-otlp-proto-grpc] Add Gauge to OTLPMetricExporter
27
27
([ #2408 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/2408 ) )
28
+ - [ logs] prevent None from causing problems
29
+ ([ #2410 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/2410 ) )
28
30
29
31
## [ 1.8.0-0.27b0] ( https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.8.0-0.27b0 ) - 2021-12-17
30
32
Original file line number Diff line number Diff line change @@ -87,8 +87,12 @@ def to_json(self) -> str:
87
87
"severity_text" : self .severity_text ,
88
88
"attributes" : self .attributes ,
89
89
"timestamp" : ns_to_iso_str (self .timestamp ),
90
- "trace_id" : f"0x{ format_trace_id (self .trace_id )} " ,
91
- "span_id" : f"0x{ format_span_id (self .span_id )} " ,
90
+ "trace_id" : f"0x{ format_trace_id (self .trace_id )} "
91
+ if self .trace_id is not None
92
+ else "" ,
93
+ "span_id" : f"0x{ format_span_id (self .span_id )} "
94
+ if self .span_id is not None
95
+ else "" ,
92
96
"trace_flags" : self .trace_flags ,
93
97
"resource" : repr (self .resource .attributes )
94
98
if self .resource
Original file line number Diff line number Diff line change
1
+ # Copyright The OpenTelemetry Authors
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import json
16
+ import unittest
17
+
18
+ from opentelemetry .sdk ._logs import LogRecord
19
+
20
+
21
+ class TestLogRecord (unittest .TestCase ):
22
+ def test_log_record_to_json (self ):
23
+ expected = json .dumps (
24
+ {
25
+ "body" : "a log line" ,
26
+ "name" : None ,
27
+ "severity_number" : "None" ,
28
+ "severity_text" : None ,
29
+ "attributes" : None ,
30
+ "timestamp" : "1970-01-01T00:00:00.000000Z" ,
31
+ "trace_id" : "" ,
32
+ "span_id" : "" ,
33
+ "trace_flags" : None ,
34
+ "resource" : "" ,
35
+ },
36
+ indent = 4 ,
37
+ )
38
+ actual = LogRecord (
39
+ timestamp = 0 ,
40
+ body = "a log line" ,
41
+ ).to_json ()
42
+ self .assertEqual (expected , actual )
You can’t perform that action at this time.
0 commit comments