Skip to content

Commit

Permalink
Merge branch 'main' into fix-error-message-format
Browse files Browse the repository at this point in the history
  • Loading branch information
xrmx authored Mar 3, 2025
2 parents dd92fcb + b61622d commit 4296243
Show file tree
Hide file tree
Showing 13 changed files with 373 additions and 26 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- Add type annotations to context's attach & detach
([#4346](https://github.com/open-telemetry/opentelemetry-python/pull/4346))
- Fix OTLP encoders missing instrumentation scope schema url and attributes
([#4359](https://github.com/open-telemetry/opentelemetry-python/pull/4359))
- prometheus-exporter: fix labels out of place for data points with different
attribute sets
([#4413](https://github.com/open-telemetry/opentelemetry-python/pull/4413))
Expand Down
4 changes: 4 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@
"py:class",
"opentelemetry.sdk.metrics._internal.aggregation._Aggregation",
),
(
"py:class",
"_contextvars.Token",
),
]

# Add any paths that contain templates here, relative to this directory.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def _encode_instrumentation_scope(
return PB2InstrumentationScope(
name=instrumentation_scope.name,
version=instrumentation_scope.version,
attributes=_encode_attributes(instrumentation_scope.attributes),
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ def _encode_resource_logs(batch: Sequence[LogData]) -> List[ResourceLogs]:
ScopeLogs(
scope=(_encode_instrumentation_scope(sdk_instrumentation)),
log_records=pb2_logs,
schema_url=sdk_instrumentation.schema_url
if sdk_instrumentation
else None,
)
)
pb2_resource_logs.append(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

from opentelemetry.exporter.otlp.proto.common._internal import (
_encode_attributes,
_encode_instrumentation_scope,
_encode_span_id,
_encode_trace_id,
)
from opentelemetry.proto.collector.metrics.v1.metrics_service_pb2 import (
ExportMetricsServiceRequest,
)
from opentelemetry.proto.common.v1.common_pb2 import InstrumentationScope
from opentelemetry.proto.metrics.v1 import metrics_pb2 as pb2
from opentelemetry.proto.resource.v1.resource_pb2 import (
Resource as PB2Resource,
Expand Down Expand Up @@ -219,10 +219,8 @@ def _encode_resource_metrics(resource_metrics, resource_metrics_dict):
# there is no need to check for existing instrumentation scopes
# here.
pb2_scope_metrics = pb2.ScopeMetrics(
scope=InstrumentationScope(
name=instrumentation_scope.name,
version=instrumentation_scope.version,
)
scope=_encode_instrumentation_scope(instrumentation_scope),
schema_url=instrumentation_scope.schema_url,
)

scope_metrics_dict[instrumentation_scope] = pb2_scope_metrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ def _encode_resource_spans(
PB2ScopeSpans(
scope=(_encode_instrumentation_scope(sdk_instrumentation)),
spans=pb2_spans,
schema_url=sdk_instrumentation.schema_url
if sdk_instrumentation
else None,
)
)
pb2_resource_spans.append(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,54 @@ def _get_sdk_log_data() -> List[LogData]:
),
)

return [log1, log2, log3, log4, log5]
log6 = LogData(
log_record=SDKLogRecord(
timestamp=1644650584292683022,
observed_timestamp=1644650584292683022,
trace_id=212592107417388365804938480559624925522,
span_id=6077757853989569222,
trace_flags=TraceFlags(0x01),
severity_text="ERROR",
severity_number=SeverityNumber.ERROR,
body="This instrumentation scope has a schema url",
resource=SDKResource(
{"first_resource": "value"},
"resource_schema_url",
),
attributes={"filename": "model.py", "func_name": "run_method"},
),
instrumentation_scope=InstrumentationScope(
"scope_with_url",
"scope_with_url_version",
"instrumentation_schema_url",
),
)

log7 = LogData(
log_record=SDKLogRecord(
timestamp=1644650584292683033,
observed_timestamp=1644650584292683033,
trace_id=212592107417388365804938480559624925533,
span_id=6077757853989569233,
trace_flags=TraceFlags(0x01),
severity_text="FATAL",
severity_number=SeverityNumber.FATAL,
body="This instrumentation scope has a schema url and attributes",
resource=SDKResource(
{"first_resource": "value"},
"resource_schema_url",
),
attributes={"filename": "model.py", "func_name": "run_method"},
),
instrumentation_scope=InstrumentationScope(
"scope_with_attributes",
"scope_with_attributes_version",
"instrumentation_schema_url",
{"one": 1, "two": "2"},
),
)

return [log1, log2, log3, log4, log5, log6, log7]

def get_test_logs(
self,
Expand Down Expand Up @@ -253,6 +300,71 @@ def get_test_logs(
)
],
),
PB2ScopeLogs(
scope=PB2InstrumentationScope(
name="scope_with_url",
version="scope_with_url_version",
),
schema_url="instrumentation_schema_url",
log_records=[
PB2LogRecord(
time_unix_nano=1644650584292683022,
observed_time_unix_nano=1644650584292683022,
trace_id=_encode_trace_id(
212592107417388365804938480559624925522
),
span_id=_encode_span_id(
6077757853989569222
),
flags=int(TraceFlags(0x01)),
severity_text="ERROR",
severity_number=SeverityNumber.ERROR.value,
body=_encode_value(
"This instrumentation scope has a schema url"
),
attributes=_encode_attributes(
{
"filename": "model.py",
"func_name": "run_method",
}
),
)
],
),
PB2ScopeLogs(
scope=PB2InstrumentationScope(
name="scope_with_attributes",
version="scope_with_attributes_version",
attributes=_encode_attributes(
{"one": 1, "two": "2"}
),
),
schema_url="instrumentation_schema_url",
log_records=[
PB2LogRecord(
time_unix_nano=1644650584292683033,
observed_time_unix_nano=1644650584292683033,
trace_id=_encode_trace_id(
212592107417388365804938480559624925533
),
span_id=_encode_span_id(
6077757853989569233
),
flags=int(TraceFlags(0x01)),
severity_text="FATAL",
severity_number=SeverityNumber.FATAL.value,
body=_encode_value(
"This instrumentation scope has a schema url and attributes"
),
attributes=_encode_attributes(
{
"filename": "model.py",
"func_name": "run_method",
}
),
)
],
),
],
schema_url="resource_schema_url",
),
Expand Down
Loading

0 comments on commit 4296243

Please sign in to comment.