Skip to content

Commit 8ad10f7

Browse files
authored
Fix python 3.12 deprecation warning (open-telemetry#3751)
* Fix python 3.12 deprecation warning utcfromtimestamp is deprecated replace with fromtimestamp with explict UTC timezone See https://docs.python.org/3/library/datetime.html#datetime.datetime.utcfromtimestamp * add changelog for 3751
1 parent 216411f commit 8ad10f7

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
- Fix python 3.12 deprecation warning
11+
([#3751](https://github.com/open-telemetry/opentelemetry-python/pull/3751))
12+
1013
## Version 1.23.0/0.44b0 (2024-02-23)
1114

1215
- Use Attribute rather than boundattribute in logrecord

opentelemetry-sdk/src/opentelemetry/sdk/util/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323

2424
def ns_to_iso_str(nanoseconds):
2525
"""Get an ISO 8601 string from time_ns value."""
26-
ts = datetime.datetime.utcfromtimestamp(nanoseconds / 1e9)
26+
ts = datetime.datetime.fromtimestamp(
27+
nanoseconds / 1e9, tz=datetime.timezone.utc
28+
)
2729
return ts.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
2830

2931

0 commit comments

Comments
 (0)