-
Notifications
You must be signed in to change notification settings - Fork 821
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
chore: use interface for context types #1515
chore: use interface for context types #1515
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1515 +/- ##
==========================================
- Coverage 93.82% 93.82% -0.01%
==========================================
Files 154 154
Lines 4763 4761 -2
Branches 952 952
==========================================
- Hits 4469 4467 -2
Misses 294 294
|
@xirzec we recently had a brief conversation about the idea that concrete classes have discrepancies more often than interfaces. Curious to know what you think of this change since my intention is to alleviate issues similar to what we discussed then. |
@dyladan Yes, the issue you're solving with this PR is the exact reason I've started preferring interfaces whenever possible. Nice work! |
@open-telemetry/javascript-approvers would like to get this merged before I leave for vacation :) |
OK good. Just wanted to make sure I understood fully the issue you were trying to solve. I believe we will also have the same problem with TraceFlags, which is currently an enum in the API. Aside from the fact that enum is an incorrect type for this, it also causes typescript to fail if you bring your own tracer which redefines this enum. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, one concern with keeping the static
@obecny fixed PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
In most cases, our current code base is using the concrete
Context
class as a type. This makes for incompatibilities when differing versions or subclasses of elements using context are used. For instance, it is possible to create a TracerProvider which satisfies all of the public methods, but typescript complains when you try to register it with the global API because private methods mismatch, even though they aren't used by the API.This changes the context-base module to export an interface, and root context which is declared to have the type of the interface, not the concrete class. This also changes usages of Context throughout the project to use the interface and the new exported root context.
Overall, this enhances the separation of the API module and its interfaces from the concrete implementations of the SDK and context.