File tree 3 files changed +32
-0
lines changed
src/opentelemetry/_logs/_internal 3 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
31
31
[ #3362 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/3362 ) )
32
32
- Fixed bug where logging export is tracked as trace
33
33
[ #3375 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/3375 ) )
34
+ - Default LogRecord observed_timestamp to current timestamp
35
+ [ #3377 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/3377 ) )
34
36
35
37
36
38
## Version 1.18.0/0.39b0 (2023-05-19)
Original file line number Diff line number Diff line change 37
37
from abc import ABC , abstractmethod
38
38
from logging import getLogger
39
39
from os import environ
40
+ from time import time_ns
40
41
from typing import Any , Optional , cast
41
42
42
43
from opentelemetry ._logs .severity import SeverityNumber
@@ -70,6 +71,8 @@ def __init__(
70
71
attributes : Optional ["Attributes" ] = None ,
71
72
):
72
73
self .timestamp = timestamp
74
+ if observed_timestamp is None :
75
+ observed_timestamp = time_ns ()
73
76
self .observed_timestamp = observed_timestamp
74
77
self .trace_id = trace_id
75
78
self .span_id = span_id
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 unittest
16
+ from unittest .mock import patch
17
+
18
+ from opentelemetry ._logs import LogRecord
19
+
20
+ OBSERVED_TIMESTAMP = "OBSERVED_TIMESTAMP"
21
+
22
+
23
+ class TestLogRecord (unittest .TestCase ):
24
+ @patch ("opentelemetry._logs._internal.time_ns" )
25
+ def test_log_record_observed_timestamp_default (self , time_ns_mock ): # type: ignore
26
+ time_ns_mock .return_value = OBSERVED_TIMESTAMP
27
+ self .assertEqual (LogRecord ().observed_timestamp , OBSERVED_TIMESTAMP )
You can’t perform that action at this time.
0 commit comments