1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-11-23 22:34:47 +02:00

otel: conceal unwrapping for global async instrument registration (#5881)

~Two defects are fixed here. However, note that async instrument
delegation appears to have been broken a long time.~

Internalizes and tests the behavior of the Global MeterProvider. This
moves the call to `Unwrap()` out of the SDK, fully concealing it within
the internal/global package (using an un-exported method).

This adds a test for the new functionality. While this test is not
comprehensive, because it doesn't test every instrument variation, it
explicitly tests that both the NewCallback function and the Observe
functions receive objects constructed by the alternate SDK.

Fixes #5827

---------

Co-authored-by: David Ashpole <dashpole@google.com>
Co-authored-by: Robert Pająk <pellared@hotmail.com>
This commit is contained in:
Joshua MacDonald
2024-10-18 10:36:05 -07:00
committed by GitHub
parent 81b2a33e1b
commit 2578accaa8
6 changed files with 325 additions and 50 deletions

View File

@@ -57,19 +57,19 @@ func TestAsyncInstrumentSetDelegateConcurrentSafe(t *testing.T) {
t.Run("Float64", func(t *testing.T) {
t.Run("Counter", func(t *testing.T) {
delegate := &afCounter{}
f := func(float64) { _ = delegate.Unwrap() }
f := func(float64) { _ = delegate.unwrap() }
testFloat64ConcurrentSafe(f, delegate.setDelegate)
})
t.Run("UpDownCounter", func(t *testing.T) {
delegate := &afUpDownCounter{}
f := func(float64) { _ = delegate.Unwrap() }
f := func(float64) { _ = delegate.unwrap() }
testFloat64ConcurrentSafe(f, delegate.setDelegate)
})
t.Run("Gauge", func(t *testing.T) {
delegate := &afGauge{}
f := func(float64) { _ = delegate.Unwrap() }
f := func(float64) { _ = delegate.unwrap() }
testFloat64ConcurrentSafe(f, delegate.setDelegate)
})
})
@@ -79,19 +79,19 @@ func TestAsyncInstrumentSetDelegateConcurrentSafe(t *testing.T) {
t.Run("Int64", func(t *testing.T) {
t.Run("Counter", func(t *testing.T) {
delegate := &aiCounter{}
f := func(int64) { _ = delegate.Unwrap() }
f := func(int64) { _ = delegate.unwrap() }
testInt64ConcurrentSafe(f, delegate.setDelegate)
})
t.Run("UpDownCounter", func(t *testing.T) {
delegate := &aiUpDownCounter{}
f := func(int64) { _ = delegate.Unwrap() }
f := func(int64) { _ = delegate.unwrap() }
testInt64ConcurrentSafe(f, delegate.setDelegate)
})
t.Run("Gauge", func(t *testing.T) {
delegate := &aiGauge{}
f := func(int64) { _ = delegate.Unwrap() }
f := func(int64) { _ = delegate.unwrap() }
testInt64ConcurrentSafe(f, delegate.setDelegate)
})
})