1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-11-27 22:49:15 +02:00

Encapsulate SDK Tracer observability (#7331)

Split from #7316 

[Follow
guidelines](a5dcd68ebb/CONTRIBUTING.md (encapsulation))
and move instrumentation into its own type.

### Benchmarks

#### Added `sdk/trace/internal/observ` benchmarks

```
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/sdk/trace/internal/observ
cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
                     │ enc-trace-sdk-tracer-obs.out │
                     │            sec/op            │
Tracer/SpanStarted-8                    7.436n ± 6%
Tracer/SpanLive-8                       9.987n ± 8%
Tracer/SpanEnded-8                      11.32n ± 7%
NewTracer-8                             87.64n ± 6%
geomean                                 16.48n

                     │ enc-trace-sdk-tracer-obs.out │
                     │             B/op             │
Tracer/SpanStarted-8                   0.000 ± 0%
Tracer/SpanLive-8                      0.000 ± 0%
Tracer/SpanEnded-8                     0.000 ± 0%
NewTracer-8                            0.000 ± 0%
geomean                                           ¹
¹ summaries must be >0 to compute geomean

                     │ enc-trace-sdk-tracer-obs.out │
                     │          allocs/op           │
Tracer/SpanStarted-8                   0.000 ± 0%
Tracer/SpanLive-8                      0.000 ± 0%
Tracer/SpanEnded-8                     0.000 ± 0%
NewTracer-8                            0.000 ± 0%
geomean                                           ¹
¹ summaries must be >0 to compute geomean
```

#### Existing `sdk/trace` benchmarks

```console
> benchstat main.out enc-trace-sdk-tracer-obs.out
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/sdk/trace
cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
                                  │  main.out   │     enc-trace-sdk-tracer-obs.out     │
                                  │   sec/op    │    sec/op     vs base                │
SpanEnd/ObservabilityEnabled-8      188.5n ± 4%   131.5n ± 32%  -30.24% (p=0.000 n=10)
TraceStart/ObservabilityEnabled-8   886.9n ± 8%   663.9n ±  2%  -25.14% (p=0.000 n=10)
geomean                             408.9n        295.5n        -27.73%

                                  │  main.out  │      enc-trace-sdk-tracer-obs.out       │
                                  │    B/op    │    B/op     vs base                     │
SpanEnd/ObservabilityEnabled-8      16.00 ± 0%    0.00 ± 0%  -100.00% (p=0.000 n=10)
TraceStart/ObservabilityEnabled-8   608.0 ± 0%   576.0 ± 0%    -5.26% (p=0.000 n=10)
geomean                             98.63                    ?                       ¹ ²
¹ summaries must be >0 to compute geomean
² ratios must be >0 to compute geomean

                                  │  main.out  │      enc-trace-sdk-tracer-obs.out       │
                                  │ allocs/op  │ allocs/op   vs base                     │
SpanEnd/ObservabilityEnabled-8      1.000 ± 0%   0.000 ± 0%  -100.00% (p=0.000 n=10)
TraceStart/ObservabilityEnabled-8   5.000 ± 0%   3.000 ± 0%   -40.00% (p=0.000 n=10)
geomean                             2.236                    ?                       ¹ ²
¹ summaries must be >0 to compute geomean
² ratios must be >0 to compute geomean
```

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Tyler Yahn
2025-09-15 12:18:32 -07:00
committed by GitHub
parent e4ab314112
commit 5b808c6ad5
7 changed files with 550 additions and 176 deletions

View File

@@ -412,11 +412,7 @@ func TestTracerProviderObservability(t *testing.T) {
require.IsType(t, &tracer{}, tr)
tStruct := tr.(*tracer)
assert.True(t, tStruct.observabilityEnabled, "observability should be enabled")
// Verify instruments are created
assert.NotNil(t, tStruct.spanLiveMetric, "spanLiveMetric should be created")
assert.NotNil(t, tStruct.spanStartedMetric, "spanStartedMetric should be created")
assert.True(t, tStruct.inst.Enabled(), "observability should be enabled")
// Verify errors are passed to the otel handler
handlerErrs := handler.errs