Skip to content

fix(proto): preserve InstrumentationScope version and attributes#3332

Open
djvcom wants to merge 7 commits intoopen-telemetry:mainfrom
djvcom:fix/preserve-instrumentation-scope-metadata
Open

fix(proto): preserve InstrumentationScope version and attributes#3332
djvcom wants to merge 7 commits intoopen-telemetry:mainfrom
djvcom:fix/preserve-instrumentation-scope-metadata

Conversation

@djvcom
Copy link

@djvcom djvcom commented Jan 30, 2026

Summary

When logs have a target set, the InstrumentationScope's version and attributes were being discarded during OTLP export. The target parameter now correctly overrides only the scope name, preserving other metadata.

  • Fix From implementations for InstrumentationScope to preserve version and attributes when target is provided
  • Add unit tests for the From implementations
  • Add integration test demonstrating the fix with group_logs_by_resource_and_scope

Context

This behaviour was introduced in PR #1869 to avoid exporting the appender crate's version when the scope name was overridden by target. However, PRs #2735 and #2796 subsequently changed both appenders to use empty scopes, so this concern no longer applies. Additionally, users who explicitly create scopes via logger_with_scope() would reasonably expect their metadata to be preserved.

Test plan

  • Unit tests for both owned and reference From implementations
  • Integration test for group_logs_by_resource_and_scope with target set
  • cargo test -p opentelemetry-proto --all-features --lib passes
  • cargo clippy -p opentelemetry-proto --all-features -- -Dwarnings passes

Fixes #3276

When logs have a target set, the InstrumentationScope's version and
attributes were being discarded during OTLP export. The target parameter
now correctly overrides only the scope name, preserving other metadata.

This behaviour was introduced in PR open-telemetry#1869 to avoid exporting the
appender crate's version when the scope name was overridden by target.
However, PRs open-telemetry#2735 and open-telemetry#2796 subsequently changed both appenders to use
empty scopes, so this concern no longer applies. Additionally, users who
explicitly create scopes via logger_with_scope() would reasonably expect
their metadata to be preserved.

Fixes open-telemetry#3276
@djvcom djvcom requested a review from a team as a code owner January 30, 2026 14:08
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jan 30, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: djvcom / name: Daniel Verrall (f1be8ab)

@codecov
Copy link

codecov bot commented Jan 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.3%. Comparing base (9650783) to head (f1be8ab).

Additional details and impacted files
@@           Coverage Diff           @@
##            main   #3332     +/-   ##
=======================================
+ Coverage   83.2%   83.3%   +0.1%     
=======================================
  Files        128     128             
  Lines      25045   25089     +44     
=======================================
+ Hits       20858   20923     +65     
+ Misses      4187    4166     -21     

☔ View full report in Codecov by Sentry.
📢 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.

@djvcom
Copy link
Author

djvcom commented Jan 30, 2026

Hi there, first time contributing here so please let me know if I need to change anything (or if I'm not allowed to contribute etc). Sorry if I've done anything wrong!

attributes: Attributes::from(library.attributes().cloned()).0,
..Default::default()
}
InstrumentationScope {
Copy link
Member

Choose a reason for hiding this comment

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

not introduced by this PR, but this area is quite expensive due to copy/allocation etc. #3307 exposes the cost of this conversion!

Just FYI, nothing for this PR. The whole idea of target and instrumentation scope needs to be revisited to improve the performance.

Copy link
Member

Choose a reason for hiding this comment

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

@djvcom Out of curiosity, can you elaborate on how did you hit this issue yourselves? The log appenders shipped in this repo always set a target and the scope attributes are empty, so this should have caused no issue. So wondering how did you hit the issue here. This is merely to help us understand the space better which will help future perf improvements!

Copy link
Author

Choose a reason for hiding this comment

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

I was creating a scope manually as well (i've been building a little rust project to help me test collector configurations are valid). I doubt that most users would ever encounter it, and it was only because I was looking to verify and assert against resource and scope attrs that I noticed it, and the issue raised. All of my use cases I use the tracing appender, so I won't even benefit from this change in my day to day, but still thought it worth addressing.

@scottgerring
Copy link
Member

I note this fixes the same bug that @calavera calavera started looking at in #3175

@djvcom
Copy link
Author

djvcom commented Feb 17, 2026

@scottgerring yep, I did look at his work as a reference point for getting started on it. Do you think this is still needed? Happy to make any changes as required or close if not? I'd forgotten about it 😅

@scottgerring
Copy link
Member

@scottgerring yep, I did look at his work as a reference point for getting started on it. Do you think this is still needed? Happy to make any changes as required or close if not? I'd forgotten about it 😅

As there's a couple folks who've hit it now and this looks like a clean change to me I reckon we should merge it. @cijothomas wdyt?

@cijothomas cijothomas added this pull request to the merge queue Mar 13, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 13, 2026
@scottgerring
Copy link
Member

@cijothomas this one looks like it's been hit with the merge queue issues too ?

@bryantbiggs
Copy link
Contributor

@scottgerring / @cijothomas feel free to tag me when you come across any flaky tests - hopefully we can burn those down so that CI is a bit more reliable and approved PRs are less likely to get kicked out of the merge queue. I see it was updated with main so hopefully that fixed the flaky tests it encountered

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.

[Bug]: opentelemetry-proto discards InstrumentationScope attributes for logs

5 participants