Skip to content

Commit e98af82

Browse files
authored
Fix: Add missing Resource SchemaURL in otlp exporters (#3652)
* fix(otlp-exporter): add missing resource schema url * test(otlp-exporter): add resource schema url to tests * chore: update changelog
1 parent d829e37 commit e98af82

File tree

7 files changed

+24
-4
lines changed

7 files changed

+24
-4
lines changed

CHANGELOG.md

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

88
## Unreleased
99

10+
- Add missing Resource SchemaURL in OTLP exporters
11+
([#3652](https://github.com/open-telemetry/opentelemetry-python/pull/3652))
1012
- Fix loglevel warning text
1113
([#3566](https://github.com/open-telemetry/opentelemetry-python/pull/3566))
1214
- Prometheus Exporter string representation for target_info labels

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
@@ -77,6 +77,7 @@ def _encode_resource_logs(batch: Sequence[LogData]) -> List[ResourceLogs]:
7777
ResourceLogs(
7878
resource=_encode_resource(sdk_resource),
7979
scope_logs=scope_logs,
80+
schema_url=sdk_resource.schema_url,
8081
)
8182
)
8283

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ def encode_metrics(data: MetricsData) -> ExportMetricsServiceRequest:
312312
attributes=_encode_attributes(sdk_resource.attributes)
313313
),
314314
scope_metrics=scope_data.values(),
315+
schema_url=sdk_resource.schema_url,
315316
)
316317
)
317318
resource_metrics = resource_data

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def _encode_resource_spans(
9797
PB2ResourceSpans(
9898
resource=_encode_resource(sdk_resource),
9999
scope_spans=scope_spans,
100+
schema_url=sdk_resource.schema_url,
100101
)
101102
)
102103

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ def _get_sdk_log_data() -> List[LogData]:
7575
severity_text="WARN",
7676
severity_number=SeverityNumber.WARN,
7777
body="Do not go gentle into that good night. Rage, rage against the dying of the light",
78-
resource=SDKResource({"first_resource": "value"}),
78+
resource=SDKResource(
79+
{"first_resource": "value"},
80+
"resource_schema_url",
81+
),
7982
attributes={"a": 1, "b": "c"},
8083
),
8184
instrumentation_scope=InstrumentationScope(
@@ -124,7 +127,10 @@ def _get_sdk_log_data() -> List[LogData]:
124127
severity_text="INFO",
125128
severity_number=SeverityNumber.INFO,
126129
body="Love is the one thing that transcends time and space",
127-
resource=SDKResource({"first_resource": "value"}),
130+
resource=SDKResource(
131+
{"first_resource": "value"},
132+
"resource_schema_url",
133+
),
128134
attributes={"filename": "model.py", "func_name": "run_method"},
129135
),
130136
instrumentation_scope=InstrumentationScope(
@@ -206,6 +212,7 @@ def get_test_logs(
206212
],
207213
),
208214
],
215+
schema_url="resource_schema_url",
209216
),
210217
PB2ResourceLogs(
211218
resource=PB2Resource(

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def test_encode_sum_int(self):
9999
expected = ExportMetricsServiceRequest(
100100
resource_metrics=[
101101
pb2.ResourceMetrics(
102+
schema_url="resource_schema_url",
102103
resource=OTLPResource(
103104
attributes=[
104105
KeyValue(key="a", value=AnyValue(int_value=1)),
@@ -178,6 +179,7 @@ def test_encode_sum_double(self):
178179
expected = ExportMetricsServiceRequest(
179180
resource_metrics=[
180181
pb2.ResourceMetrics(
182+
schema_url="resource_schema_url",
181183
resource=OTLPResource(
182184
attributes=[
183185
KeyValue(key="a", value=AnyValue(int_value=1)),
@@ -257,6 +259,7 @@ def test_encode_gauge_int(self):
257259
expected = ExportMetricsServiceRequest(
258260
resource_metrics=[
259261
pb2.ResourceMetrics(
262+
schema_url="resource_schema_url",
260263
resource=OTLPResource(
261264
attributes=[
262265
KeyValue(key="a", value=AnyValue(int_value=1)),
@@ -333,6 +336,7 @@ def test_encode_gauge_double(self):
333336
expected = ExportMetricsServiceRequest(
334337
resource_metrics=[
335338
pb2.ResourceMetrics(
339+
schema_url="resource_schema_url",
336340
resource=OTLPResource(
337341
attributes=[
338342
KeyValue(key="a", value=AnyValue(int_value=1)),
@@ -409,6 +413,7 @@ def test_encode_histogram(self):
409413
expected = ExportMetricsServiceRequest(
410414
resource_metrics=[
411415
pb2.ResourceMetrics(
416+
schema_url="resource_schema_url",
412417
resource=OTLPResource(
413418
attributes=[
414419
KeyValue(key="a", value=AnyValue(int_value=1)),
@@ -511,6 +516,7 @@ def test_encode_multiple_scope_histogram(self):
511516
expected = ExportMetricsServiceRequest(
512517
resource_metrics=[
513518
pb2.ResourceMetrics(
519+
schema_url="resource_schema_url",
514520
resource=OTLPResource(
515521
attributes=[
516522
KeyValue(key="a", value=AnyValue(int_value=1)),
@@ -739,6 +745,7 @@ def test_encode_exponential_histogram(self):
739745
expected = ExportMetricsServiceRequest(
740746
resource_metrics=[
741747
pb2.ResourceMetrics(
748+
schema_url="resource_schema_url",
742749
resource=OTLPResource(
743750
attributes=[
744751
KeyValue(key="a", value=AnyValue(int_value=1)),

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def get_exhaustive_otel_span_list() -> List[SDKSpan]:
111111
links=(
112112
SDKLink(context=other_context, attributes={"key_bool": True}),
113113
),
114-
resource=SDKResource({}),
114+
resource=SDKResource({}, "resource_schema_url"),
115115
)
116116
span1.start(start_time=start_times[0])
117117
span1.set_attribute("key_bool", False)
@@ -143,7 +143,7 @@ def get_exhaustive_otel_span_list() -> List[SDKSpan]:
143143
name="test-span-4",
144144
context=other_context,
145145
parent=None,
146-
resource=SDKResource({}),
146+
resource=SDKResource({}, "resource_schema_url"),
147147
instrumentation_scope=SDKInstrumentationScope(
148148
name="name", version="version"
149149
),
@@ -163,6 +163,7 @@ def get_exhaustive_test_spans(
163163
pb2_service_request = PB2ExportTraceServiceRequest(
164164
resource_spans=[
165165
PB2ResourceSpans(
166+
schema_url="resource_schema_url",
166167
resource=PB2Resource(),
167168
scope_spans=[
168169
PB2ScopeSpans(

0 commit comments

Comments
 (0)