From 2736fadc2dd5fe81f6f2d210b37106f25791d6bc Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Mon, 19 Aug 2024 13:52:51 -0700 Subject: [PATCH] Bump opentelemetry to latest version (#33) --- CHANGELOG.md | 4 +++ anaconda/meta.yaml | 6 ++-- setup.py | 6 ++-- .../exporter/otlp/proto/logs/__init__.py | 8 ++--- tests/test_log_encoder.py | 29 +++++++++------- tests/test_metrics_encoder.py | 6 ++-- tests/test_trace_encoder.py | 33 +++++++++---------- 7 files changed, 49 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa1a3c6..81b0510 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History +## Unreleased + +* Upgrade OpenTelemetry Python dependencies to version 1.26.0 + ## 0.5.0 (2024-07-23) * Set empty resource for Python OpenTelemetry config. diff --git a/anaconda/meta.yaml b/anaconda/meta.yaml index 47d12c8..cd27e14 100644 --- a/anaconda/meta.yaml +++ b/anaconda/meta.yaml @@ -11,9 +11,9 @@ requirements: - setuptools >=40.0.0 run: - python - - opentelemetry-api ==1.23.0 - - opentelemetry-exporter-otlp-proto-common ==1.23.0 - - opentelemetry-sdk ==1.23.0 + - opentelemetry-api ==1.26.0 + - opentelemetry-exporter-otlp-proto-common ==1.26.0 + - opentelemetry-sdk ==1.26.0 about: home: https://www.snowflake.com/ diff --git a/setup.py b/setup.py index 92c3682..06b813c 100644 --- a/setup.py +++ b/setup.py @@ -27,9 +27,9 @@ description=DESCRIPTION, long_description=LONG_DESCRIPTION, install_requires=[ - "opentelemetry-api == 1.23.0", - "opentelemetry-exporter-otlp-proto-common == 1.23.0", - "opentelemetry-sdk == 1.23.0", + "opentelemetry-api == 1.26.0", + "opentelemetry-exporter-otlp-proto-common == 1.26.0", + "opentelemetry-sdk == 1.26.0", ], packages=find_namespace_packages( where='src' diff --git a/src/snowflake/telemetry/_internal/exporter/otlp/proto/logs/__init__.py b/src/snowflake/telemetry/_internal/exporter/otlp/proto/logs/__init__.py index a08f74c..3214e3e 100644 --- a/src/snowflake/telemetry/_internal/exporter/otlp/proto/logs/__init__.py +++ b/src/snowflake/telemetry/_internal/exporter/otlp/proto/logs/__init__.py @@ -183,10 +183,10 @@ class _SnowflakeTelemetryLoggerProvider(_logs.LoggerProvider): """ def get_logger( - self, - name: str, - version: types.Optional[str] = None, - schema_url: types.Optional[str] = None, + self, name: str, + version: types.Optional[str] = None, + schema_url: types.Optional[str] = None, + attributes: types.Optional[types.Attributes] = None, ) -> _logs.Logger: return _SnowflakeTelemetryLogger( Resource.get_empty(), diff --git a/tests/test_log_encoder.py b/tests/test_log_encoder.py index cf189d6..a4cfb95 100644 --- a/tests/test_log_encoder.py +++ b/tests/test_log_encoder.py @@ -13,7 +13,7 @@ # limitations under the License. import unittest -from typing import List, Tuple +from typing import Sequence, Tuple from opentelemetry._logs import SeverityNumber from opentelemetry.exporter.otlp.proto.common._internal import ( @@ -40,8 +40,7 @@ from opentelemetry.proto.resource.v1.resource_pb2 import ( Resource as PB2Resource, ) -from opentelemetry.sdk._logs import LogData, LogLimits -from opentelemetry.sdk._logs import LogRecord as SDKLogRecord +from opentelemetry.sdk._logs import LogData, LogLimits, LogRecord as SDKLogRecord from opentelemetry.sdk.resources import Resource as SDKResource from opentelemetry.sdk.util.instrumentation import InstrumentationScope from opentelemetry.trace import TraceFlags @@ -82,10 +81,11 @@ def test_dropped_attributes_count(self): ) @staticmethod - def _get_sdk_log_data() -> List[LogData]: + def _get_sdk_log_data() -> Sequence[LogData]: log1 = LogData( log_record=SDKLogRecord( timestamp=1644650195189786880, + observed_timestamp=1644660000000000000, trace_id=89564621134313219400156819398935297684, span_id=1312458408527513268, trace_flags=TraceFlags(0x01), @@ -106,6 +106,7 @@ def _get_sdk_log_data() -> List[LogData]: log2 = LogData( log_record=SDKLogRecord( timestamp=1644650249738562048, + observed_timestamp=1644660000000000000, trace_id=0, span_id=0, trace_flags=TraceFlags.DEFAULT, @@ -123,6 +124,7 @@ def _get_sdk_log_data() -> List[LogData]: log3 = LogData( log_record=SDKLogRecord( timestamp=1644650427658989056, + observed_timestamp=1644660000000000000, trace_id=271615924622795969659406376515024083555, span_id=4242561578944770265, trace_flags=TraceFlags(0x01), @@ -138,6 +140,7 @@ def _get_sdk_log_data() -> List[LogData]: log4 = LogData( log_record=SDKLogRecord( timestamp=1644650584292683008, + observed_timestamp=1644660000000000000, trace_id=212592107417388365804938480559624925555, span_id=6077757853989569223, trace_flags=TraceFlags(0x01), @@ -159,7 +162,7 @@ def _get_sdk_log_data() -> List[LogData]: def get_test_logs( self, - ) -> Tuple[List[SDKLogRecord], ExportLogsServiceRequest]: + ) -> Tuple[Sequence[LogData], ExportLogsServiceRequest]: sdk_logs = self._get_sdk_log_data() pb2_service_request = ExportLogsServiceRequest( @@ -181,13 +184,14 @@ def get_test_logs( log_records=[ PB2LogRecord( time_unix_nano=1644650195189786880, + observed_time_unix_nano=1644660000000000000, trace_id=_encode_trace_id( 89564621134313219400156819398935297684 ), span_id=_encode_span_id( 1312458408527513268 ), - flags=int(TraceFlags(0x01)), + flags=int(0x01), severity_text="WARN", severity_number=SeverityNumber.WARN.value, body=_encode_value( @@ -207,13 +211,14 @@ def get_test_logs( log_records=[ PB2LogRecord( time_unix_nano=1644650584292683008, + observed_time_unix_nano=1644660000000000000, trace_id=_encode_trace_id( 212592107417388365804938480559624925555 ), span_id=_encode_span_id( 6077757853989569223 ), - flags=int(TraceFlags(0x01)), + flags=int(0x01), severity_text="INFO", severity_number=SeverityNumber.INFO.value, body=_encode_value( @@ -249,9 +254,8 @@ def get_test_logs( log_records=[ PB2LogRecord( time_unix_nano=1644650249738562048, - trace_id=_encode_trace_id(0), - span_id=_encode_span_id(0), - flags=int(TraceFlags.DEFAULT), + observed_time_unix_nano=1644660000000000000, + flags=int(0x00), severity_text="WARN", severity_number=SeverityNumber.WARN.value, body=_encode_value( @@ -266,13 +270,14 @@ def get_test_logs( log_records=[ PB2LogRecord( time_unix_nano=1644650427658989056, + observed_time_unix_nano=1644660000000000000, trace_id=_encode_trace_id( 271615924622795969659406376515024083555 ), span_id=_encode_span_id( 4242561578944770265 ), - flags=int(TraceFlags(0x01)), + flags=int(0x01), severity_text="DEBUG", severity_number=SeverityNumber.DEBUG.value, body=_encode_value("To our galaxy"), @@ -290,7 +295,7 @@ def get_test_logs( return sdk_logs, pb2_service_request @staticmethod - def _get_test_logs_dropped_attributes() -> List[LogData]: + def _get_test_logs_dropped_attributes() -> Sequence[LogData]: log1 = LogData( log_record=SDKLogRecord( timestamp=1644650195189786880, diff --git a/tests/test_metrics_encoder.py b/tests/test_metrics_encoder.py index bb4b1d8..76464a6 100644 --- a/tests/test_metrics_encoder.py +++ b/tests/test_metrics_encoder.py @@ -33,10 +33,8 @@ from opentelemetry.sdk.metrics.export import AggregationTemporality, Buckets from opentelemetry.sdk.metrics.export import ( ExponentialHistogram as ExponentialHistogramType, -) -from opentelemetry.sdk.metrics.export import ExponentialHistogramDataPoint -from opentelemetry.sdk.metrics.export import Histogram as HistogramType -from opentelemetry.sdk.metrics.export import ( + Histogram as HistogramType, + ExponentialHistogramDataPoint, HistogramDataPoint, Metric, MetricsData, diff --git a/tests/test_trace_encoder.py b/tests/test_trace_encoder.py index 0fc767f..322a521 100644 --- a/tests/test_trace_encoder.py +++ b/tests/test_trace_encoder.py @@ -40,10 +40,11 @@ from opentelemetry.proto.trace.v1.trace_pb2 import ( ResourceSpans as PB2ResourceSpans, TracesData as PB2TracesData, + ScopeSpans as PB2ScopeSpans, + Span as PB2Span, + SpanFlags as PB2SpanFlags, + Status as PB2Status, ) -from opentelemetry.proto.trace.v1.trace_pb2 import ScopeSpans as PB2ScopeSpans -from opentelemetry.proto.trace.v1.trace_pb2 import Span as PB2SPan -from opentelemetry.proto.trace.v1.trace_pb2 import Status as PB2Status from opentelemetry.sdk.trace import Event as SDKEvent from opentelemetry.sdk.trace import Resource as SDKResource from opentelemetry.sdk.trace import SpanContext as SDKSpanContext @@ -97,7 +98,7 @@ def get_exhaustive_otel_span_list() -> List[SDKSpan]: ) parent_span_context = SDKSpanContext( - trace_id, 0x1111111111111111, is_remote=False + trace_id, 0x1111111111111111, is_remote=True ) other_context = SDKSpanContext( @@ -185,15 +186,15 @@ def get_exhaustive_test_spans( PB2ScopeSpans( scope=PB2InstrumentationScope(), spans=[ - PB2SPan( + PB2Span( trace_id=trace_id, span_id=_encode_span_id( otel_spans[0].context.span_id ), - trace_state=None, parent_span_id=_encode_span_id( otel_spans[0].parent.span_id ), + flags=PB2SpanFlags.SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK|PB2SpanFlags.SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK, name=otel_spans[0].name, kind=span_kind, start_time_unix_nano=otel_spans[ @@ -221,7 +222,7 @@ def get_exhaustive_test_spans( ), ], events=[ - PB2SPan.Event( + PB2Span.Event( name="event0", time_unix_nano=otel_spans[0] .events[0] @@ -249,7 +250,7 @@ def get_exhaustive_test_spans( ) ], links=[ - PB2SPan.Link( + PB2Span.Link( trace_id=_encode_trace_id( otel_spans[0] .links[0] @@ -260,6 +261,7 @@ def get_exhaustive_test_spans( .links[0] .context.span_id ), + flags=PB2SpanFlags.SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK, attributes=[ PB2KeyValue( key="key_bool", @@ -283,13 +285,12 @@ def get_exhaustive_test_spans( version="version", ), spans=[ - PB2SPan( + PB2Span( trace_id=trace_id, span_id=_encode_span_id( otel_spans[3].context.span_id ), - trace_state=None, - parent_span_id=None, + flags=PB2SpanFlags.SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK, name=otel_spans[3].name, kind=span_kind, start_time_unix_nano=otel_spans[ @@ -320,13 +321,12 @@ def get_exhaustive_test_spans( PB2ScopeSpans( scope=PB2InstrumentationScope(), spans=[ - PB2SPan( + PB2Span( trace_id=trace_id, span_id=_encode_span_id( otel_spans[1].context.span_id ), - trace_state=None, - parent_span_id=None, + flags=PB2SpanFlags.SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK, name=otel_spans[1].name, kind=span_kind, start_time_unix_nano=otel_spans[ @@ -338,13 +338,12 @@ def get_exhaustive_test_spans( links=None, status={}, ), - PB2SPan( + PB2Span( trace_id=trace_id, span_id=_encode_span_id( otel_spans[2].context.span_id ), - trace_state=None, - parent_span_id=None, + flags=PB2SpanFlags.SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK, name=otel_spans[2].name, kind=span_kind, start_time_unix_nano=otel_spans[