Skip to content

Commit

Permalink
Fix panic where model.NameValidationScheme isn't set
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Silva Sens <[email protected]>
  • Loading branch information
ArthurSens committed Jan 10, 2025
1 parent f03944f commit 707ce2a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions receiver/prometheusreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package prometheusreceiver // import "github.com/open-telemetry/opentelemetry-co
import (
"context"

"github.com/prometheus/common/model"
promconfig "github.com/prometheus/prometheus/config"
_ "github.com/prometheus/prometheus/discovery/install" // init() of this package registers service discovery impl.
"go.opentelemetry.io/collector/component"
Expand Down Expand Up @@ -35,6 +36,12 @@ var enableNativeHistogramsGate = featuregate.GlobalRegistry().MustRegister(

// NewFactory creates a new Prometheus receiver factory.
func NewFactory() receiver.Factory {
// Since Prometheus 3.0, the default validation scheme for metric names is UTF8.
// This includes ScrapeManager lib that is used by the Promethes receiver.
// We need to set the validation scheme to _something_ to avoid panics, and
// UTF8 is the default in Prometheus.
model.NameValidationScheme = model.UTF8Validation

return receiver.NewFactory(
metadata.Type,
createDefaultConfig,
Expand Down

0 comments on commit 707ce2a

Please sign in to comment.