Skip to content

Commit

Permalink
Update the template for generated_telemetry.go
Browse files Browse the repository at this point in the history
  • Loading branch information
madaraszg-tulip committed Nov 25, 2024
1 parent a98ddce commit 011d62e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/mdatagen/internal/samplereceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions cmd/mdatagen/internal/templates/telemetry.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}",
Expand All @@ -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 }}
Expand Down

0 comments on commit 011d62e

Please sign in to comment.