Skip to content

Commit f296239

Browse files
authored
Merge branch 'main' into main
2 parents f72d854 + adbcf82 commit f296239

File tree

47 files changed

+678
-712
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+678
-712
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ env:
1010
# Otherwise, set variable to the commit of your branch on
1111
# opentelemetry-python-contrib which is compatible with these Core repo
1212
# changes.
13-
CONTRIB_REPO_SHA: 2edd017c22edb4896e182c934bc199d716495ce6
13+
CONTRIB_REPO_SHA: a5ed4da478c4360fd6e24893f7574b150431b7ee
1414
# This is needed because we do not clone the core repo in contrib builds anymore.
1515
# When running contrib builds as part of core builds, we use actions/checkout@v2 which
1616
# does not set an environment variable (simply just runs tox), which is different when

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,22 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## Unreleased
9+
910
- Use BoundedAttributes instead of raw dict to extract attributes from LogRecord and Support dropped_attributes_count in LogRecord ([#3310](https://github.com/open-telemetry/opentelemetry-python/pull/3310))
1011
- Update the body type in the log
1112
([$3343](https://github.com/open-telemetry/opentelemetry-python/pull/3343))
13+
- Add max_scale option to Exponential Bucket Histogram Aggregation
14+
([#3323](https://github.com/open-telemetry/opentelemetry-python/pull/3323))
15+
- Use BoundedAttributes instead of raw dict to extract attributes from LogRecord
16+
([#3310](https://github.com/open-telemetry/opentelemetry-python/pull/3310))
17+
- Support dropped_attributes_count in LogRecord and exporters
18+
([#3351](https://github.com/open-telemetry/opentelemetry-python/pull/3351))
19+
- Add unit to view instrument selection criteria
20+
([#3341](https://github.com/open-telemetry/opentelemetry-python/pull/3341))
21+
- Upgrade opentelemetry-proto to 0.20 and regen
22+
[#3355](https://github.com/open-telemetry/opentelemetry-python/pull/3355))
23+
24+
1225
## Version 1.18.0/0.39b0 (2023-05-04)
1326

1427
- Select histogram aggregation with an environment variable
@@ -26,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2639
- Add speced out environment variables and arguments for BatchLogRecordProcessor
2740
([#3237](https://github.com/open-telemetry/opentelemetry-python/pull/3237))
2841

42+
2943
## Version 1.17.0/0.38b0 (2023-03-22)
3044

3145
- Implement LowMemory temporality

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ Approvers ([@open-telemetry/python-approvers](https://github.com/orgs/open-telem
101101
- [Aaron Abbott](https://github.com/aabmass), Google
102102
- [Jeremy Voss](https://github.com/jeremydvoss), Microsoft
103103
- [Sanket Mehta](https://github.com/sanketmehta28), Cisco
104+
- [Shalev Roda](https://github.com/shalevr), Cisco
104105

105106
Emeritus Approvers
106107

dev-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ mypy-protobuf~=3.0.0
2222
markupsafe==2.0.1
2323
bleach==4.1.0 # This dependency was updated to a breaking version.
2424
codespell==2.1.0
25-
requests==2.28.1
25+
requests==2.31.0
2626
ruamel.yaml==0.17.21

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def _encode_log(log_data: LogData) -> PB2LogRecord:
4747
body=_encode_value(log_data.log_record.body),
4848
severity_text=log_data.log_record.severity_text,
4949
attributes=_encode_attributes(log_data.log_record.attributes),
50+
dropped_attributes_count=log_data.log_record.dropped_attributes,
5051
severity_number=log_data.log_record.severity_number.value,
5152
)
5253

exporter/opentelemetry-exporter-otlp-proto-common/tests/test_log_encoder.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from opentelemetry.proto.resource.v1.resource_pb2 import (
4040
Resource as PB2Resource,
4141
)
42-
from opentelemetry.sdk._logs import LogData
42+
from opentelemetry.sdk._logs import LogData, LogLimits
4343
from opentelemetry.sdk._logs import LogRecord as SDKLogRecord
4444
from opentelemetry.sdk.resources import Resource as SDKResource
4545
from opentelemetry.sdk.util.instrumentation import InstrumentationScope
@@ -51,6 +51,19 @@ def test_encode(self):
5151
sdk_logs, expected_encoding = self.get_test_logs()
5252
self.assertEqual(encode_logs(sdk_logs), expected_encoding)
5353

54+
def test_dropped_attributes_count(self):
55+
sdk_logs = self._get_test_logs_dropped_attributes()
56+
encoded_logs = encode_logs(sdk_logs)
57+
self.assertTrue(hasattr(sdk_logs[0].log_record, "dropped_attributes"))
58+
self.assertEqual(
59+
# pylint:disable=no-member
60+
encoded_logs.resource_logs[0]
61+
.scope_logs[0]
62+
.log_records[0]
63+
.dropped_attributes_count,
64+
2,
65+
)
66+
5467
@staticmethod
5568
def _get_sdk_log_data() -> List[LogData]:
5669
log1 = LogData(
@@ -251,3 +264,42 @@ def get_test_logs(
251264
)
252265

253266
return sdk_logs, pb2_service_request
267+
268+
@staticmethod
269+
def _get_test_logs_dropped_attributes() -> List[LogData]:
270+
log1 = LogData(
271+
log_record=SDKLogRecord(
272+
timestamp=1644650195189786880,
273+
trace_id=89564621134313219400156819398935297684,
274+
span_id=1312458408527513268,
275+
trace_flags=TraceFlags(0x01),
276+
severity_text="WARN",
277+
severity_number=SeverityNumber.WARN,
278+
body="Do not go gentle into that good night. Rage, rage against the dying of the light",
279+
resource=SDKResource({"first_resource": "value"}),
280+
attributes={"a": 1, "b": "c", "user_id": "B121092"},
281+
limits=LogLimits(max_attributes=1),
282+
),
283+
instrumentation_scope=InstrumentationScope(
284+
"first_name", "first_version"
285+
),
286+
)
287+
288+
log2 = LogData(
289+
log_record=SDKLogRecord(
290+
timestamp=1644650249738562048,
291+
trace_id=0,
292+
span_id=0,
293+
trace_flags=TraceFlags.DEFAULT,
294+
severity_text="WARN",
295+
severity_number=SeverityNumber.WARN,
296+
body="Cooper, this is no time for caution!",
297+
resource=SDKResource({"second_resource": "CASE"}),
298+
attributes={},
299+
),
300+
instrumentation_scope=InstrumentationScope(
301+
"second_name", "second_version"
302+
),
303+
)
304+
305+
return [log1, log2]

exporter/opentelemetry-exporter-otlp-proto-common/tests/test_metrics_encoder.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,6 @@ def test_encode_histogram(self):
451451
bucket_counts=[1, 4],
452452
explicit_bounds=[10.0, 20.0],
453453
exemplars=[],
454-
flags=pb2.DataPointFlags.FLAG_NONE,
455454
max=18.0,
456455
min=8.0,
457456
)
@@ -554,7 +553,6 @@ def test_encode_multiple_scope_histogram(self):
554553
bucket_counts=[1, 4],
555554
explicit_bounds=[10.0, 20.0],
556555
exemplars=[],
557-
flags=pb2.DataPointFlags.FLAG_NONE,
558556
max=18.0,
559557
min=8.0,
560558
)
@@ -590,7 +588,6 @@ def test_encode_multiple_scope_histogram(self):
590588
bucket_counts=[1, 4],
591589
explicit_bounds=[10.0, 20.0],
592590
exemplars=[],
593-
flags=pb2.DataPointFlags.FLAG_NONE,
594591
max=18.0,
595592
min=8.0,
596593
)
@@ -633,7 +630,6 @@ def test_encode_multiple_scope_histogram(self):
633630
bucket_counts=[1, 4],
634631
explicit_bounds=[10.0, 20.0],
635632
exemplars=[],
636-
flags=pb2.DataPointFlags.FLAG_NONE,
637633
max=18.0,
638634
min=8.0,
639635
)
@@ -676,7 +672,6 @@ def test_encode_multiple_scope_histogram(self):
676672
bucket_counts=[1, 4],
677673
explicit_bounds=[10.0, 20.0],
678674
exemplars=[],
679-
flags=pb2.DataPointFlags.FLAG_NONE,
680675
max=18.0,
681676
min=8.0,
682677
)

exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,12 @@ def _translate_data(
107107
def export(self, batch: Sequence[LogData]) -> LogExportResult:
108108
return self._export(batch)
109109

110-
def shutdown(self) -> None:
111-
pass
110+
def shutdown(self, timeout_millis: float = 30_000, **kwargs) -> None:
111+
OTLPExporterMixin.shutdown(self, timeout_millis=timeout_millis)
112+
113+
def force_flush(self, timeout_millis: float = 10_000) -> bool:
114+
"""Nothing is buffered in this exporter, so this method does nothing."""
115+
return True
112116

113117
@property
114118
def _exporting(self) -> str:

exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,20 @@
1616

1717
import threading
1818
from abc import ABC, abstractmethod
19-
from collections.abc import Sequence
19+
from collections.abc import Sequence # noqa: F401
2020
from logging import getLogger
2121
from os import environ
2222
from time import sleep
23-
from typing import Any, Callable, Dict, Generic, List, Optional, Tuple, Union
23+
from typing import ( # noqa: F401
24+
Any,
25+
Callable,
26+
Dict,
27+
Generic,
28+
List,
29+
Optional,
30+
Tuple,
31+
Union,
32+
)
2433
from typing import Sequence as TypingSequence
2534
from typing import TypeVar
2635
from urllib.parse import urlparse
@@ -45,7 +54,7 @@
4554
from opentelemetry.exporter.otlp.proto.grpc import (
4655
_OTLP_GRPC_HEADERS,
4756
)
48-
from opentelemetry.proto.common.v1.common_pb2 import (
57+
from opentelemetry.proto.common.v1.common_pb2 import ( # noqa: F401
4958
AnyValue,
5059
ArrayValue,
5160
KeyValue,
@@ -97,44 +106,6 @@ def environ_to_compression(environ_key: str) -> Optional[Compression]:
97106
return _ENVIRON_TO_COMPRESSION[environ_value]
98107

99108

100-
def _translate_value(value: Any) -> KeyValue:
101-
if isinstance(value, bool):
102-
any_value = AnyValue(bool_value=value)
103-
104-
elif isinstance(value, str):
105-
any_value = AnyValue(string_value=value)
106-
107-
elif isinstance(value, int):
108-
any_value = AnyValue(int_value=value)
109-
110-
elif isinstance(value, float):
111-
any_value = AnyValue(double_value=value)
112-
113-
elif isinstance(value, Sequence):
114-
any_value = AnyValue(
115-
array_value=ArrayValue(values=[_translate_value(v) for v in value])
116-
)
117-
118-
# Tracing specs currently does not support Mapping type attributes
119-
# elif isinstance(value, Mapping):
120-
# any_value = AnyValue(
121-
# kvlist_value=KeyValueList(
122-
# values=[
123-
# _translate_key_values(str(k), v) for k, v in value.items()
124-
# ]
125-
# )
126-
# )
127-
128-
else:
129-
raise Exception(f"Invalid type {type(value)} of value {value}")
130-
131-
return any_value
132-
133-
134-
def _translate_key_values(key: str, value: Any) -> KeyValue:
135-
return KeyValue(key=key, value=_translate_value(value))
136-
137-
138109
@deprecated(
139110
version="1.18.0",
140111
reason="Use one of the encoders from opentelemetry-exporter-otlp-proto-common instead",
@@ -271,17 +242,6 @@ def _translate_data(
271242
) -> ExportServiceRequestT:
272243
pass
273244

274-
def _translate_attributes(self, attributes) -> TypingSequence[KeyValue]:
275-
output = []
276-
if attributes:
277-
278-
for key, value in attributes.items():
279-
try:
280-
output.append(_translate_key_values(key, value))
281-
except Exception as error: # pylint: disable=broad-except
282-
logger.exception(error)
283-
return output
284-
285245
def _export(
286246
self, data: Union[TypingSequence[ReadableSpan], MetricsData]
287247
) -> ExportResultT:

exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,5 @@ def _exporting(self) -> str:
258258
return "metrics"
259259

260260
def force_flush(self, timeout_millis: float = 10_000) -> bool:
261+
"""Nothing is buffered in this exporter, so this method does nothing."""
261262
return True

0 commit comments

Comments
 (0)