Skip to content

Commit

Permalink
Add autometrics.version to build_info metric
Browse files Browse the repository at this point in the history
  • Loading branch information
gagbo committed Nov 13, 2023
1 parent 71c2fd0 commit 2808891
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
9 changes: 9 additions & 0 deletions otel/autometrics/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ var (
)

const (
// AutometricsSpecVersion is the version of the specification the library follows
// The specifications can be found in https://github.com/autometrics-dev/autometrics-shared/tree/main/specs
AutometricsSpecVersion = "1.0.0"

// FunctionCallsCountName is the name of the openTelemetry metric for the counter of calls to specific functions.
FunctionCallsCountName = "function.calls"
// FunctionCallsDurationName is the name of the openTelemetry metric for the duration histogram of calls to specific functions.
Expand Down Expand Up @@ -91,6 +95,10 @@ const (
// service repository url
RepositoryProviderLabel = "repository.provider"

// AutometricsVersionLabel is the openTelemetry attribute that describes the version of the Autometrics specification
// the library follows
AutometricsVersionLabel = "autometrics.version"

// ServiceNameLabel is the openTelemetry attribute that describes the name of the Service being monitored.
ServiceNameLabel = "service.name"

Expand Down Expand Up @@ -244,6 +252,7 @@ func Init(meterName string, histogramBuckets []float64, buildInformation BuildIn
attribute.Key(RepositoryProviderLabel).String(autometrics.GetRepositoryProvider()),
attribute.Key(RepositoryURLLabel).String(autometrics.GetRepositoryURL()),
attribute.Key(JobNameLabel).String(autometrics.GetPushJobName()),
attribute.Key(AutometricsVersionLabel).String(AutometricsSpecVersion),
}...))

return cancelFunc, nil
Expand Down
11 changes: 10 additions & 1 deletion prometheus/autometrics/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ var (
)

const (
// AutometricsSpecVersion is the version of the specification the library follows
// The specifications can be found in https://github.com/autometrics-dev/autometrics-shared/tree/main/specs
AutometricsSpecVersion = "1.0.0"

// FunctionCallsCountName is the name of the prometheus metric for the counter of calls to specific functions.
FunctionCallsCountName = "function_calls_total"
// FunctionCallsDurationName is the name of the prometheus metric for the duration histogram of calls to specific functions.
Expand Down Expand Up @@ -83,6 +87,10 @@ const (
// service repository url
RepositoryProviderLabel = "repository_provider"

// AutometricsVersionLabel is the prometheus label that describes the version of the Autometrics specification
// the library follows
AutometricsVersionLabel = "autometrics_version"

// ServiceNameLabel is the prometheus label that describes the name of the service being monitored
ServiceNameLabel = "service_name"

Expand Down Expand Up @@ -186,7 +194,7 @@ func Init(reg *prometheus.Registry, histogramBuckets []float64, buildInformation

buildInfo = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: BuildInfoName,
}, []string{CommitLabel, VersionLabel, BranchLabel, ServiceNameLabel, RepositoryURLLabel, RepositoryProviderLabel})
}, []string{CommitLabel, VersionLabel, BranchLabel, ServiceNameLabel, RepositoryURLLabel, RepositoryProviderLabel, AutometricsVersionLabel})

if reg != nil {
reg.MustRegister(functionCallsCount)
Expand All @@ -207,6 +215,7 @@ func Init(reg *prometheus.Registry, histogramBuckets []float64, buildInformation
ServiceNameLabel: autometrics.GetService(),
RepositoryURLLabel: autometrics.GetRepositoryURL(),
RepositoryProviderLabel: autometrics.GetRepositoryProvider(),
AutometricsVersionLabel: AutometricsSpecVersion,
}).Set(1)

if pusher != nil {
Expand Down

0 comments on commit 2808891

Please sign in to comment.