telegraf icon indicating copy to clipboard operation
telegraf copied to clipboard

allow adding version to userAgent

Open povilasv opened this issue 3 years ago • 0 comments

Use Case

I would like to use https://github.com/influxdata/telegraf/blob/master/internal/internal.go#L52-L55 to get the telegraf version and set it in the userAgent , but if I execute the call in package level variable:

package opentelemetry

import (
	"context
	"github.com/influxdata/telegraf/plugins/common/tls"
	"github.com/influxdata/telegraf/plugins/outputs"
)

var userAgent = fmt.Sprintf("telegraf %s (%s/%s)", internal.Version(), runtime.GOOS, runtime.GOARCH)

It will be empty, as it is set during runtime -> https://github.com/influxdata/telegraf/blob/master/cmd/telegraf/telegraf.go#L413-L417 not compile time.

Expected behavior

internal.Version() returning correct version

Actual behavior

internal.Version() is empty

Additional info

No response

povilasv avatar Aug 10 '22 08:08 povilasv

Thanks for the issue and the PR!

reimda avatar Aug 11 '22 20:08 reimda