Skip to content

Adding target as LogRecord field, and using it as scope.name in OTLP exporter#1869

Merged
cijothomas merged 19 commits intoopen-telemetry:mainfrom
lalitb:set_instrumentation_scope
Jun 20, 2024
Merged

Adding target as LogRecord field, and using it as scope.name in OTLP exporter#1869
cijothomas merged 19 commits intoopen-telemetry:mainfrom
lalitb:set_instrumentation_scope

Conversation

@lalitb
Copy link
Member

@lalitb lalitb commented Jun 6, 2024

Fixes #1683

Changes

  • Add an API method LogRecord::set_target(&mut self, target: Cow<'static, str>).
  • Introduce target as a field in opentelemetry_sdk::logs::LogRecord:
pub struct LogRecord {
    /// Target of the log record
    pub target: Option<Cow<'static, str>>,
}
  • The opentelemetry-appender-tracing module will call set_target() using the tracing::metadata::target value.
  • The opentelemetry-appender-logs module will call set_target() using the logs::metadata::target value.
  • The OTLP logs exporter will:
    • Copy the target to scope.name before exporting the record.

Please provide a brief description of the changes here.

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated (if applicable)
  • Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • Changes in public API reviewed (if applicable)

@lalitb lalitb requested a review from a team June 6, 2024 18:32
@lalitb lalitb marked this pull request as draft June 6, 2024 18:32
@lalitb
Copy link
Member Author

lalitb commented Jun 6, 2024

Moving to draft to add tests, but should be good to review otherwise.

@codecov
Copy link

codecov bot commented Jun 6, 2024

Codecov Report

Attention: Patch coverage is 47.14286% with 37 lines in your changes missing coverage. Please review.

Project coverage is 74.6%. Comparing base (e0fb7fe) to head (d372130).

Current head d372130 differs from pull request most recent head e70e1d9

Please upload reports for the commit e70e1d9 to get more accurate results.

Files Patch % Lines
opentelemetry-proto/src/transform/common.rs 31.8% 30 Missing ⚠️
opentelemetry/src/logs/noop.rs 0.0% 5 Missing ⚠️
opentelemetry-proto/src/transform/logs.rs 0.0% 1 Missing ⚠️
opentelemetry-proto/src/transform/metrics.rs 0.0% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main   #1869     +/-   ##
=======================================
- Coverage   74.6%   74.6%   -0.1%     
=======================================
  Files        122     122             
  Lines      19952   20001     +49     
=======================================
+ Hits       14902   14933     +31     
- Misses      5050    5068     +18     

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

@lalitb lalitb added the integration tests Run integration tests label Jun 6, 2024
@lalitb lalitb marked this pull request as ready for review June 7, 2024 18:00
- Bump MSRV to 1.70 [#1840](https://github.com/open-telemetry/opentelemetry-rust/pull/1840)
- Fixing the OTLP HTTP/JSON exporter. [#1882](https://github.com/open-telemetry/opentelemetry-rust/pull/1882) - The exporter was broken in the
previous release.
- **Breaking** [1869](https://github.com/open-telemetry/opentelemetry-rust/pull/1869) The OTLP logs exporter now populates the [InstrumentationScope::name](https://github.com/open-telemetry/opentelemetry-proto/blob/b3060d2104df364136d75a35779e6bd48bac449a/opentelemetry/proto/common/v1/common.proto#L73) field with the name of the target/component emitting the logs, instead of the appender's name as done previously.
Copy link
Member

Choose a reason for hiding this comment

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

OTLP Exporter now overrides InstrumentationScope's name with target from LogRecord, if it is present.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

let mut log_record = self.logger.create_log_record();
log_record.set_severity_number(severity_of_level(meta.level()));
log_record.set_severity_text(meta.level().to_string().into());
log_record.set_target(meta.target().to_string());
Copy link
Member

Choose a reason for hiding this comment

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

the logger created by appender - please modify it to not populate version, as it'll be misleading now.

Copy link
Member

Choose a reason for hiding this comment

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

also - there is some experimental feature where target was added as an attribute. lets remove that now?

Copy link
Member Author

Choose a reason for hiding this comment

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

the logger created by appender - please modify it to not populate version, as it'll be misleading now.

Other thought - we can keep it, and allow users to customize the logger-name, for those interested to have the single logger, and use that created by appender?

also - there is some experimental feature where target was added as an attribute. lets remove that now?

Yeah good point. This is basically the "log.target" coming from log-to-tracing conversion. Will handle it as separate PR ?

Copy link
Member

Choose a reason for hiding this comment

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

the version will be misleading. it'll be the version of appender-crate, but the name will be that of the tracing:target. I'd suggest to remove version completely to avoid this confusion..

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree, as of now I have removed version and attributes population from OTLP exporter. We should make this configurable in OTLP exporter - default to override the scope.name with target, unless configured otherwise. Will create a separate PR for that (and a tracing task). I think the current way of configuration is bit messy with no separate way to provide log/trace/metrics specific configuration.

Copy link
Member Author

Choose a reason for hiding this comment

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

#1890 to track this.

Copy link
Member

@cijothomas cijothomas Jun 20, 2024

Choose a reason for hiding this comment

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

This is basically the "log.target" coming from log-to-tracing conversion. Will handle it as separate PR ?

Lets add an issue to track this too.

Copy link
Member Author

Choose a reason for hiding this comment

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

#1894 for tracking.

{
}

/// Sets the `target` of a record
Copy link
Member

Choose a reason for hiding this comment

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

some note about the need for this as opposed to instrumentation scope would be helpful.
also mention that exporters would use target to override instrumentation scope when present.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

@cijothomas cijothomas left a comment

Choose a reason for hiding this comment

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

Looks good, overall. Left some comments to be addressed before marking as approved.

Copy link
Member

@cijothomas cijothomas left a comment

Choose a reason for hiding this comment

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

Left a suggestion to improve changelog wording, rest looks good.

Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
@cijothomas cijothomas merged commit 4d45506 into open-telemetry:main Jun 20, 2024
bantonsson pushed a commit to bantonsson/opentelemetry-rust that referenced this pull request Oct 9, 2025
…exporter (open-telemetry#1869)

Co-authored-by: Zhongyang Wu <zhongyang.wu@outlook.com>
Co-authored-by: Cijo Thomas <cijo.thomas@gmail.com>
Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
takumi-earth pushed a commit to earthlings-dev/opentelemetry-rust that referenced this pull request Jan 27, 2026
…exporter (open-telemetry#1869)

Co-authored-by: Zhongyang Wu <zhongyang.wu@outlook.com>
Co-authored-by: Cijo Thomas <cijo.thomas@gmail.com>
Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
djvcom added a commit to djvcom/opentelemetry-rust that referenced this pull request Jan 29, 2026
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 added a commit to djvcom/opentelemetry-rust that referenced this pull request Jan 29, 2026
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 added a commit to djvcom/opentelemetry-rust that referenced this pull request Jan 29, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration tests Run integration tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Appender-tracing and target

3 participants