Skip to content

Commit

Permalink
Fix: Add missing Resource SchemaURL in otlp exporters (#3652)
Browse files Browse the repository at this point in the history
* fix(otlp-exporter): add missing resource schema url

* test(otlp-exporter): add resource schema url to tests

* chore: update changelog
  • Loading branch information
hirotasoshu committed Feb 10, 2024
1 parent d829e37 commit e98af82
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- Add missing Resource SchemaURL in OTLP exporters
([#3652](https://github.com/open-telemetry/opentelemetry-python/pull/3652))
- Fix loglevel warning text
([#3566](https://github.com/open-telemetry/opentelemetry-python/pull/3566))
- Prometheus Exporter string representation for target_info labels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def _encode_resource_logs(batch: Sequence[LogData]) -> List[ResourceLogs]:
ResourceLogs(
resource=_encode_resource(sdk_resource),
scope_logs=scope_logs,
schema_url=sdk_resource.schema_url,
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ def encode_metrics(data: MetricsData) -> ExportMetricsServiceRequest:
attributes=_encode_attributes(sdk_resource.attributes)
),
scope_metrics=scope_data.values(),
schema_url=sdk_resource.schema_url,
)
)
resource_metrics = resource_data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def _encode_resource_spans(
PB2ResourceSpans(
resource=_encode_resource(sdk_resource),
scope_spans=scope_spans,
schema_url=sdk_resource.schema_url,
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ def _get_sdk_log_data() -> List[LogData]:
severity_text="WARN",
severity_number=SeverityNumber.WARN,
body="Do not go gentle into that good night. Rage, rage against the dying of the light",
resource=SDKResource({"first_resource": "value"}),
resource=SDKResource(
{"first_resource": "value"},
"resource_schema_url",
),
attributes={"a": 1, "b": "c"},
),
instrumentation_scope=InstrumentationScope(
Expand Down Expand Up @@ -124,7 +127,10 @@ def _get_sdk_log_data() -> List[LogData]:
severity_text="INFO",
severity_number=SeverityNumber.INFO,
body="Love is the one thing that transcends time and space",
resource=SDKResource({"first_resource": "value"}),
resource=SDKResource(
{"first_resource": "value"},
"resource_schema_url",
),
attributes={"filename": "model.py", "func_name": "run_method"},
),
instrumentation_scope=InstrumentationScope(
Expand Down Expand Up @@ -206,6 +212,7 @@ def get_test_logs(
],
),
],
schema_url="resource_schema_url",
),
PB2ResourceLogs(
resource=PB2Resource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def test_encode_sum_int(self):
expected = ExportMetricsServiceRequest(
resource_metrics=[
pb2.ResourceMetrics(
schema_url="resource_schema_url",
resource=OTLPResource(
attributes=[
KeyValue(key="a", value=AnyValue(int_value=1)),
Expand Down Expand Up @@ -178,6 +179,7 @@ def test_encode_sum_double(self):
expected = ExportMetricsServiceRequest(
resource_metrics=[
pb2.ResourceMetrics(
schema_url="resource_schema_url",
resource=OTLPResource(
attributes=[
KeyValue(key="a", value=AnyValue(int_value=1)),
Expand Down Expand Up @@ -257,6 +259,7 @@ def test_encode_gauge_int(self):
expected = ExportMetricsServiceRequest(
resource_metrics=[
pb2.ResourceMetrics(
schema_url="resource_schema_url",
resource=OTLPResource(
attributes=[
KeyValue(key="a", value=AnyValue(int_value=1)),
Expand Down Expand Up @@ -333,6 +336,7 @@ def test_encode_gauge_double(self):
expected = ExportMetricsServiceRequest(
resource_metrics=[
pb2.ResourceMetrics(
schema_url="resource_schema_url",
resource=OTLPResource(
attributes=[
KeyValue(key="a", value=AnyValue(int_value=1)),
Expand Down Expand Up @@ -409,6 +413,7 @@ def test_encode_histogram(self):
expected = ExportMetricsServiceRequest(
resource_metrics=[
pb2.ResourceMetrics(
schema_url="resource_schema_url",
resource=OTLPResource(
attributes=[
KeyValue(key="a", value=AnyValue(int_value=1)),
Expand Down Expand Up @@ -511,6 +516,7 @@ def test_encode_multiple_scope_histogram(self):
expected = ExportMetricsServiceRequest(
resource_metrics=[
pb2.ResourceMetrics(
schema_url="resource_schema_url",
resource=OTLPResource(
attributes=[
KeyValue(key="a", value=AnyValue(int_value=1)),
Expand Down Expand Up @@ -739,6 +745,7 @@ def test_encode_exponential_histogram(self):
expected = ExportMetricsServiceRequest(
resource_metrics=[
pb2.ResourceMetrics(
schema_url="resource_schema_url",
resource=OTLPResource(
attributes=[
KeyValue(key="a", value=AnyValue(int_value=1)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def get_exhaustive_otel_span_list() -> List[SDKSpan]:
links=(
SDKLink(context=other_context, attributes={"key_bool": True}),
),
resource=SDKResource({}),
resource=SDKResource({}, "resource_schema_url"),
)
span1.start(start_time=start_times[0])
span1.set_attribute("key_bool", False)
Expand Down Expand Up @@ -143,7 +143,7 @@ def get_exhaustive_otel_span_list() -> List[SDKSpan]:
name="test-span-4",
context=other_context,
parent=None,
resource=SDKResource({}),
resource=SDKResource({}, "resource_schema_url"),
instrumentation_scope=SDKInstrumentationScope(
name="name", version="version"
),
Expand All @@ -163,6 +163,7 @@ def get_exhaustive_test_spans(
pb2_service_request = PB2ExportTraceServiceRequest(
resource_spans=[
PB2ResourceSpans(
schema_url="resource_schema_url",
resource=PB2Resource(),
scope_spans=[
PB2ScopeSpans(
Expand Down

0 comments on commit e98af82

Please sign in to comment.