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

Unify builders across signals #2220

Merged

Conversation

stormshield-fabs
Copy link
Contributor

@stormshield-fabs stormshield-fabs commented Oct 18, 2024

Fixes #1527 and fixes #2164

Changes

The consensus reached during the SIG meeting is that we'd like to unify the builder APIs across signals, limit duplication and keep our traits object-safe.

  • opentelemetry
    • Removed deprecated method InstrumentationLibrary::new
    • Renamed InstrumentationLibrary to InstrumentationScope
    • Renamed InstrumentationLibraryBuilder to InstrumentationScopeBuilder
    • Removed deprecated methods LoggerProvider::versioned_logger and TracerProvider::versioned_tracer
    • Removed methods LoggerProvider::logger_builder, TracerProvider::tracer_builder and MeterProvider::versioned_meter
    • Replaced these methods with LoggerProvider::logger_with_scope, TracerProvider::logger_with_scope, MeterProvider::meter_with_scope
    • Replaced global::meter_with_version with global::meter_with_scope
    • Added global::tracer_with_scope
  • opentelemetry_sdk:
    • Removed InstrumentationLibrary re-export and its Scope alias, use opentelemetry::InstrumentationLibrary instead.
    • Unified builders across signals
      • Removed deprecated LoggerProvider::versioned_logger, TracerProvider::versioned_tracer
      • Removed MeterProvider::versioned_meter
      • Replaced these methods with LoggerProvider::logger_with_scope, TracerProvider::logger_with_scope, MeterProvider::meter_with_scope

Migration guide (example for logger but the changes are similar across all 3 signals)

let provider = LoggerProvider::builder().build();

// Before:
let library = std::sync::Arc::new(
    InstrumentationLibrary::builder("test_logger")
        .with_version("v1.2.3")
        .with_schema_url("https://opentelemetry.io/schema/1.0.0")
        .build(),
);
let logger = provider.library_logger(library); // no longer available, use provider.logger_with_scope


// or maybe (was deprecated):
let logger = provider.versioned_logger(
  "test_logger",
  Some("v1.2.3".into()),
  Some("https://opentelemetry.io/schema/1.0.0".into()),
);

// After:
let scope = InstrumentationScope::builder("test_logger")
  .with_version("v1.2.3")
  .with_schema_url("https://opentelemetry.io/schema/1.0.0")
  .build();

let logger = provider.logger_with_scope(scope);

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)

Copy link

codecov bot commented Oct 18, 2024

Codecov Report

Attention: Patch coverage is 76.11111% with 43 lines in your changes missing coverage. Please review.

Project coverage is 79.6%. Comparing base (5628f66) to head (af8562b).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
opentelemetry-zipkin/src/exporter/mod.rs 0.0% 10 Missing ⚠️
opentelemetry-stdout/src/trace/exporter.rs 0.0% 4 Missing ⚠️
opentelemetry-sdk/src/logs/log_emitter.rs 84.2% 3 Missing ⚠️
opentelemetry/src/global/trace.rs 57.1% 3 Missing ⚠️
opentelemetry-proto/src/transform/trace.rs 66.6% 2 Missing ⚠️
opentelemetry-sdk/src/logs/log_processor.rs 88.8% 2 Missing ⚠️
opentelemetry-sdk/src/metrics/instrument.rs 0.0% 2 Missing ⚠️
opentelemetry-sdk/src/metrics/meter_provider.rs 93.5% 2 Missing ⚠️
opentelemetry-sdk/src/trace/tracer.rs 66.6% 2 Missing ⚠️
opentelemetry/src/global/metrics.rs 0.0% 2 Missing ⚠️
... and 9 more
Additional details and impacted files
@@          Coverage Diff           @@
##            main   #2220    +/-   ##
======================================
  Coverage   79.5%   79.6%            
======================================
  Files        121     121            
  Lines      21116   20918   -198     
======================================
- Hits       16805   16666   -139     
+ Misses      4311    4252    -59     

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

@stormshield-fabs
Copy link
Contributor Author

There were some concerns about having Arc in the library_signal APIs, but someone also mentioned we want to avoid unnecessary copies. We could hide the Arc inside the InstrumentationLibrary if needed.

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 few comments but looks good overall.
Please check the comments and see if they make sense.

opentelemetry-otlp/examples/basic-otlp/src/main.rs Outdated Show resolved Hide resolved
opentelemetry-otlp/examples/basic-otlp/src/main.rs Outdated Show resolved Hide resolved
opentelemetry-stdout/examples/basic.rs Outdated Show resolved Hide resolved
opentelemetry/src/global/metrics.rs Outdated Show resolved Hide resolved
@cijothomas
Copy link
Member

There were some concerns about having Arc in the library_signal APIs, but someone also mentioned we want to avoid unnecessary copies. We could hide the Arc inside the InstrumentationLibrary if needed.

yes I suggest to hide Arc inside.

opentelemetry/src/common.rs Outdated Show resolved Hide resolved
opentelemetry/src/common.rs Outdated Show resolved Hide resolved
@cijothomas
Copy link
Member

@stormshield-fabs Thanks a lot! I think the following are to be addressed before merge. We also need to write a migration guide in the PR description showing before/after, so users can easily (relatively) react to this.

Lets keep InstrumentationScope simple, and accept the perf cost now, given it is infrequent operation.
#2220 (comment)

Rename library-signal to something like signal_with_scope/better names.
#2220 (comment)

@stormshield-fabs stormshield-fabs force-pushed the provider-builder-pattern branch 3 times, most recently from f3c67cd to a6bd2db Compare October 22, 2024 08:04
@stormshield-fabs
Copy link
Contributor Author

I've addressed the pending comments and added changelog entries (feel free to edit them!)

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.

LGTM.
Could you modify the PR description to show the before/after example for logs/metrics/traces, so users can easily do the migration?

@cijothomas
Copy link
Member

@stormshield-fabs oops we just cause some merge conflicts! Could you resolve them.
We can merge with one more approval.
(Also, please update pr description to show before/after code snippets to make it easy for users to migrate)

Copy link
Contributor

@utpilla utpilla left a comment

Choose a reason for hiding this comment

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

Left some minor suggestions.

Great work @stormshield-fabs!!

Copy link
Member

@lalitb lalitb left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the changes.

@cijothomas
Copy link
Member

@stormshield-fabs Can you resolve conflicts and address the nits, and we can merge!

As suggested offline, if you can add a migration guide in the PR description, similar to #2221, that'd be awesome!

(The next release is a flood of breaking changes, so we need to write an overall migration guide, which will refer to the sub-migration-guides within each PR description.)

@lalitb
Copy link
Member

lalitb commented Oct 24, 2024

@stormshield-fabs I took the liberty of fixing minor merge conflicts in this PR, as it was introduced by changes from my own PR. Hope that's fine :)

@cijothomas cijothomas merged commit e2db7a0 into open-telemetry:main Oct 25, 2024
23 of 25 checks passed
@stormshield-fabs stormshield-fabs deleted the provider-builder-pattern branch October 25, 2024 06:42
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.

Metrics API - Move to builder pattern for creating Meters Instrumentation scope - move to builder pattern?
4 participants