Skip to content
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

Wrap the SDK-internal MeterProvider with a shim to replace otelcol_ with otelsdk_ #760

Merged
merged 3 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## Unreleased

- Metrics/Traces exporter [#760](https://github.com/lightstep/otel-launcher-go/pull/760)
- Traces exporter: allow custom meter/trace providers [#739](https://github.com/lightstep/otel-launcher-go/pull/739)
- Use correct default retry settings. [#741](https://github.com/lightstep/otel-launcher-go/pull/741)

## [1.30.0](https://github.com/lightstep/otel-launcher-go/releases/tag/v1.30.0) - 2024-07-17
Expand Down
90 changes: 90 additions & 0 deletions lightstep/sdk/internal/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
package internal

import (
"strings"
"sync"

"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/embedded"
"go.opentelemetry.io/otel/sdk/resource"
)

Expand Down Expand Up @@ -101,3 +104,90 @@ func CopyAttributes(dest pcommon.Map, src attribute.Set) {
}
}
}

type notelMeterProvider struct {
embedded.MeterProvider
meterProvider metric.MeterProvider
}

type notelMeter struct {
embedded.Meter
meter metric.Meter
}

func (no notelMeterProvider) Meter(name string, opts ...metric.MeterOption) metric.Meter {
return notelMeter{
meter: no.meterProvider.Meter(name, opts...),
}
}

func fixName(name string) string {
if strings.HasPrefix(name, "otelcol_") {
return "otelsdk_" + name[8:]
}
return name
}

func (no notelMeter) Int64Counter(name string, options ...metric.Int64CounterOption) (metric.Int64Counter, error) {
return no.meter.Int64Counter(fixName(name), options...)
}

func (no notelMeter) Int64UpDownCounter(name string, options ...metric.Int64UpDownCounterOption) (metric.Int64UpDownCounter, error) {
return no.meter.Int64UpDownCounter(fixName(name), options...)
}

func (no notelMeter) Int64Histogram(name string, options ...metric.Int64HistogramOption) (metric.Int64Histogram, error) {
return no.meter.Int64Histogram(fixName(name), options...)
}

func (no notelMeter) Int64Gauge(name string, options ...metric.Int64GaugeOption) (metric.Int64Gauge, error) {
return no.meter.Int64Gauge(fixName(name), options...)
}

func (no notelMeter) Int64ObservableCounter(name string, options ...metric.Int64ObservableCounterOption) (metric.Int64ObservableCounter, error) {
return no.meter.Int64ObservableCounter(fixName(name), options...)
}

func (no notelMeter) Int64ObservableUpDownCounter(name string, options ...metric.Int64ObservableUpDownCounterOption) (metric.Int64ObservableUpDownCounter, error) {
return no.meter.Int64ObservableUpDownCounter(fixName(name), options...)
}

func (no notelMeter) Int64ObservableGauge(name string, options ...metric.Int64ObservableGaugeOption) (metric.Int64ObservableGauge, error) {
return no.meter.Int64ObservableGauge(fixName(name), options...)
}

func (no notelMeter) Float64Counter(name string, options ...metric.Float64CounterOption) (metric.Float64Counter, error) {
return no.meter.Float64Counter(fixName(name), options...)
}

func (no notelMeter) Float64UpDownCounter(name string, options ...metric.Float64UpDownCounterOption) (metric.Float64UpDownCounter, error) {
return no.meter.Float64UpDownCounter(fixName(name), options...)
}

func (no notelMeter) Float64Histogram(name string, options ...metric.Float64HistogramOption) (metric.Float64Histogram, error) {
return no.meter.Float64Histogram(fixName(name), options...)
}

func (no notelMeter) Float64Gauge(name string, options ...metric.Float64GaugeOption) (metric.Float64Gauge, error) {
return no.meter.Float64Gauge(fixName(name), options...)
}

func (no notelMeter) Float64ObservableCounter(name string, options ...metric.Float64ObservableCounterOption) (metric.Float64ObservableCounter, error) {
return no.meter.Float64ObservableCounter(fixName(name), options...)
}

func (no notelMeter) Float64ObservableUpDownCounter(name string, options ...metric.Float64ObservableUpDownCounterOption) (metric.Float64ObservableUpDownCounter, error) {
return no.meter.Float64ObservableUpDownCounter(fixName(name), options...)
}

func (no notelMeter) Float64ObservableGauge(name string, options ...metric.Float64ObservableGaugeOption) (metric.Float64ObservableGauge, error) {
return no.meter.Float64ObservableGauge(fixName(name), options...)
}

func (no notelMeter) RegisterCallback(f metric.Callback, instruments ...metric.Observable) (metric.Registration, error) {
return no.meter.RegisterCallback(f, instruments...)
}

func NOTelColMeterProvider(m metric.MeterProvider) metric.MeterProvider {
return &notelMeterProvider{meterProvider: m}
}
2 changes: 1 addition & 1 deletion lightstep/sdk/internal/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/pdata v1.12.0
go.opentelemetry.io/otel v1.28.0
go.opentelemetry.io/otel/metric v1.28.0
go.opentelemetry.io/otel/sdk v1.28.0
)

Expand All @@ -20,7 +21,6 @@ require (
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/trace v1.28.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.25.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion lightstep/sdk/metric/exporters/otlp/otelcol/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func NewExporter(ctx context.Context, cfg Config) (metric.PushExporter, error) {
}

if cfg.SelfMetrics {
c.settings.TelemetrySettings.MeterProvider = otel.GetMeterProvider()
c.settings.TelemetrySettings.MeterProvider = internal.NOTelColMeterProvider(otel.GetMeterProvider())
c.settings.TelemetrySettings.MetricsLevel = configtelemetry.LevelNormal
c.counter, _ = c.settings.TelemetrySettings.MeterProvider.Meter("lightstep/sdk/metric").Int64Counter("otelsdk.telemetry.items")
} else {
Expand Down
1 change: 1 addition & 0 deletions lightstep/sdk/trace/exporters/otlp/otelcol/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ func NewExporter(ctx context.Context, cfg Config, opts ...func(options *Exporter
} else {
c.settings.TelemetrySettings.MeterProvider = options.MeterProvider
}
c.settings.TelemetrySettings.MeterProvider = internal.NOTelColMeterProvider(c.settings.TelemetrySettings.MeterProvider)
c.settings.TelemetrySettings.MetricsLevel = configtelemetry.LevelNormal
// Note: the metrics SDK creates a counter at this
// point and counts points. The same is not done here
Expand Down
Loading