[OpenTelemetry] Support Schema URL for resources#7472
Conversation
- Add support for including a schema URL for resources. - Print the schema URL in the console exporter. - Serialize the schema URL in the OTLP exporter. Resolves open-telemetry#6696.
Add PR number.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #7472 +/- ##
==========================================
- Coverage 90.12% 90.11% -0.02%
==========================================
Files 285 285
Lines 15343 15447 +104
==========================================
+ Hits 13828 13920 +92
- Misses 1515 1527 +12
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Pull request overview
This PR adds first-class support for a Resource Schema URL in the SDK layer, including correct merge behavior, and ensures the Schema URL is emitted by the console exporter and OTLP protobuf serializers.
Changes:
- Added
Resource.SchemaUrlplus merge logic consistent with the spec (including a warning on conflicts). - Added public
ResourceBuilder.AddAttributes(..., schemaUrl)overload to allow contributors/detectors to supply a Schema URL. - Propagated Schema URL to console output and OTLP
Resource*messages, with unit + fuzz test coverage.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/OpenTelemetry.Tests/Resources/ResourceTests.cs | Adds unit tests for Schema URL normalization and merge behavior (including conflict warning). |
| test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpTraceExporterTests.cs | Verifies Schema URL flows through provider resource -> OTLP trace export request. |
| test/OpenTelemetry.Exporter.OpenTelemetryProtocol.FuzzTests/ProtobufOtlpTraceSerializerTests.cs | Adds fuzz/property test to ensure trace ResourceSpans Schema URL round-trips. |
| test/OpenTelemetry.Exporter.OpenTelemetryProtocol.FuzzTests/ProtobufOtlpMetricSerializerTests.cs | Adds fuzz/property test to ensure metric ResourceMetrics Schema URL round-trips. |
| test/OpenTelemetry.Exporter.OpenTelemetryProtocol.FuzzTests/ProtobufOtlpLogSerializerTests.cs | Adds fuzz/property test to ensure log ResourceLogs Schema URL round-trips. |
| test/OpenTelemetry.Exporter.OpenTelemetryProtocol.FuzzTests/Generators.cs | Extends resource generator to include Schema URL variants. |
| src/OpenTelemetry/Resources/ResourceBuilderExtensions.cs | Introduces AddAttributes(..., schemaUrl) public overload and docs. |
| src/OpenTelemetry/Resources/Resource.cs | Implements Schema URL storage, normalization, and merge logic with conflict warning. |
| src/OpenTelemetry/Internal/OpenTelemetrySdkEventSource.cs | Adds event for Schema URL merge conflict warning (EventId 59). |
| src/OpenTelemetry/CHANGELOG.md | Adds changelog entry for Resource Schema URL support. |
| src/OpenTelemetry/.publicApi/Stable/PublicAPI.Unshipped.txt | Tracks newly added stable public APIs (constructor, property, extension overload). |
| src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/Serializer/ProtobufOtlpTraceSerializer.cs | Serializes ResourceSpans schema_url when present. |
| src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/Serializer/ProtobufOtlpMetricSerializer.cs | Serializes ResourceMetrics schema_url when present. |
| src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/Serializer/ProtobufOtlpLogSerializer.cs | Serializes ResourceLogs schema_url when present. |
| src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md | Adds OTLP exporter changelog entry for emitting Resource schema URL fields. |
| src/OpenTelemetry.Exporter.Console/ConsoleMetricExporter.cs | Prints Resource Schema URL alongside resource attributes for metrics. |
| src/OpenTelemetry.Exporter.Console/ConsoleLogRecordExporter.cs | Prints Resource Schema URL alongside resource attributes for logs. |
| src/OpenTelemetry.Exporter.Console/ConsoleActivityExporter.cs | Prints Resource Schema URL alongside resource attributes for traces/activities. |
| src/OpenTelemetry.Exporter.Console/CHANGELOG.md | Adds console exporter changelog entry for printing Resource Schema URL. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Return `null` on schema URL merge conflict. - Use `EnvironmentVariableScope` in resource tests.
Also update the event log message for a merge conflict.
| const string OldSchemaUrl = "https://opentelemetry.io/schemas/1.0.0"; | ||
| const string UpdatingSchemaUrl = "https://opentelemetry.io/schemas/1.1.0"; |
There was a problem hiding this comment.
I think that we are missing one test case
const string OldSchemaUrl = "https://opentelemetry.io/schemas/1.0.0";
const string UpdatingSchemaUrl = "https://opentelemetry.io/schemas/1.1.0";
const string UpdatingSchemaUr2l = "https://opentelemetry.io/schemas/1.2.0";
var current = new Resource([], OldSchemaUrl);
var updating = new Resource([], UpdatingSchemaUrl);
var updating2 = new Resource([], UpdatingSchemaUrl2);
var merged = current.Merge(updating).Merge(updating2;
Assert.Null(merged.SchemaUrl);
I do not executed code, but I think it will leads to https://opentelemetry.io/schemas/1.2.0
There was a problem hiding this comment.
I've added a test that shows how it currently works.
There was a problem hiding this comment.
IMO it is bad, typically, you call.
.AddResource1()
.AddResource2()
.AddResource3()
.AddResource4()
Depends on the number of different schemaUrls it can lead to different schemarUrl
There was a problem hiding this comment.
How do we fix that without diverging from the spec?
If they're all different schema URLs every even-numbered resource will cause a conflict and the schema URL will be lost at the end, and every even-numbered resource will "win" because the previous merge lost.
We could do a first or last always wins the merge approach, but that would revert your original suggestion to return null.
There was a problem hiding this comment.
We can keep internal error state, (I think that the Go-lang is doing that). With this we will have consistent behavior.
There was a problem hiding this comment.
Latest change should do that now.
Add missing test.
Make conflict resolution propagate through a chain of resources so that the output is independent of the order and number.
Fixes #6696
Changes
Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changes