Skip to content

Commit c71323b

Browse files
authored
Merge branch 'main' into export-nonmonotonic-sums-as-gauges-in-prometheus
2 parents a35c37d + b9f31e9 commit c71323b

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

opentelemetry-api/src/opentelemetry/_logs/_internal/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from abc import ABC, abstractmethod
3838
from logging import getLogger
3939
from os import environ
40+
from time import time_ns
4041
from typing import Any, Optional, cast
4142

4243
from 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
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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)

0 commit comments

Comments
 (0)