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

fix(instrumentation-redis): remove redis types from public API #1424

Merged

Conversation

pichlermarc
Copy link
Member

@pichlermarc pichlermarc commented Mar 9, 2023

Which problem is this PR solving?

Having both @opentelemetry/instrumentation-redis and redis@^4.0.2 (common when using @opentelemetry/autoinstrumentations-node) installed causes typescript compilation errors.

Fixes #1323

Short description of the changes

  • This PR fixes the above problem by not using the removed Callback type in the public API.
  • Also updates the link to command.js in the comment.
  • Removes @types/redis as a dependency and moves it to devDependencies instead

@pichlermarc pichlermarc added the bug Something isn't working label Mar 9, 2023
@pichlermarc pichlermarc requested a review from a team March 9, 2023 13:31
@github-actions github-actions bot requested a review from blumamir March 9, 2023 13:31
@codecov
Copy link

codecov bot commented Mar 9, 2023

Codecov Report

Merging #1424 (474ad7d) into main (5f180aa) will decrease coverage by 0.18%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1424      +/-   ##
==========================================
- Coverage   96.13%   95.96%   -0.18%     
==========================================
  Files          14       17       +3     
  Lines         906     1066     +160     
  Branches      197      217      +20     
==========================================
+ Hits          871     1023     +152     
- Misses         35       43       +8     
Impacted Files Coverage Δ
...metry-instrumentation-redis/src/instrumentation.ts 93.47% <100.00%> (ø)

... and 2 files with indirect coverage changes

@Flarna
Copy link
Member

Flarna commented Mar 9, 2023

The change itself is ok but it doesn't solve the problem that the redis instrumentation exposes the redis types.
The use of typeof redisTypes in a protected method and on the base class still causes that @types/redis is required to be a dependency instead a devDependency.

Could you replace typeof redisTypes at these places by any or similar and update package.json?

@pichlermarc
Copy link
Member Author

The change itself is ok but it doesn't solve the problem that the redis instrumentation exposes the redis types. The use of typeof redisTypes in a protected method and on the base class still causes that @types/redis is required to be a dependency instead a devDependency.

Could you replace typeof redisTypes at these places by any or similar and update package.json?

Thanks for the feedback, I updated the PR with these changes (b86dc5e) 🙂

I feel like I still lack some understanding of the subject, though:

  • not using Callback from redis fixed the issue in my local testing setup
    • As I understand this fixes the problem as Callback does not exist in redis 4, so not using it in the public API works with the types shipped with redis@^4.0.0.
    • As we're now not using anything from the @types/redis package, I was under the impression that it should be safe to use it in this way as type-arguments.

We're doing something similar in the express instrumentation (depending on @types/express using it in the instrumentation class and in one of its protected methods) - would that need to be subject to the same changes? I'd like to provoke some of the issues caused by using types in this manner in a local app so I can understand the problem a bit better 🙂

@Flarna
Copy link
Member

Flarna commented Mar 13, 2023

Using the types in the user facing API is always a time bomb. We had this in several instrumentations in the past. You may fix one problem by removing Callback but other problems remain.

If it is in the user facing API it needs to be in the dependencies otherwise users using typescript see issues because of missing types.
If it is in the dependencies it's a specific version which is likely not that one used in actual application. Might again cause all sorts of issues.
If types are included in the package itself it's even worse as instrumentation has to depend on a specific version of the module it instruments.

The only safe variant is to keep the user facing API free of types of 3rd party modules. see also here.

Copy link
Member

@Flarna Flarna left a comment

Choose a reason for hiding this comment

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

You might want to update description a bit as it's now a bit more then do not use Callback.

@pichlermarc pichlermarc changed the title fix(instrumentation-redis): do not use Callback from @types/redis fix(instrumentation-redis): remove redis types from public API Mar 13, 2023
@pichlermarc
Copy link
Member Author

@Flarna got it, thanks! 🙂

@pichlermarc pichlermarc merged commit 861b867 into open-telemetry:main Mar 30, 2023
@pichlermarc pichlermarc deleted the fix/redis-types branch March 30, 2023 11:25
@dyladan dyladan mentioned this pull request Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pkg:instrumentation-redis
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tsc compiling both redis and redis-4 when importing getNodeAutoInstrumentations
5 participants