Skip to content

chore: decouple opentelemetry-proto from opentelemetry-sdk - #3512

Closed
scottgerring wants to merge 8 commits into
open-telemetry:mainfrom
scottgerring:sgg/proto-decouple
Closed

scottgerring wants to merge 8 commits into
open-telemetry:mainfrom
scottgerring:sgg/proto-decouple

Conversation

@scottgerring

Copy link
Copy Markdown
Member

Summary

This refactors opentelemetry-proto so it only contains generated OTLP protobuf types. The diff is substantial because of the orphan rules - opentelemetry-otlp cannot implement the conversion traits for foreign types into foreign types. My feeling is that we just need to pull off the bandaid here!

The SDK/api-aware transform helpers have been moved into opentelemetry-otlp, where they are used by the exporters. This removes the direct opentelemetry / opentelemetry_sdk dependency from opentelemetry-proto and makes the crate usable by consumers that only need OTLP wire-format types. This will also provide other options to structure changes like #3460 , where we could benefit from having the dependency the other way around (although this is by no means a done deal).

Changes

  • Remove the public opentelemetry_proto::transform module.
  • Move SDK/API → OTLP protobuf transformation logic into a private opentelemetry-otlp::transform module.
  • Update OTLP exporters to use the local transform helpers.
  • Update opentelemetry-proto docs and changelog to describe the crate as generated protobuf types only.

Prior art / related work

This implements the SDK-decoupling part of:

@scottgerring scottgerring assigned lalitb and unassigned lalitb May 11, 2026
@scottgerring
scottgerring requested a review from lalitb May 11, 2026 07:55
@scottgerring

Copy link
Copy Markdown
Member Author

@lalitb I know you've worked on this before; it would be great to get your high-level opinions on this so I can push it in the right direction. I'm not sure if i've missed some important nuance given this has come up a few times but never landed!

@codecov

codecov Bot commented May 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 61.71792% with 361 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.7%. Comparing base (2595432) to head (d25f572).
⚠️ Report is 23 commits behind head on main.

Files with missing lines Patch % Lines
opentelemetry-otlp/src/transform/metrics.rs 9.8% 202 Missing ⚠️
opentelemetry-otlp/src/transform/logs.rs 74.1% 68 Missing ⚠️
opentelemetry-otlp/src/transform/trace.rs 84.7% 50 Missing ⚠️
opentelemetry-otlp/src/transform/common.rs 74.3% 30 Missing ⚠️
opentelemetry-otlp/src/exporter/tonic/metrics.rs 0.0% 3 Missing ⚠️
opentelemetry-otlp/src/exporter/http/logs.rs 0.0% 2 Missing ⚠️
opentelemetry-otlp/src/exporter/http/trace.rs 0.0% 2 Missing ⚠️
opentelemetry-otlp/src/exporter/tonic/logs.rs 0.0% 2 Missing ⚠️
opentelemetry-otlp/src/exporter/tonic/trace.rs 0.0% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main   #3512     +/-   ##
=======================================
- Coverage   84.0%   83.7%   -0.3%     
=======================================
  Files        123     122      -1     
  Lines      30141   29765    -376     
=======================================
- Hits       25328   24942    -386     
- Misses      4813    4823     +10     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@scottgerring
scottgerring force-pushed the sgg/proto-decouple branch 2 times, most recently from 803374d to 4985d5c Compare May 12, 2026 07:07
@scottgerring
scottgerring marked this pull request as ready for review May 12, 2026 07:15
@scottgerring
scottgerring requested a review from a team as a code owner May 12, 2026 07:15

