Skip to content

Commit 149db70

Browse files
Bump opentelemetry to latest version
1 parent 1871d26 commit 149db70

File tree

16 files changed

+355
-270
lines changed

16 files changed

+355
-270
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.35.0
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.35.0
18+
- opentelemetry-sdk ==1.35.0
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.35.0"
1313

1414
set -e
1515

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
long_description=LONG_DESCRIPTION,
3131
python_requires=REQUIRED_PYTHON_VERSION,
3232
install_requires=[
33-
"opentelemetry-api == 1.26.0",
34-
"opentelemetry-sdk == 1.26.0",
33+
"opentelemetry-api == 1.35.0",
34+
"opentelemetry-sdk == 1.35.0",
3535
],
3636
packages=find_namespace_packages(
3737
where='src'

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

Lines changed: 19 additions & 2 deletions
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
#
@@ -159,7 +176,7 @@ def emit(self, record: _logs.LogRecord):
159176
# 2. It would emit a log record with the default instrumentation scope,
160177
# not with the scope we want.
161178
log_data = _logs.LogData(record, current_scope)
162-
self._multi_log_record_processor.emit(log_data)
179+
self._multi_log_record_processor.on_emit(log_data)
163180

164181

165182
class _SnowflakeTelemetryLoggerProvider(_logs.LoggerProvider):

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.35.0
1818
#
1919
# by Snowflake Inc.
2020

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

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,42 @@
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.35.0
1818
#
1919
# by Snowflake Inc.
2020

2121

22+
from __future__ import annotations
23+
2224
import logging
2325
from collections.abc import Sequence
24-
from itertools import count
2526
from typing import (
2627
Any,
28+
Callable,
29+
Dict,
30+
List,
2731
Mapping,
2832
Optional,
29-
List,
30-
Callable,
3133
TypeVar,
32-
Dict,
33-
Iterator,
3434
)
3535

36-
from opentelemetry.sdk.util.instrumentation import InstrumentationScope
36+
from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common_marshaler import AnyValue as PB2AnyValue
3737
from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common_marshaler import (
38-
InstrumentationScope as PB2InstrumentationScope,
38+
ArrayValue as PB2ArrayValue,
3939
)
40-
from snowflake.telemetry._internal.opentelemetry.proto.resource.v1.resource_marshaler import (
41-
Resource as PB2Resource,
40+
from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common_marshaler import (
41+
InstrumentationScope as PB2InstrumentationScope,
4242
)
43-
from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common_marshaler import AnyValue as PB2AnyValue
4443
from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common_marshaler import KeyValue as PB2KeyValue
4544
from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common_marshaler import (
4645
KeyValueList as PB2KeyValueList,
4746
)
48-
from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common_marshaler import (
49-
ArrayValue as PB2ArrayValue,
47+
from snowflake.telemetry._internal.opentelemetry.proto.resource.v1.resource_marshaler import (
48+
Resource as PB2Resource,
5049
)
5150
from opentelemetry.sdk.trace import Resource
52-
from opentelemetry.util.types import Attributes
51+
from opentelemetry.sdk.util.instrumentation import InstrumentationScope
52+
from opentelemetry.util.types import _ExtendedAttributes
5353

5454
_logger = logging.getLogger(__name__)
5555

@@ -65,14 +65,19 @@ def _encode_instrumentation_scope(
6565
return PB2InstrumentationScope(
6666
name=instrumentation_scope.name,
6767
version=instrumentation_scope.version,
68+
attributes=_encode_attributes(instrumentation_scope.attributes),
6869
)
6970

7071

7172
def _encode_resource(resource: Resource) -> PB2Resource:
7273
return PB2Resource(attributes=_encode_attributes(resource.attributes))
7374

7475

75-
def _encode_value(value: Any) -> PB2AnyValue:
76+
def _encode_value(
77+
value: Any, allow_null: bool = False
78+
) -> Optional[PB2AnyValue]:
79+
if allow_null is True and value is None:
80+
return None
7681
if isinstance(value, bool):
7782
return PB2AnyValue(bool_value=value)
7883
if isinstance(value, str):
@@ -81,21 +86,49 @@ def _encode_value(value: Any) -> PB2AnyValue:
8186
return PB2AnyValue(int_value=value)
8287
if isinstance(value, float):
8388
return PB2AnyValue(double_value=value)
89+
if isinstance(value, bytes):
90+
return PB2AnyValue(bytes_value=value)
8491
if isinstance(value, Sequence):
8592
return PB2AnyValue(
86-
array_value=PB2ArrayValue(values=[_encode_value(v) for v in value])
93+
array_value=PB2ArrayValue(
94+
values=_encode_array(value, allow_null=allow_null)
95+
)
8796
)
8897
elif isinstance(value, Mapping):
8998
return PB2AnyValue(
9099
kvlist_value=PB2KeyValueList(
91-
values=[_encode_key_value(str(k), v) for k, v in value.items()]
100+
values=[
101+
_encode_key_value(str(k), v, allow_null=allow_null)
102+
for k, v in value.items()
103+
]
92104
)
93105
)
94106
raise Exception(f"Invalid type {type(value)} of value {value}")
95107

96108

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

100133

101134
def _encode_span_id(span_id: int) -> bytes:
@@ -107,14 +140,17 @@ def _encode_trace_id(trace_id: int) -> bytes:
107140

108141

109142
def _encode_attributes(
110-
attributes: Attributes,
143+
attributes: _ExtendedAttributes,
144+
allow_null: bool = False,
111145
) -> Optional[List[PB2KeyValue]]:
112146
if attributes:
113147
pb2_attributes = []
114148
for key, value in attributes.items():
115149
# pylint: disable=broad-exception-caught
116150
try:
117-
pb2_attributes.append(_encode_key_value(key, value))
151+
pb2_attributes.append(
152+
_encode_key_value(key, value, allow_null=allow_null)
153+
)
118154
except Exception as error:
119155
_logger.exception("Failed to encode key %s: %s", key, error)
120156
else:
@@ -145,38 +181,3 @@ def _get_resource_data(
145181
)
146182
)
147183
return resource_data
148-
149-
150-
def _create_exp_backoff_generator(max_value: int = 0) -> Iterator[int]:
151-
"""
152-
Generates an infinite sequence of exponential backoff values. The sequence starts
153-
from 1 (2^0) and doubles each time (2^1, 2^2, 2^3, ...). If a max_value is specified
154-
and non-zero, the generated values will not exceed this maximum, capping at max_value
155-
instead of growing indefinitely.
156-
157-
Parameters:
158-
- max_value (int, optional): The maximum value to yield. If 0 or not provided, the
159-
sequence grows without bound.
160-
161-
Returns:
162-
Iterator[int]: An iterator that yields the exponential backoff values, either uncapped or
163-
capped at max_value.
164-
165-
Example:
166-
```
167-
gen = _create_exp_backoff_generator(max_value=10)
168-
for _ in range(5):
169-
print(next(gen))
170-
```
171-
This will print:
172-
1
173-
2
174-
4
175-
8
176-
10
177-
178-
Note: this functionality used to be handled by the 'backoff' package.
179-
"""
180-
for i in count(0):
181-
out = 2**i
182-
yield min(out, max_value) if max_value else out

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.35.0
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)