File tree Expand file tree Collapse file tree 3 files changed +32
-0
lines changed
src/opentelemetry/_logs/_internal Expand file tree Collapse file tree 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
3131 [ #3362 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/3362 ) )
3232- Fixed bug where logging export is tracked as trace
3333 [ #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 ) )
3436
3537
3638## Version 1.18.0/0.39b0 (2023-05-19)
Original file line number Diff line number Diff line change 3737from abc import ABC , abstractmethod
3838from logging import getLogger
3939from os import environ
40+ from time import time_ns
4041from typing import Any , Optional , cast
4142
4243from opentelemetry ._logs .severity import SeverityNumber
@@ -70,6 +71,8 @@ def __init__(
7071 attributes : Optional ["Attributes" ] = None ,
7172 ):
7273 self .timestamp = timestamp
74+ if observed_timestamp is None :
75+ observed_timestamp = time_ns ()
7376 self .observed_timestamp = observed_timestamp
7477 self .trace_id = trace_id
7578 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