Skip to content

Commit 6fdcf82

Browse files
dashpoleminimAluminiumalismCopilotpellared
authored
feat: add self-observability metrics to otlpmetricgrpc metric exporters (#8192)
Fixes #7012 This updates #7120, and addresses outstanding comments. See commit descriptions for the changes made on top of that PR. Credit to minimAluminiumalism for the initial work. Benchmark results: ``` goos: linux goarch: amd64 pkg: go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/observ cpu: Intel(R) Xeon(R) CPU @ 2.20GHz │ bench_feature.txt │ │ sec/op │ InstrumentationTrackExport/EnabledNoError-24 1.045µ ± 5% InstrumentationTrackExport/EnabledError-24 2.248µ ± 1% InstrumentationTrackExport/Disabled-24 9.643n ± 1% geomean 282.9n │ bench_feature.txt │ │ B/op │ InstrumentationTrackExport/EnabledNoError-24 160.0 ± 0% InstrumentationTrackExport/EnabledError-24 488.0 ± 0% InstrumentationTrackExport/Disabled-24 0.000 ± 0% geomean ¹ ¹ summaries must be >0 to compute geomean │ bench_feature.txt │ │ allocs/op │ InstrumentationTrackExport/EnabledNoError-24 5.000 ± 0% InstrumentationTrackExport/EnabledError-24 6.000 ± 0% InstrumentationTrackExport/Disabled-24 0.000 ± 0% geomean ¹ ¹ summaries must be >0 to compute geomean ``` Written with assistance from Gemini. --------- Co-authored-by: minimAluminiumalism <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: Robert Pająk <[email protected]>
1 parent 761bbfc commit 6fdcf82

16 files changed

Lines changed: 2134 additions & 3 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
4444
- Add experimental self-observability metrics in `go.opentelemetry.io/otel/exporters/stdout/stdoutlog`. (#8263)
4545
- Add Observable variants of instruments to `go.opentelemetry.io/otel/semconv/v1.41.0` package. (#8350)
4646
- Generate explicit histogram bucket boundaries from weaver configuration for HTTP and RPC duration instruments in `go.opentelemetry.io/otel/semconv/v1.41.0`. (#8002)
47+
- Add experimental self-observability metrics to OTLP metric exporters in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc` and `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`.
48+
Enable with `OTEL_GO_X_SELF_OBSERVABILITY=true` environment variable. (#8192)
4749

4850
### Changed
4951

‎exporters/otlp/otlpmetric/otlpmetricgrpc/doc.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ default aggregation to use for histogram instruments. Supported values:
7777
7878
The configuration can be overridden by [WithAggregationSelector] option.
7979
80+
See [go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/x] for information about
81+
the experimental features.
82+
8083
[W3C Baggage HTTP Header Content Format]: https://www.w3.org/TR/baggage/#header-content
8184
[Explicit Bucket Histogram Aggregation]: https://github.com/open-telemetry/opentelemetry-specification/blob/v1.26.0/specification/metrics/sdk.md#explicit-bucket-histogram-aggregation
8285
[Base2 Exponential Bucket Histogram Aggregation]: https://github.com/open-telemetry/opentelemetry-specification/blob/v1.26.0/specification/metrics/sdk.md#base2-exponential-bucket-histogram-aggregation

‎exporters/otlp/otlpmetric/otlpmetricgrpc/exporter.go‎

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ import (
1111

1212
metricpb "go.opentelemetry.io/proto/otlp/metrics/v1"
1313

14+
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/counter"
15+
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/observ"
1416
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf"
1517
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform"
18+
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/x"
1619
"go.opentelemetry.io/otel/internal/global"
1720
"go.opentelemetry.io/otel/sdk/metric"
1821
"go.opentelemetry.io/otel/sdk/metric/metricdata"
@@ -31,6 +34,9 @@ type Exporter struct {
3134
aggregationSelector metric.AggregationSelector
3235

3336
shutdownOnce sync.Once
37+
38+
// Self-observability metrics
39+
inst *observ.Instrumentation
3440
}
3541

3642
func newExporter(c *client, cfg oconf.Config) (*Exporter, error) {
@@ -46,12 +52,27 @@ func newExporter(c *client, cfg oconf.Config) (*Exporter, error) {
4652
as = metric.DefaultAggregationSelector
4753
}
4854

55+
var inst *observ.Instrumentation
56+
var initErr error
57+
if x.Observability.Enabled() {
58+
var err error
59+
inst, err = observ.NewInstrumentation(
60+
counter.NextExporterID(),
61+
c.conn.CanonicalTarget(),
62+
)
63+
if err != nil {
64+
initErr = err
65+
}
66+
}
67+
4968
return &Exporter{
5069
client: c,
5170

5271
temporalitySelector: ts,
5372
aggregationSelector: as,
54-
}, nil
73+
74+
inst: inst,
75+
}, initErr
5576
}
5677

5778
// Temporality returns the Temporality to use for an instrument kind.
@@ -72,10 +93,18 @@ func (e *Exporter) Export(ctx context.Context, rm *metricdata.ResourceMetrics) e
7293
defer global.Debug("OTLP/gRPC exporter export", "Data", rm)
7394

7495
otlpRm, err := transform.ResourceMetrics(rm)
96+
97+
// Track export operation for self-observability
98+
op := e.inst.TrackExport(ctx, otlpRm)
99+
100+
var upErr error
101+
defer func() { op.End(upErr) }()
102+
75103
// Best effort upload of transformable metrics.
76104
e.clientMu.Lock()
77-
upErr := e.client.UploadMetrics(ctx, otlpRm)
105+
upErr = e.client.UploadMetrics(ctx, otlpRm)
78106
e.clientMu.Unlock()
107+
79108
if upErr != nil {
80109
if err == nil {
81110
return fmt.Errorf("failed to upload metrics: %w", upErr)

‎exporters/otlp/otlpmetric/otlpmetricgrpc/go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/google/go-cmp v0.7.0
1010
github.com/stretchr/testify v1.11.1
1111
go.opentelemetry.io/otel v1.43.0
12+
go.opentelemetry.io/otel/metric v1.43.0
1213
go.opentelemetry.io/otel/sdk v1.43.0
1314
go.opentelemetry.io/otel/sdk/metric v1.43.0
1415
go.opentelemetry.io/proto/otlp v1.10.0
@@ -26,7 +27,6 @@ require (
2627
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 // indirect
2728
github.com/pmezard/go-difflib v1.0.0 // indirect
2829
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
29-
go.opentelemetry.io/otel/metric v1.43.0 // indirect
3030
go.opentelemetry.io/otel/trace v1.43.0 // indirect
3131
golang.org/x/net v0.55.0 // indirect
3232
golang.org/x/sys v0.45.0 // indirect

‎exporters/otlp/otlpmetric/otlpmetricgrpc/internal/counter/counter.go‎

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎exporters/otlp/otlpmetric/otlpmetricgrpc/internal/counter/counter_test.go‎

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎exporters/otlp/otlpmetric/otlpmetricgrpc/internal/gen.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ package internal // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/o
77
//go:generate gotmpl --body=../../../../../internal/shared/otlp/partialsuccess.go.tmpl "--data={}" --out=partialsuccess.go
88
//go:generate gotmpl --body=../../../../../internal/shared/otlp/partialsuccess_test.go.tmpl "--data={}" --out=partialsuccess_test.go
99

10+
//go:generate gotmpl --body=../../../../../internal/shared/otlp/observ/target.go.tmpl "--data={ \"pkg\": \"observ\", \"pkg_path\": \"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/observ\" }" --out=observ/target.go
11+
//go:generate gotmpl --body=../../../../../internal/shared/otlp/observ/target_test.go.tmpl "--data={ \"pkg\": \"observ\" }" --out=observ/target_test.go
12+
1013
//go:generate gotmpl --body=../../../../../internal/shared/otlp/retry/retry.go.tmpl "--data={}" --out=retry/retry.go
1114
//go:generate gotmpl --body=../../../../../internal/shared/otlp/retry/retry_test.go.tmpl "--data={}" --out=retry/retry_test.go
1215

@@ -30,3 +33,9 @@ package internal // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/o
3033
//go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/transform/error_test.go.tmpl "--data={}" --out=transform/error_test.go
3134
//go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/transform/metricdata.go.tmpl "--data={}" --out=transform/metricdata.go
3235
//go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/transform/metricdata_test.go.tmpl "--data={}" --out=transform/metricdata_test.go
36+
37+
//go:generate gotmpl --body=../../../../../internal/shared/counter/counter.go.tmpl "--data={ \"pkg\": \"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/counter\" }" --out=counter/counter.go
38+
//go:generate gotmpl --body=../../../../../internal/shared/counter/counter_test.go.tmpl "--data={}" --out=counter/counter_test.go
39+
40+
//go:generate gotmpl --body=../../../../../internal/shared/x/x.go.tmpl "--data={ \"pkg\": \"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc\" }" --out=x/x.go
41+
//go:generate gotmpl --body=../../../../../internal/shared/x/x_test.go.tmpl "--data={}" --out=x/x_test.go

0 commit comments

Comments
 (0)