diff --git a/cmd/mdatagen/internal/samplereceiver/factory.go b/cmd/mdatagen/internal/samplereceiver/factory.go index 7a3c9bb170d..e7445f9cb29 100644 --- a/cmd/mdatagen/internal/samplereceiver/factory.go +++ b/cmd/mdatagen/internal/samplereceiver/factory.go @@ -48,5 +48,5 @@ type nopReceiver struct { } func (r nopReceiver) initOptionalMetric() { - _ = r.telemetryBuilder.InitQueueLength(func() int64 { return 1 }) + _, _ = r.telemetryBuilder.InitQueueLength(func() int64 { return 1 }) } diff --git a/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_telemetry.go b/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_telemetry.go index 71d4e1e78d6..99c7017b575 100644 --- a/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_telemetry.go +++ b/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_telemetry.go @@ -55,7 +55,7 @@ func WithProcessRuntimeTotalAllocBytesCallback(cb func() int64, opts ...metric.O } // InitQueueLength configures the QueueLength metric. -func (builder *TelemetryBuilder) InitQueueLength(cb func() int64, opts ...metric.ObserveOption) error { +func (builder *TelemetryBuilder) InitQueueLength(cb func() int64, opts ...metric.ObserveOption) (metric.Registration, error) { var err error builder.QueueLength, err = builder.meter.Int64ObservableGauge( "otelcol_queue_length", @@ -63,13 +63,13 @@ func (builder *TelemetryBuilder) InitQueueLength(cb func() int64, opts ...metric metric.WithUnit("{items}"), ) if err != nil { - return err + return nil, err } - _, err = builder.meter.RegisterCallback(func(_ context.Context, o metric.Observer) error { + reg, err := builder.meter.RegisterCallback(func(_ context.Context, o metric.Observer) error { o.ObserveInt64(builder.QueueLength, cb(), opts...) return nil }, builder.QueueLength) - return err + return reg, err } // NewTelemetryBuilder provides a struct with methods to update all internal telemetry diff --git a/cmd/mdatagen/internal/templates/telemetry.go.tmpl b/cmd/mdatagen/internal/templates/telemetry.go.tmpl index 8b6c6e7d1dc..3f365e45167 100644 --- a/cmd/mdatagen/internal/templates/telemetry.go.tmpl +++ b/cmd/mdatagen/internal/templates/telemetry.go.tmpl @@ -56,7 +56,7 @@ func (tbof telemetryBuilderOptionFunc) apply(mb *TelemetryBuilder) { {{- range $name, $metric := .Telemetry.Metrics }} {{- if $metric.Optional }} // Init{{ $name.Render }} configures the {{ $name.Render }} metric. -func (builder *TelemetryBuilder) Init{{ $name.Render }}({{ if $metric.Data.Async -}}cb func() {{ $metric.Data.BasicType }}{{- end }}, opts ...metric.ObserveOption) error { +func (builder *TelemetryBuilder) Init{{ $name.Render }}({{ if $metric.Data.Async -}}cb func() {{ $metric.Data.BasicType }}{{- end }}, opts ...metric.ObserveOption) (metric.Registration, error) { var err error builder.{{ $name.Render }}, err = builder.meter.{{ $metric.Data.Instrument }}( "otelcol_{{ $name }}", @@ -68,14 +68,14 @@ func (builder *TelemetryBuilder) Init{{ $name.Render }}({{ if $metric.Data.Async ) {{- if $metric.Data.Async }} if err != nil { - return err + return nil, err } - _, err = builder.meter.RegisterCallback(func(_ context.Context, o metric.Observer) error { + reg, err := builder.meter.RegisterCallback(func(_ context.Context, o metric.Observer) error { o.Observe{{ casesTitle $metric.Data.BasicType }}(builder.{{ $name.Render }}, cb(), opts...) return nil }, builder.{{ $name.Render }}) {{- end }} - return err + return reg, err } {{- else }}