File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -30,14 +30,19 @@ var (
3030
3131// Init initializes the OpenTelemetry metrics with Prometheus exporter
3232func Init (environment string ) error {
33- exporter , err := prometheus .New ()
33+ // Create a resource with the environment attribute
34+ res := resource .NewSchemaless (attribute .String ("env" , environment ))
35+
36+ // Configure Prometheus exporter to include resource attributes as metric labels, it doesn't do it by default
37+ exporter , err := prometheus .New (
38+ prometheus .WithResourceAsConstantLabels (
39+ attribute .NewAllowKeysFilter ("env" ), // Only include "env" as a label
40+ ),
41+ )
3442 if err != nil {
3543 return fmt .Errorf ("failed to create prometheus exporter: %w" , err )
3644 }
3745
38- // Create a resource with the environment attribute
39- res := resource .NewSchemaless (attribute .String ("env" , environment ))
40-
4146 // Create a MeterProvider with the Prometheus exporter and resource
4247 provider := sdkmetric .NewMeterProvider (
4348 sdkmetric .WithReader (exporter ),
You can’t perform that action at this time.
0 commit comments