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

Allow LoggerProvider to be specified in Instrumentations #4314

Merged
merged 21 commits into from
Feb 6, 2024

Conversation

hectorhdzg
Copy link
Member

@hectorhdzg hectorhdzg commented Nov 21, 2023

Which problem is this PR solving?

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Allow LoggerProvider to be set for Instrumentations, so auto generation code for logs can use it, Bunyan, Winston, Pino, etc.

Fixes # (issue)

Short description of the changes

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Unit tests

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

Copy link

codecov bot commented Nov 21, 2023

Codecov Report

Merging #4314 (aab138b) into main (0229434) will increase coverage by 0.03%.
The diff coverage is 83.33%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4314      +/-   ##
==========================================
+ Coverage   92.31%   92.35%   +0.03%     
==========================================
  Files         108      328     +220     
  Lines        2213     9455    +7242     
  Branches      428     2011    +1583     
==========================================
+ Hits         2043     8732    +6689     
- Misses        170      723     +553     
Files Coverage Δ
...es/opentelemetry-instrumentation/src/autoLoader.ts 100.00% <100.00%> (ø)
...entelemetry-instrumentation/src/autoLoaderUtils.ts 92.85% <100.00%> (ø)
...entelemetry-instrumentation/src/instrumentation.ts 77.77% <66.66%> (ø)

... and 228 files with indirect coverage changes

@hectorhdzg hectorhdzg marked this pull request as ready for review November 21, 2023 23:49
@hectorhdzg hectorhdzg requested a review from a team November 21, 2023 23:49
@hectorhdzg
Copy link
Member Author

This functionality was discussed before in open-telemetry/opentelemetry-js-contrib#1713 (comment), thanks @trentm for letting me know about that, we can have different classes for Trace Instrumentations and Log Instrumenations, so we can have the definition of it and shared functionality in the same place avoiding different behaviors and duplication of code, @blumamir @pichlermarc thoughts?

Copy link
Member

@dyladan dyladan 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. Can you please add tests for this functionality?

@trentm
Copy link
Contributor

trentm commented Nov 22, 2023

This functionality was discussed before in open-telemetry/opentelemetry-js-contrib#1713 (comment)

Note that in the earlier discussion, we had been leaning towards not adding a this._logger to every instrumentation.

Other related comments from that issue:

From open-telemetry/opentelemetry-js-contrib#1713 (comment)

well then it would be good to have a specific Log Instrumentation then or similar

open-telemetry/opentelemetry-js-contrib#1713 (comment)

yeah having a LoggingInstrumentationConfig and a LoggingInstrumentation in @opentelemetry/instrumentation starts to make sense to me, at least for now we want to have, Winston, Bunyan, Pino and Console to also generate log telemetry, so this is something that several package would benefit from.

Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

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

I think holding off on this feature for now is a better idea.

The Logs API is not stable yet, and while @opentelemetry/instrumentation is also not stable I think we should start moving towards this. Also I think right now a very small percentage of instrumentations would make use of the logger for now.

I'm also not sure about the idea of having a separate class for Logging instrumentation, as that could make it difficult (it may encourage double wrapping libraries, for traces and for logs, and then there's a large potential of bugs where another instrumentation interferes with another one)

Just some thoughts, happy to be convinced otherwise though 🙂

@hectorhdzg
Copy link
Member Author

@pichlermarc related to logs not being stable, I believe we should be pushing to stabilize both Log API and Instrumentation, Logs is quite important as well, we are working on adding more instrumentations including winston, bunyan and console to use the logger, so this will start to grow very soon, I'm more in favor of having Logger available for all instrumentations, would be similar to Meter, some instrumentations will use it and some other don't, what is preventing us to stabilize Logs API?

@trentm
Copy link
Contributor

trentm commented Nov 30, 2023

I'm more in favor of having Logger available for all instrumentations

But shouldn't the only instrumentations that would use a this._logger property be those that are instrumenting logging frameworks? For all other instrumentations this._logger should be unused.

@pichlermarc
Copy link
Member

I'm more in favor of having Logger available for all instrumentations

But shouldn't the only instrumentations that would use a this._logger property be those that are instrumenting logging frameworks? For all other instrumentations this._logger should be unused.

I agree, to my understanding this is the main idea of the Logs bridge. With events, I'd expect this to be a different story.

what is preventing us to stabilize Logs API?

The API spec is stable so it's mainly a question of available bandwidth in the SIG. Anyone can pick up and drive the topic - in fact it would be highly appreciated. There has not been a lot of work after the initial prototyping so the first step would be to re-review the API based on spec compliance, then fix any issues - the same with the logs SDK. Then we would request a review from the Technical Committee, after that we integrate the API into the @opentelemetry/api package and move the logs sdk to the stable packages, at which point they will be released as stable.

@hectorhdzg
Copy link
Member Author

@pichlermarc great news, I would be more than happy to start the discussion of stabilizing Logs API, @trentm I understand logger would not be used by all instrumentations but what is the issue of logger being there?, instrumentations using the logger would be deviating from the common way and that is why I created this PR, without this the instrumentations will always use global loggerProvider and maybe that is ok but why having the options to specify providers in autoLoader in the first place then

@trentm
Copy link
Contributor

trentm commented Nov 30, 2023

without this the instrumentations will always use global loggerProvider and maybe that is ok but why having the options to specify providers in autoLoader in the first place then

Ah, that is a good argument for this.

https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation/README.md#selection-of-the-used-tracerprovidermeterprovider mentions "There might be usecase" for specifying providers other than the global ones for instrumentations. I haven't used this myself, so I don't know what use cases were in mind for that. I see a fair amount of .setTracerProvider(...) usage in tests in the contrib repo, so that seems to be at least one useful case.

I'm now okay with this change.

@trentm trentm assigned trentm and unassigned trentm Jan 4, 2024
@trentm
Copy link
Contributor

trentm commented Jan 4, 2024

^^ sorry for that self-assigning and unassigning.

Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

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

I am now also in favor (we discussed this in a SIG meeting some time ago) and we came to the conclusion that adding it would be beneficial.

Looks good, thanks!

Copy link
Contributor

@trentm trentm left a comment

Choose a reason for hiding this comment

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

LGTM, but nit about the changelog item now needing to move up.

experimental/CHANGELOG.md Outdated Show resolved Hide resolved
@hectorhdzg hectorhdzg added this to the Logs API/SDK GA milestone Jan 10, 2024
@hectorhdzg
Copy link
Member Author

@pichlermarc @dyladan looks like this PR is ready to merge, let me know if there is any additional feedback

@pichlermarc pichlermarc merged commit 588d8ad into open-telemetry:main Feb 6, 2024
20 checks passed
Zirak pushed a commit to Zirak/opentelemetry-js that referenced this pull request Sep 14, 2024
…try#4314)

* Allow LoggerProvider to be specified in Instrumentations

* Update

* Lint

* Add test

* npm i

* Update changelog

* npm i

* marking setLoggerProvider as optional

* Add check for possible undefined method

* npm i
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.

5 participants