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

Added a version tag to the collector's own telemetry metrics #3960

Closed
wants to merge 4 commits into from
Closed
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
12 changes: 11 additions & 1 deletion internal/collector/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ var (
metricsAddrPtr *string
metricsPrefixPtr *string

addInstanceIDPtr *bool
addInstanceIDPtr *bool
addCollectorVersionPtr *bool
)

func Flags(flags *flag.FlagSet) {
Expand All @@ -49,6 +50,11 @@ func Flags(flags *flag.FlagSet) {
"add-instance-id",
true,
"Flag to control the addition of 'service.instance.id' to the collector metrics.")

addCollectorVersionPtr = flags.Bool(
"add-collector-version",
true,
"Flag to control the addition of 'service.version' to the collector metrics.")
}
Comment on lines +54 to 58
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not add more flags, see #3957 and #3843

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// GetMetricsAddrDefault returns the default metrics bind address and port depending on
Expand All @@ -61,6 +67,10 @@ func GetAddInstanceID() bool {
return *addInstanceIDPtr
}

func GetAddCollectorVersion() bool {
return *addCollectorVersionPtr
}

func GetMetricsAddr() string {
return *metricsAddrPtr
}
Expand Down
10 changes: 7 additions & 3 deletions service/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/internal/collector/telemetry"
"go.opentelemetry.io/collector/internal/obsreportconfig"
"go.opentelemetry.io/collector/internal/version"
semconv "go.opentelemetry.io/collector/model/semconv/v1.5.0"
"go.opentelemetry.io/collector/processor/batchprocessor"
telemetry2 "go.opentelemetry.io/collector/service/internal/telemetry"
Expand Down Expand Up @@ -75,14 +76,17 @@ func (tel *colTelemetry) init(asyncErrorChannel chan<- error, ballastSizeBytes u
opts := prometheus.Options{
Namespace: telemetry.GetMetricsPrefix(),
}
opts.ConstLabels = make(map[string]string)

var instanceID string
if telemetry.GetAddInstanceID() {
instanceUUID, _ := uuid.NewRandom()
instanceID = instanceUUID.String()
opts.ConstLabels = map[string]string{
sanitizePrometheusKey(semconv.AttributeServiceInstanceID): instanceID,
}
opts.ConstLabels[sanitizePrometheusKey(semconv.AttributeServiceInstanceID)] = instanceID
}

if telemetry.GetAddCollectorVersion() {
opts.ConstLabels[sanitizePrometheusKey(semconv.AttributeServiceVersion)] = version.Version
}

pe, err := prometheus.NewExporter(opts)
Expand Down