Skip to content

[OpenTelemetry] Support Schema URL for resources#7472

Merged
martincostello merged 6 commits into
open-telemetry:mainfrom
martincostello:gh-6696
Jul 1, 2026
Merged

[OpenTelemetry] Support Schema URL for resources#7472
martincostello merged 6 commits into
open-telemetry:mainfrom
martincostello:gh-6696

Conversation

@martincostello

Copy link
Copy Markdown
Member

Fixes #6696

Changes

  • 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.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

- 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.
@github-actions github-actions Bot added pkg:OpenTelemetry.Exporter.Console Issues related to OpenTelemetry.Exporter.Console NuGet package pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package labels Jun 30, 2026
Comment thread src/OpenTelemetry.Exporter.Console/CHANGELOG.md Outdated
Comment thread src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md Outdated
Comment thread src/OpenTelemetry/CHANGELOG.md Outdated
@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.11%. Comparing base (2d50a2b) to head (9a9c0ad).
⚠️ Report is 9 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...emetry.Exporter.Console/ConsoleActivityExporter.cs 50.00% 1 Missing ⚠️
...metry.Exporter.Console/ConsoleLogRecordExporter.cs 50.00% 1 Missing ⚠️
...elemetry.Exporter.Console/ConsoleMetricExporter.cs 50.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            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     
Flag Coverage Δ
unittests-Project-Experimental 89.98% <91.66%> (-0.14%) ⬇️
unittests-Project-Stable 90.01% <91.66%> (-0.13%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ementation/Serializer/ProtobufOtlpLogSerializer.cs 98.52% <100.00%> (+0.02%) ⬆️
...ntation/Serializer/ProtobufOtlpMetricSerializer.cs 99.02% <100.00%> (+<0.01%) ⬆️
...entation/Serializer/ProtobufOtlpTraceSerializer.cs 95.07% <100.00%> (+0.03%) ⬆️
...nTelemetry/Internal/OpenTelemetrySdkEventSource.cs 67.34% <100.00%> (+0.33%) ⬆️
src/OpenTelemetry/Resources/Resource.cs 96.77% <100.00%> (+1.53%) ⬆️
...enTelemetry/Resources/ResourceBuilderExtensions.cs 100.00% <100.00%> (ø)
...emetry.Exporter.Console/ConsoleActivityExporter.cs 91.42% <50.00%> (-1.22%) ⬇️
...metry.Exporter.Console/ConsoleLogRecordExporter.cs 95.83% <50.00%> (-1.31%) ⬇️
...elemetry.Exporter.Console/ConsoleMetricExporter.cs 74.45% <50.00%> (-0.37%) ⬇️

... and 2 files with indirect coverage changes

@martincostello
martincostello marked this pull request as ready for review June 30, 2026 16:25
@martincostello
martincostello requested a review from a team as a code owner June 30, 2026 16:25
Copilot AI review requested due to automatic review settings June 30, 2026 16:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.SchemaUrl plus 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.

Comment thread src/OpenTelemetry/.publicApi/Stable/PublicAPI.Unshipped.txt
Comment thread src/OpenTelemetry/.publicApi/Stable/PublicAPI.Unshipped.txt
Comment thread src/OpenTelemetry/Resources/Resource.cs
- Return `null` on schema URL merge conflict.
- Use `EnvironmentVariableScope` in resource tests.
Comment thread src/OpenTelemetry/Internal/OpenTelemetrySdkEventSource.cs Outdated
Also update the event log message for a merge conflict.
Comment on lines +466 to +467
const string OldSchemaUrl = "https://opentelemetry.io/schemas/1.0.0";
const string UpdatingSchemaUrl = "https://opentelemetry.io/schemas/1.1.0";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a test that shows how it currently works.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it is bad, typically, you call.

.AddResource1()
.AddResource2()
.AddResource3()
.AddResource4()

Depends on the number of different schemaUrls it can lead to different schemarUrl

@martincostello martincostello Jul 1, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can keep internal error state, (I think that the Go-lang is doing that). With this we will have consistent behavior.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latest change should do that now.

Make conflict resolution propagate through a chain of resources so that the output is independent of the order and number.

@Kielek Kielek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@martincostello
martincostello requested a review from alanwest July 1, 2026 16:44
@martincostello
martincostello added this pull request to the merge queue Jul 1, 2026
Merged via the queue into open-telemetry:main with commit 87cf4fd Jul 1, 2026
75 checks passed
@martincostello
martincostello deleted the gh-6696 branch July 1, 2026 19:25
This was referenced Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:OpenTelemetry.Exporter.Console Issues related to OpenTelemetry.Exporter.Console NuGet package pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature request] schema url for resources

4 participants