Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 19 commits into from
Jun 20, 2024

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 as a code owner 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.

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
@@ -18,6 +18,7 @@ now use `.with_resource(RESOURCE::default())` to configure Resource when using
- 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.

@@ -172,6 +172,7 @@ where
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.

@@ -10,6 +10,11 @@ pub trait LogRecord {
{
}

/// 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
22 checks passed
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