Fix for delayed global registration #2784
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: #2777
What happened to cause this?
Before the global package, the only way to create an instrument was via the actual SDK. The global package introduced the idea of a delegated instrument, which when set forwarded all calls to the underlying instrument. But part of the SDK checks that the instruments passed to RegisterCallback were created by this SDK. The problem is that it does this poorly (eg just that they are of an internal type, so it won't guard against 2 instances of SDK interchanging instruments.)
So when you SetGlobalMeterProvider is called, it delegates all of the instruments and callbacks to the provided MP, but it will call RegisterCallback with a delegated type not the SDK type (it's stored inside the delegate).
How does this fix the problem?
Added an internal Unwrap to the delegated types, and before calling RegisterCallback it will unwrap the delegates so the SDK's type should be called.