Skip to content

Commit 1347d73

Browse files
Bump opentelemetry to latest version
1 parent 91dd222 commit 1347d73

File tree

16 files changed

+355
-233
lines changed

16 files changed

+355
-233
lines changed

NOTICE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The following notices are required by licensors of software used in the Snowflak
66
--------------------------------------------------------------------------------
77

88
This library includes software which is copied from or derived from the OpenTelemetry Python API and SDK.
9-
OpenTelemetry Python v1.26.0
9+
OpenTelemetry Python v1.33.1
1010
https://github.com/open-telemetry/opentelemetry-python
1111

1212
Apache License

anaconda/meta.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ requirements:
1414
- setuptools >=40.0.0
1515
run:
1616
- python
17-
- opentelemetry-api ==1.26.0
18-
- opentelemetry-sdk ==1.26.0
17+
- opentelemetry-api ==1.33.1
18+
- opentelemetry-sdk ==1.33.1
1919

2020
about:
2121
home: https://www.snowflake.com/

scripts/vendor_otlp_proto_common.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# fixes needed in the OTLP exporter.
1010

1111
# Pinned commit/branch/tag for the current version used in opentelemetry-proto python package.
12-
REPO_BRANCH_OR_COMMIT="v1.26.0"
12+
REPO_BRANCH_OR_COMMIT="v1.33.1"
1313

