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

[api-logs] Remove InstrumentationScope class #4436

Merged

Conversation

CodeBlanch
Copy link
Member

@CodeBlanch CodeBlanch commented Apr 25, 2023

Relates to #4433

Changes

  • Remove class InstrumentationScope (some early feedback from @alanwest)
  • Add some tests for LoggerProvider

Merge requirement checklist

  • CONTRIBUTING guidelines followed (nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Changes in public API reviewed (if applicable)

@CodeBlanch CodeBlanch requested a review from a team April 25, 2023 20:28
@codecov
Copy link

codecov bot commented Apr 25, 2023

Codecov Report

Merging #4436 (4885e46) into main (201beab) will increase coverage by 0.18%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4436      +/-   ##
==========================================
+ Coverage   84.77%   84.95%   +0.18%     
==========================================
  Files         307      306       -1     
  Lines       12158    12154       -4     
==========================================
+ Hits        10307    10326      +19     
+ Misses       1851     1828      -23     
Impacted Files Coverage Δ
src/OpenTelemetry.Api/Logs/Logger.cs 100.00% <100.00%> (+100.00%) ⬆️
src/OpenTelemetry.Api/Logs/LoggerProvider.cs 100.00% <100.00%> (+66.66%) ⬆️
src/OpenTelemetry.Api/Logs/NoopLogger.cs 66.66% <100.00%> (+66.66%) ⬆️

... and 1 file with indirect coverage changes

src/OpenTelemetry.Api/Logs/Logger.cs Outdated Show resolved Hide resolved
}

/// <summary>
/// Gets the <see cref="OpenTelemetry.InstrumentationScope"/> associated
/// with the logger.
/// Gets the name identifying the instrumentation library.
Copy link
Member

Choose a reason for hiding this comment

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

XML comments can be clean up in a later PR, but just noting that...

We can still refer to this as instrumentation scope here. Something like

Suggested change
/// Gets the name identifying the instrumentation library.
/// Gets the instrumentation scope name of the Logger.

or even just dropping the term instrumentation scope, which mimics the docs for Meter

Suggested change
/// Gets the name identifying the instrumentation library.
/// Gets the Logger name.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't disagree with you that they suck 🤣 but I did keep it ~consistent with what we have in TracerProvider:

/// <param name="name">Name identifying the instrumentation library.</param>
/// <param name="version">Version of the instrumentation library.</param>

I think I'll leave it alone for now and then in a follow-up we can fix it all up?

Copy link
Member

Choose a reason for hiding this comment

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

I think I'll leave it alone for now and then in a follow-up we can fix it all up?

Totally, and you're right we'd probably benefit from an editorial pass over our XML docs in general.

/// <param name="name">Optional name identifying the instrumentation library.</param>
/// <param name="logger"><see cref="Logger"/>.</param>
/// <returns><see langword="true"/> if the logger was created.</returns>
protected virtual bool TryCreateLogger(
Copy link
Member Author

Choose a reason for hiding this comment

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

This TryCreateLogger may look a little strange, but it accomplishes a number of things...

  • There is only a single virtual method that must be implemented in SDK(s).
  • We can add other GetLogger methods freely that add other things to the instrumentation scope (schema_url, attributes, etc.) maintained on Logger without implementations breaking.
  • There is some stuff in the spec about repeat calls returning the same instances and mutating instances when config changes. We don't support that yet, but in theory separating "Get" from "Create" should allow the base class to implement that stuff if we ever need to.

@CodeBlanch CodeBlanch merged commit 9d2c31a into open-telemetry:main Apr 25, 2023
@CodeBlanch CodeBlanch deleted the log-api-instrumentationscope branch April 25, 2023 23:12
/// <returns><see langword="true"/> if the logger was created.</returns>
protected virtual bool TryCreateLogger(
string? name,
#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
Copy link
Member Author

Choose a reason for hiding this comment

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

A note about this condition...

OpenTelemetry.Api currently targets netstandard2.0;net462 so this will never resolve to true for any binary in the package. @TimothyMothra is currently exploring how to best approach this (eg #4293). Once we have a more recent target (or two) this should light up. In the meantime nothing catastrophic will happen just some wonky false-positive warnings about possibly accessing a null variable.

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.

2 participants