fn set_resource(&mut self, resource: &opentelemetry_sdk::Resource) {
self.resource = resource.into();
self.resource =

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.

More of a style suggestion. But I wonder if it would be better to package this as a extension trait against SDK resource, instead of resource_to_attributes_with_schema function

@scottgerring scottgerring May 26, 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.

@TommyCpp thanks for taking a look, and good point!

I think this conversion is one of the few places where a method-style API could be reasonable, since it’s a high-level boundary used directly by the exporters.

That said, I’m a bit hesitant to make it look like an operation that inherently belongs on Resource: this is really an OTLP/proto-specific projection of a Resource, including how we carry the schema URL alongside attributes. Since we already have a local target type here, From<&Resource> gives us a short call site without adding an extension trait or implying this is a general Resource capability; maybe something like this? -->

Suggested change
self.resource =
self.resource = resource.into();

For the broader transform module I’d probably keep the explicit *_to_proto functions, since most are lower-level implementation details or external-to-external mappings where From isn’t available due to orphan rules.

@github-actions

Copy link
Copy Markdown

Thank you for your contribution! This PR has been automatically marked as stale because it has not had activity in the last 14 days. This may be due to a delay in review on our side or awaiting a response from you; either is fine, and we appreciate your patience.

It will be closed in 14 days if no further activity occurs. Pushing a new commit or leaving a comment will remove the stale label and keep the PR open.

@scottgerring

Copy link
Copy Markdown
Member Author

This isn't stale, it just needs a review :D

@cijothomas

Copy link
Copy Markdown
Member

@lalitb Can you review this one?

@github-actions

Copy link
Copy Markdown

Thank you for your contribution! This PR has been automatically marked as stale because it has not had activity in the last 14 days. This may be due to a delay in review on our side or awaiting a response from you; either is fine, and we appreciate your patience.

It will be closed in 14 days if no further activity occurs. Pushing a new commit or leaving a comment will remove the stale label and keep the PR open.

@github-actions github-actions Bot added Stale and removed Stale labels Jun 25, 2026
@scottgerring

Copy link
Copy Markdown
Member Author

@lalitb do you have time to look at this?

@github-actions

Copy link
Copy Markdown

Thank you for your contribution! This PR has been automatically marked as stale because it has not had activity in the last 14 days. This may be due to a delay in review on our side or awaiting a response from you; either is fine, and we appreciate your patience.

It will be closed in 14 days if no further activity occurs. Pushing a new commit or leaving a comment will remove the stale label and keep the PR open.

@github-actions github-actions Bot added the Stale label Jul 16, 2026
@github-actions

Copy link
Copy Markdown

Closed as inactive. Thank you again for the contribution; please feel free to reopen this PR (or open a new one) if you'd like to continue the work.

@github-actions

Copy link
Copy Markdown

Thank you for your contribution! This PR has been automatically marked as stale because it has not had activity in the last 14 days. This may be due to a delay in review on our side or awaiting a response from you; either is fine, and we appreciate your patience.

It will be closed in 14 days if no further activity occurs. Pushing a new commit or leaving a comment will remove the stale label and keep the PR open.

@github-actions github-actions Bot added the Stale label Aug 20, 2026
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown

Closed as inactive. Thank you again for the contribution; please feel free to reopen this PR (or open a new one) if you'd like to continue the work.

The transform module was copied from opentelemetry-proto before two fixes
landed on main. Port them into the opentelemetry-otlp copy so the move does
not silently regress behaviour:

- trace: group_spans_by_resource_and_scope moves spans into the proto
  conversion instead of cloning every SpanData (open-telemetry#3652).
- logs: group_logs_by_resource_and_scope keys on the full InstrumentationScope
  and exports each scope's own schema_url, so logs sharing a target but
  differing in scope version/attributes/schema are no longer merged.

Adds a regression test for the logs scope-grouping behaviour.
@herin049

herin049 commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

The diff is substantial because of the orphan rules - opentelemetry-otlp cannot implement the conversion traits for foreign types into foreign types. My feeling is that we just need to pull off the bandaid here!

Personally, I like having the conversion traits as convenience. Could we instead define a feature flag (e.g. sdk) under which the conversion traits between SDK types are implemented?

@scottgerring

Copy link
Copy Markdown
Member Author

The diff is substantial because of the orphan rules - opentelemetry-otlp cannot implement the conversion traits for foreign types into foreign types. My feeling is that we just need to pull off the bandaid here!

Personally, I like having the conversion traits as convenience. Could we instead define a feature flag (e.g. sdk) under which the conversion traits between SDK types are implemented?

@herin049 TBH i'd rather fix the relationship between the crates and eat a bit of verbosity on the conversions.
I can see this is useful in some cases, but it doesn't remove the coupling and it adds more configuration complexity for us to carry. There are also situations where we may want to take advantage of the proto defs from the SDK, for instance in #3460

@herin049

herin049 commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

@herin049 TBH i'd rather fix the relationship between the crates and eat a bit of verbosity on the conversions.
I can see this is useful in some cases, but it doesn't remove the coupling and it adds more configuration complexity for us to carry. There are also situations where we may want to take advantage of the proto defs from the SDK, for instance in #3460

Isn't process context an SDK-independent crate? Regardless, I see your point here.

Could we instead invert the dependency and add an optional proto feature into the SDK and bake the conversion trait implementations into an optional portion of the SDK? I don't see too many downsides with this approach, we can always isolate away the conversion logic into a submodule for logical isolation.

@github-actions github-actions Bot removed the Stale label Oct 7, 2026
@scottgerring

scottgerring commented Oct 7, 2026 •

Copy link
Copy Markdown
Member Author

Could we instead invert the dependency and add an optional proto feature into the SDK and bake the conversion trait implementations into an optional portion of the SDK? I don't see too many downsides with this approach, we can always isolate away the conversion logic into a submodule for logical isolation.

I don't think the SDK should depend on a particular wire format crate - the spec is reasonably direct:

The SDK must be clearly separated into wire protocol-independent parts that implement common logic (e.g. batching, tag enrichment by process information, etc.) and protocol-dependent telemetry exporters

My mental model is that the SDK and the proto crate should logically fan in as deps of the OTLP crate; there should be no need for SDK or proto to depend on each other. In this case Rust's orphan rules mean we took a dep yonks ago so we could implement the conversion traits, implicitly accepting a tradeoff for caller sugar which causes pain now. Beyond that, in general with the feature flags we've already got so many that make the build increasingly hard to reason about, I am super hesitant to introduce more.

Could be I'm missing something more here? Do you need the conversion functions for your procCtx purposes, or just the proto? One thing notable with this approach is - previously if you wanted to build something that serialises SDK types to proto types, you didn't need the OTLP crate, now you would. We actually have #3763 open at the moment which would add a new crate to do OTLP file format export, but it seems likely we'll fold that into the existing OTLP crate.

edit: in the interests of not getting bogged down forever on what might be a heavy PR to review, maybe there's a cheap-and-cheerful the way you suggested initially; move the SDK dep behind a non-default flag in the proto crate. I'd personally rather pull the bandaid off, but let's see what the other @open-telemetry/rust-maintainers think

@herin049

herin049 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Could we instead invert the dependency and add an optional proto feature into the SDK and bake the conversion trait implementations into an optional portion of the SDK? I don't see too many downsides with this approach, we can always isolate away the conversion logic into a submodule for logical isolation.

I don't think the SDK should depend on a particular wire format crate - the spec is reasonably direct:

The SDK must be clearly separated into wire protocol-independent parts that implement common logic (e.g. batching, tag enrichment by process information, etc.) and protocol-dependent telemetry exporters

My mental model is that the SDK and the proto crate should logically fan in as deps of the OTLP crate; there should be no need for SDK or proto to depend on each other. In this case Rust's orphan rules mean we took a dep yonks ago so we could implement the conversion traits, implicitly accepting a tradeoff for caller sugar which causes pain now. Beyond that, in general with the feature flags we've already got so many that make the build increasingly hard to reason about, I am super hesitant to introduce more.

Could be I'm missing something more here? Do you need the conversion functions for your procCtx purposes, or just the proto? One thing notable with this approach is - previously if you wanted to build something that serialises SDK types to proto types, you didn't need the OTLP crate, now you would. We actually have #3763 open at the moment which would add a new crate to do OTLP file format export, but it seems likely we'll fold that into the existing OTLP crate.

edit: in the interests of not getting bogged down forever on what might be a heavy PR to review, maybe there's a cheap-and-cheerful the way you suggested initially; move the SDK dep behind a non-default flag in the proto crate. I'd personally rather pull the bandaid off, but let's see what the other @open-telemetry/rust-maintainers think

Apologies if I'm seeming a bit pedantic 😅, was just thinking about alternatives. And no, this isn't needed for the process context work we're doing in Python, I'm just trying to look at this from a Rust user/implementor POV. I just have a strong preference for implementing the std traits when possible since in makes things a bit more ergonomic (in my opinion). I'm sure you and other maintainers have a much better idea of what the best approach is, so I'd be happy with whatever we align on.

@scottgerring

Copy link
Copy Markdown
Member Author

Could we instead invert the dependency and add an optional proto feature into the SDK and bake the conversion trait implementations into an optional portion of the SDK? I don't see too many downsides with this approach, we can always isolate away the conversion logic into a submodule for logical isolation.

I don't think the SDK should depend on a particular wire format crate - the spec is reasonably direct:

The SDK must be clearly separated into wire protocol-independent parts that implement common logic (e.g. batching, tag enrichment by process information, etc.) and protocol-dependent telemetry exporters

My mental model is that the SDK and the proto crate should logically fan in as deps of the OTLP crate; there should be no need for SDK or proto to depend on each other. In this case Rust's orphan rules mean we took a dep yonks ago so we could implement the conversion traits, implicitly accepting a tradeoff for caller sugar which causes pain now. Beyond that, in general with the feature flags we've already got so many that make the build increasingly hard to reason about, I am super hesitant to introduce more.
Could be I'm missing something more here? Do you need the conversion functions for your procCtx purposes, or just the proto? One thing notable with this approach is - previously if you wanted to build something that serialises SDK types to proto types, you didn't need the OTLP crate, now you would. We actually have #3763 open at the moment which would add a new crate to do OTLP file format export, but it seems likely we'll fold that into the existing OTLP crate.
edit: in the interests of not getting bogged down forever on what might be a heavy PR to review, maybe there's a cheap-and-cheerful the way you suggested initially; move the SDK dep behind a non-default flag in the proto crate. I'd personally rather pull the bandaid off, but let's see what the other @open-telemetry/rust-maintainers think

Apologies if I'm seeming a bit pedantic 😅, was just thinking about alternatives. And no, this isn't needed for the process context work we're doing in Python, I'm just trying to look at this from a Rust user/implementor POV. I just have a strong preference for implementing the std traits when possible since in makes things a bit more ergonomic (in my opinion). I'm sure you and other maintainers have a much better idea of what the best approach is, so I'd be happy with whatever we align on.

@herin049 honestly it's good to discuss to work out what's going to suck less 💪 ! I'll try and get opinions from the others so we can turn this around.

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Closed · refreshed 2026-10-27 09:44 UTC

Status above doesn't look right?
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

@opentelemetry-pr-dashboard

This comment has been minimized.

@lalitb

lalitb commented Oct 19, 2026

Copy link
Copy Markdown
Member

+1 on removing proto’s dependency on the SDK and keeping protocol conversion outside the SDK.

Could we keep the conversions public somewhere? Several public projects, including an exporter in contrib, use them to convert SDK data before sending or storing it in their own way. The file exporter in #3763 also uses these conversions for all three signals, so we should coordinate the changes.

One option would be a small, separate conversion crate. The logs and metrics OTLP exporters are already stable, so this would avoid adding proto types and a new conversion API to their public interface. The conversion crate could remain experimental until we are ready to stabilise it.

We could start with one function per signal, returning Export*ServiceRequest, while keeping the grouping helpers and resource wrappers private. The exact API is open for discussion.

If we agree on this direction, we could add the replacement in this PR, or add it first in a separate PR before removing the old conversions. Migration instructions and a note about the removed tracez conversions would also help users.

This is my preference, but I’d like to hear what the other @open-telemetry/rust-maintainers think. Would you prefer this approach, or a different way to keep the conversions available?

@scottgerring

Copy link
Copy Markdown
Member Author

+1 on removing proto’s dependency on the SDK and keeping protocol conversion outside the SDK.

Could we keep the conversions public somewhere? Several public projects, including an exporter in contrib, use them to convert SDK data before sending or storing it in their own way. The file exporter in #3763 also uses these conversions for all three signals, so we should coordinate the changes.

One option would be a small, separate conversion crate. The logs and metrics OTLP exporters are already stable, so this would avoid adding proto types and a new conversion API to their public interface. The conversion crate could remain experimental until we are ready to stabilise it.

We could start with one function per signal, returning Export*ServiceRequest, while keeping the grouping helpers and resource wrappers private. The exact API is open for discussion.

If we agree on this direction, we could add the replacement in this PR, or add it first in a separate PR before removing the old conversions. Migration instructions and a note about the removed tracez conversions would also help users.

This is my preference, but I’d like to hear what the other @open-telemetry/rust-maintainers think. Would you prefer this approach, or a different way to keep the conversions available?

@lalitb so I reckon we're aligned on breaking the dep and accepting free functions, and tbh if you're happy to add another crate just for this i'd be happy too as this will let us preserve the conversions for other users as you say.

@herin049 as you started us down this path again, will this work for you all over in python land? I'm happy to throw this up quickly, but also happy to step out of the way if you are feeling enthusiastic; I know we are blocking you here.

@herin049

herin049 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

+1 on removing proto’s dependency on the SDK and keeping protocol conversion outside the SDK.
Could we keep the conversions public somewhere? Several public projects, including an exporter in contrib, use them to convert SDK data before sending or storing it in their own way. The file exporter in #3763 also uses these conversions for all three signals, so we should coordinate the changes.
One option would be a small, separate conversion crate. The logs and metrics OTLP exporters are already stable, so this would avoid adding proto types and a new conversion API to their public interface. The conversion crate could remain experimental until we are ready to stabilise it.
We could start with one function per signal, returning Export*ServiceRequest, while keeping the grouping helpers and resource wrappers private. The exact API is open for discussion.
If we agree on this direction, we could add the replacement in this PR, or add it first in a separate PR before removing the old conversions. Migration instructions and a note about the removed tracez conversions would also help users.
This is my preference, but I’d like to hear what the other @open-telemetry/rust-maintainers think. Would you prefer this approach, or a different way to keep the conversions available?

@lalitb so I reckon we're aligned on breaking the dep and accepting free functions, and tbh if you're happy to add another crate just for this i'd be happy too as this will let us preserve the conversions for other users as you say.

@herin049 as you started us down this path again, will this work for you all over in python land? I'm happy to throw this up quickly, but also happy to step out of the way if you are feeling enthusiastic; I know we are blocking you here.

This sounds great, it's actually almost exactly what we do in Python

I know we are blocking you here.

Definitely not blocking, feel free to take your time here!

@opentelemetry-pr-dashboard

This comment has been minimized.

@scottgerring

Copy link
Copy Markdown
Member Author

Closing this in favour of #3824 which takes the approach agreed on above - introducing a conversion crate. Just a draft for now but i'll have some time to polish it this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants