Skip to content

Commit c879fa6

Browse files
authored
Merge branch 'main' into 2024/add/tokenTyping
2 parents 0717c70 + 8e3c7d2 commit c879fa6

File tree

8 files changed

+349
-17
lines changed

8 files changed

+349
-17
lines changed

CHANGELOG.md

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

1010
- Add type annotations to context's attach & detach
1111
([#4346](https://github.com/open-telemetry/opentelemetry-python/pull/4346))
12+
- Fix OTLP encoders missing instrumentation scope schema url and attributes
13+
([#4359](https://github.com/open-telemetry/opentelemetry-python/pull/4359))
1214
- prometheus-exporter: fix labels out of place for data points with different
1315
attribute sets
1416
([#4413](https://github.com/open-telemetry/opentelemetry-python/pull/4413))

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def _encode_instrumentation_scope(
6161
return PB2InstrumentationScope(
6262
name=instrumentation_scope.name,
6363
version=instrumentation_scope.version,
64+
attributes=_encode_attributes(instrumentation_scope.attributes),
6465
)
6566

6667

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ def _encode_resource_logs(batch: Sequence[LogData]) -> List[ResourceLogs]:
8282
ScopeLogs(
8383
scope=(_encode_instrumentation_scope(sdk_instrumentation)),
8484
log_records=pb2_logs,
85+
schema_url=sdk_instrumentation.schema_url
86+
if sdk_instrumentation
87+
else None,
8588
)
8689
)
8790
pb2_resource_logs.append(

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717

1818
from opentelemetry.exporter.otlp.proto.common._internal import (
1919
_encode_attributes,
20+
_encode_instrumentation_scope,
2021
_encode_span_id,
2122
_encode_trace_id,
2223
)
2324
from opentelemetry.proto.collector.metrics.v1.metrics_service_pb2 import (
2425
ExportMetricsServiceRequest,
2526
)
26-
from opentelemetry.proto.common.v1.common_pb2 import InstrumentationScope
2727
from opentelemetry.proto.metrics.v1 import metrics_pb2 as pb2
2828
from opentelemetry.proto.resource.v1.resource_pb2 import (
2929
Resource as PB2Resource,
@@ -219,10 +219,8 @@ def _encode_resource_metrics(resource_metrics, resource_metrics_dict):
219219
# there is no need to check for existing instrumentation scopes
220220
# here.
221221
pb2_scope_metrics = pb2.ScopeMetrics(
222-
scope=InstrumentationScope(
223-
name=instrumentation_scope.name,
224-
version=instrumentation_scope.version,
225-
)
222+
scope=_encode_instrumentation_scope(instrumentation_scope),
223+
schema_url=instrumentation_scope.schema_url,
226224
)
227225

228226
scope_metrics_dict[instrumentation_scope] = pb2_scope_metrics

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ def _encode_resource_spans(
8989
PB2ScopeSpans(
9090
scope=(_encode_instrumentation_scope(sdk_instrumentation)),
9191
spans=pb2_spans,
92+
schema_url=sdk_instrumentation.schema_url
93+
if sdk_instrumentation
94+
else None,
9295
)
9396
)
9497
pb2_resource_spans.append(

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

Lines changed: 113 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,54 @@ def _get_sdk_log_data() -> List[LogData]:
178178
),
179179
)
180180

181-
return [log1, log2, log3, log4, log5]
181+
log6 = LogData(
182+
log_record=SDKLogRecord(
183+
timestamp=1644650584292683022,
184+
observed_timestamp=1644650584292683022,
185+
trace_id=212592107417388365804938480559624925522,
186+
span_id=6077757853989569222,
187+
trace_flags=TraceFlags(0x01),
188+
severity_text="ERROR",
189+
severity_number=SeverityNumber.ERROR,
190+
body="This instrumentation scope has a schema url",
191+
resource=SDKResource(
192+
{"first_resource": "value"},
193+
"resource_schema_url",
194+
),
195+
attributes={"filename": "model.py", "func_name": "run_method"},
196+
),
197+
instrumentation_scope=InstrumentationScope(
198+
"scope_with_url",
199+
"scope_with_url_version",
200+
"instrumentation_schema_url",
201+
),
202+
)
203+
204+
log7 = LogData(
205+
log_record=SDKLogRecord(
206+
timestamp=1644650584292683033,
207+
observed_timestamp=1644650584292683033,
208+
trace_id=212592107417388365804938480559624925533,
209+
span_id=6077757853989569233,
210+
trace_flags=TraceFlags(0x01),
211+
severity_text="FATAL",
212+
severity_number=SeverityNumber.FATAL,
213+
body="This instrumentation scope has a schema url and attributes",
214+
resource=SDKResource(
215+
{"first_resource": "value"},
216+
"resource_schema_url",
217+
),
218+
attributes={"filename": "model.py", "func_name": "run_method"},
219+
),
220+
instrumentation_scope=InstrumentationScope(
221+
"scope_with_attributes",
222+
"scope_with_attributes_version",
223+
"instrumentation_schema_url",
224+
{"one": 1, "two": "2"},
225+
),
226+
)
227+
228+
return [log1, log2, log3, log4, log5, log6, log7]
182229

183230
def get_test_logs(
184231
self,
@@ -253,6 +300,71 @@ def get_test_logs(
253300
)
254301
],
255302
),
303+
PB2ScopeLogs(
304+
scope=PB2InstrumentationScope(
305+
name="scope_with_url",
306+
version="scope_with_url_version",
307+
),
308+
schema_url="instrumentation_schema_url",
309+
log_records=[
310+
PB2LogRecord(
311+
time_unix_nano=1644650584292683022,
312+
observed_time_unix_nano=1644650584292683022,
313+
trace_id=_encode_trace_id(
314+
212592107417388365804938480559624925522
315+
),
316+
span_id=_encode_span_id(
317+
6077757853989569222
318+
),
319+
flags=int(TraceFlags(0x01)),
320+
severity_text="ERROR",
321+
severity_number=SeverityNumber.ERROR.value,
322+
body=_encode_value(
323+
"This instrumentation scope has a schema url"
324+
),
325+
attributes=_encode_attributes(
326+
{
327+
"filename": "model.py",
328+
"func_name": "run_method",
329+
}
330+
),
331+
)
332+
],
333+
),
334+
PB2ScopeLogs(
335+
scope=PB2InstrumentationScope(
336+
name="scope_with_attributes",
337+
version="scope_with_attributes_version",
338+
attributes=_encode_attributes(
339+
{"one": 1, "two": "2"}
340+
),
341+
),
342+
schema_url="instrumentation_schema_url",
343+
log_records=[
344+
PB2LogRecord(
345+
time_unix_nano=1644650584292683033,
346+
observed_time_unix_nano=1644650584292683033,
347+
trace_id=_encode_trace_id(
348+
212592107417388365804938480559624925533
349+
),
350+
span_id=_encode_span_id(
351+
6077757853989569233
352+
),
353+
flags=int(TraceFlags(0x01)),
354+
severity_text="FATAL",
355+
severity_number=SeverityNumber.FATAL.value,
356+
body=_encode_value(
357+
"This instrumentation scope has a schema url and attributes"
358+
),
359+
attributes=_encode_attributes(
360+
{
361+
"filename": "model.py",
362+
"func_name": "run_method",
363+
}
364+
),
365+
)
366+
],
367+
),
256368
],
257369
schema_url="resource_schema_url",
258370
),

0 commit comments

Comments
 (0)