1414
set -e
1515

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
description=DESCRIPTION,
2828
long_description=LONG_DESCRIPTION,
2929
install_requires=[
30-
"opentelemetry-api == 1.26.0",
31-
"opentelemetry-sdk == 1.26.0",
30+
"opentelemetry-api == 1.33.1",
31+
"opentelemetry-sdk == 1.33.1",
3232
],
3333
packages=find_namespace_packages(
3434
where='src'

src/snowflake/telemetry/_internal/exporter/otlp/proto/logs/__init__.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,13 @@ class SnowflakeLoggingHandler(_logs.LoggingHandler):
8484
discarded by the original implementation.
8585
"""
8686

87-
LOGGER_NAME_TEMP_ATTRIBUTE = "__snow.logging.temp.logger_name"
87+
LOGGER_NAME_TEMP_ATTRIBUTE: typing.Final = "__snow.logging.temp.logger_name"
88+
CODE_FILEPATH: typing.Final = "code.filepath"
89+
CODE_FILE_PATH: typing.Final = "code.file.path"
90+
CODE_FUNCTION: typing.Final = "code.function"
91+
CODE_FUNCTION_NAME: typing.Final = "code.function.name"
92+
CODE_LINENO: typing.Final = "code.lineno"
93+
CODE_LINE_NUMBER: typing.Final = "code.line.number"
8894

8995
def __init__(
9096
self,
@@ -101,6 +107,17 @@ def __init__(
101107
def _get_attributes(record: logging.LogRecord) -> types.Attributes:
102108
attributes = _logs.LoggingHandler._get_attributes(record) # pylint: disable=protected-access
103109

110+
# Preserving old naming conventions for code attributes that were changed as part of
111+
# https://github.com/open-telemetry/opentelemetry-python/commit/1b1e8d80c764ad3aa76abfb56a7002ddea11fdb5 in
112+
# order to avoid a behavior change for Snowflake customers.
113+
if SnowflakeLoggingHandler.CODE_FILE_PATH in attributes:
114+
attributes[SnowflakeLoggingHandler.CODE_FILEPATH] = attributes.pop(SnowflakeLoggingHandler.CODE_FILE_PATH)
115+
if SnowflakeLoggingHandler.CODE_FUNCTION_NAME in attributes:
116+
attributes[SnowflakeLoggingHandler.CODE_FUNCTION] = attributes.pop(
117+
SnowflakeLoggingHandler.CODE_FUNCTION_NAME)
118+
if SnowflakeLoggingHandler.CODE_LINE_NUMBER in attributes:
119+
attributes[SnowflakeLoggingHandler.CODE_LINENO] = attributes.pop(SnowflakeLoggingHandler.CODE_LINE_NUMBER)
120+
104121
# Temporarily storing logger's name in record's attributes.
105122
# This attribute will be removed by the logger.
106123
#

src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#
1515
# This file has been modified from the original source code at
1616
#
17-
# https://github.com/open-telemetry/opentelemetry-python/tree/v1.26.0
17+
# https://github.com/open-telemetry/opentelemetry-python/tree/v1.33.1
1818
#
1919
# by Snowflake Inc.
2020

src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,44 @@
1414
#
1515
# This file has been modified from the original source code at
1616
#
17-
# https://github.com/open-telemetry/opentelemetry-python/tree/v1.26.0
17+
# https://github.com/open-telemetry/opentelemetry-python/tree/v1.33.1
1818
#
1919
# by Snowflake Inc.
2020

2121

22+
from __future__ import annotations
23+
2224
import logging
2325
from collections.abc import Sequence
2426
from itertools import count
2527
from typing import (
2628
Any,
27-
Mapping,
28-
Optional,
29-
List,
3029
Callable,
31-
TypeVar,
3230
Dict,
3331
Iterator,
32+
List,
33+
Mapping,
34+
Optional,
35+
TypeVar,
3436
)
3537

36-
from opentelemetry.sdk.util.instrumentation import InstrumentationScope
38+
from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common_marshaler import AnyValue as PB2AnyValue
3739
from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common_marshaler import (
38-
InstrumentationScope as PB2InstrumentationScope,
40+
ArrayValue as PB2ArrayValue,
3941
)
40-
from snowflake.telemetry._internal.opentelemetry.proto.resource.v1.resource_marshaler import (
41-
Resource as PB2Resource,
42+
from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common_marshaler import (
43+
InstrumentationScope as PB2InstrumentationScope,
4244
)
43-
from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common_marshaler import AnyValue as PB2AnyValue
4445
from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common_marshaler import KeyValue as PB2KeyValue
4546
from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common_marshaler import (
4647
KeyValueList as PB2KeyValueList,
4748
)
48-
from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common_marshaler import (
49-
ArrayValue as PB2ArrayValue,
49+
from snowflake.telemetry._internal.opentelemetry.proto.resource.v1.resource_marshaler import (
50+
Resource as PB2Resource,
5051
)
5152
from opentelemetry.sdk.trace import Resource
52-
from opentelemetry.util.types import Attributes
53+
from opentelemetry.sdk.util.instrumentation import InstrumentationScope
54+
from opentelemetry.util.types import _ExtendedAttributes
5355

5456
_logger = logging.getLogger(__name__)
5557

@@ -65,14 +67,19 @@ def _encode_instrumentation_scope(
6567
return PB2InstrumentationScope(
6668
name=instrumentation_scope.name,
6769
version=instrumentation_scope.version,
70+
attributes=_encode_attributes(instrumentation_scope.attributes),
6871
)
6972

7073

7174
def _encode_resource(resource: Resource) -> PB2Resource:
7275
return PB2Resource(attributes=_encode_attributes(resource.attributes))
7376

7477

75-
def _encode_value(value: Any) -> PB2AnyValue:
78+
def _encode_value(
79+
value: Any, allow_null: bool = False
80+
) -> Optional[PB2AnyValue]:
81+
if allow_null is True and value is None:
82+
return None
7683
if isinstance(value, bool):
7784
return PB2AnyValue(bool_value=value)
7885
if isinstance(value, str):
@@ -81,21 +88,49 @@ def _encode_value(value: Any) -> PB2AnyValue:
8188
return PB2AnyValue(int_value=value)
8289
if isinstance(value, float):
8390
return PB2AnyValue(double_value=value)
91+
if isinstance(value, bytes):
92+
return PB2AnyValue(bytes_value=value)
8493
if isinstance(value, Sequence):
8594
return PB2AnyValue(
86-
array_value=PB2ArrayValue(values=[_encode_value(v) for v in value])
95+
array_value=PB2ArrayValue(
96+
values=_encode_array(value, allow_null=allow_null)
97+
)
8798
)
8899
elif isinstance(value, Mapping):
89100
return PB2AnyValue(
90101
kvlist_value=PB2KeyValueList(
91-
values=[_encode_key_value(str(k), v) for k, v in value.items()]
102+
values=[
103+
_encode_key_value(str(k), v, allow_null=allow_null)
104+
for k, v in value.items()
105+
]
92106
)
93107
)
94108
raise Exception(f"Invalid type {type(value)} of value {value}")
95109

96110

97-
def _encode_key_value(key: str, value: Any) -> PB2KeyValue:
98-
return PB2KeyValue(key=key, value=_encode_value(value))
111+
def _encode_key_value(
112+
key: str, value: Any, allow_null: bool = False
113+
) -> PB2KeyValue:
114+
return PB2KeyValue(
115+
key=key, value=_encode_value(value, allow_null=allow_null)
116+
)
117+
118+
119+
def _encode_array(
120+
array: Sequence[Any], allow_null: bool = False
121+
) -> Sequence[PB2AnyValue]:
122+
if not allow_null:
123+
# Let the exception get raised by _encode_value()
124+
return [_encode_value(v, allow_null=allow_null) for v in array]
125+
126+
return [
127+
_encode_value(v, allow_null=allow_null)
128+
if v is not None
129+
# Use an empty AnyValue to represent None in an array. Behavior may change pending
130+
# https://github.com/open-telemetry/opentelemetry-specification/issues/4392
131+
else PB2AnyValue()
132+
for v in array
133+
]
99134

100135

101136
def _encode_span_id(span_id: int) -> bytes:
@@ -107,14 +142,17 @@ def _encode_trace_id(trace_id: int) -> bytes:
107142

108143

109144
def _encode_attributes(
110-
attributes: Attributes,
145+
attributes: _ExtendedAttributes,
146+
allow_null: bool = False,
111147
) -> Optional[List[PB2KeyValue]]:
112148
if attributes:
113149
pb2_attributes = []
114150
for key, value in attributes.items():
115151
# pylint: disable=broad-exception-caught
116152
try:
117-
pb2_attributes.append(_encode_key_value(key, value))
153+
pb2_attributes.append(
154+
_encode_key_value(key, value, allow_null=allow_null)
155+
)
118156
except Exception as error:
119157
_logger.exception("Failed to encode key %s: %s", key, error)
120158
else:

src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/_log_encoder/__init__.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,28 @@
1414
#
1515
# This file has been modified from the original source code at
1616
#
17-
# https://github.com/open-telemetry/opentelemetry-python/tree/v1.26.0
17+
# https://github.com/open-telemetry/opentelemetry-python/tree/v1.33.1
1818
#
1919
# by Snowflake Inc.
2020
from collections import defaultdict
21-
from typing import Sequence, List
21+
from typing import List, Sequence
2222

2323
from snowflake.telemetry._internal.opentelemetry.exporter.otlp.proto.common._internal import (
24+
_encode_attributes,
2425
_encode_instrumentation_scope,
2526
_encode_resource,
2627
_encode_span_id,
2728
_encode_trace_id,
2829
_encode_value,
29-
_encode_attributes,
3030
)
3131
from snowflake.telemetry._internal.opentelemetry.proto.collector.logs.v1.logs_service_marshaler import (
3232
ExportLogsServiceRequest,
3333
)
34+
from snowflake.telemetry._internal.opentelemetry.proto.logs.v1.logs_marshaler import LogRecord as PB2LogRecord
3435
from snowflake.telemetry._internal.opentelemetry.proto.logs.v1.logs_marshaler import (
35-
ScopeLogs,
3636
ResourceLogs,
37+
ScopeLogs,
3738
)
38-
from snowflake.telemetry._internal.opentelemetry.proto.logs.v1.logs_marshaler import LogRecord as PB2LogRecord
39-
4039
from opentelemetry.sdk._logs import LogData
4140

4241

@@ -55,15 +54,18 @@ def _encode_log(log_data: LogData) -> PB2LogRecord:
5554
if log_data.log_record.trace_id == 0
5655
else _encode_trace_id(log_data.log_record.trace_id)
5756
)
57+
body = log_data.log_record.body
5858
return PB2LogRecord(
5959
time_unix_nano=log_data.log_record.timestamp,
6060
observed_time_unix_nano=log_data.log_record.observed_timestamp,
6161
span_id=span_id,
6262
trace_id=trace_id,
6363
flags=int(log_data.log_record.trace_flags),
64-
body=_encode_value(log_data.log_record.body),
64+
body=_encode_value(body, allow_null=True),
6565
severity_text=log_data.log_record.severity_text,
66-
attributes=_encode_attributes(log_data.log_record.attributes),
66+
attributes=_encode_attributes(
67+
log_data.log_record.attributes, allow_null=True
68+
),
6769
dropped_attributes_count=log_data.log_record.dropped_attributes,
6870
severity_number=log_data.log_record.severity_number.value,
6971
)
@@ -88,6 +90,9 @@ def _encode_resource_logs(batch: Sequence[LogData]) -> List[ResourceLogs]:
8890
ScopeLogs(
8991
scope=(_encode_instrumentation_scope(sdk_instrumentation)),
9092
log_records=pb2_logs,
93+
schema_url=sdk_instrumentation.schema_url
94+
if sdk_instrumentation
95+
else None,
9196
)
9297
)
9398
pb2_resource_logs.append(

0 commit comments

Comments
 (0)