2020-12-02 08:50:59 +01:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2025-03-27 02:40:27 -04:00
|
|
|
"github.com/zitadel/zitadel/internal/telemetry/metrics"
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/telemetry/metrics/otel"
|
2023-12-08 16:30:55 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
2020-12-02 08:50:59 +01:00
|
|
|
)
|
|
|
|
|
2022-07-18 10:42:32 +02:00
|
|
|
type Config struct {
|
2020-12-02 08:50:59 +01:00
|
|
|
Type string
|
2022-07-18 10:42:32 +02:00
|
|
|
Config map[string]interface{} `mapstructure:",remain"`
|
2020-12-02 08:50:59 +01:00
|
|
|
}
|
|
|
|
|
2022-07-18 10:42:32 +02:00
|
|
|
var meter = map[string]func(map[string]interface{}) error{
|
|
|
|
"otel": otel.NewTracerFromConfig,
|
2025-03-27 02:40:27 -04:00
|
|
|
"none": registerNoopMetrics,
|
|
|
|
"": registerNoopMetrics,
|
2020-12-02 08:50:59 +01:00
|
|
|
}
|
|
|
|
|
2022-07-18 10:42:32 +02:00
|
|
|
func (c *Config) NewMeter() error {
|
2025-03-27 02:40:27 -04:00
|
|
|
// When using start-from-init or start-from-setup the metric provider
|
|
|
|
// was already set in the setup phase and the start phase must not overwrite it.
|
|
|
|
if metrics.M != nil {
|
|
|
|
return nil
|
|
|
|
}
|
2022-07-18 10:42:32 +02:00
|
|
|
t, ok := meter[c.Type]
|
2020-12-02 08:50:59 +01:00
|
|
|
if !ok {
|
2023-12-08 16:30:55 +02:00
|
|
|
return zerrors.ThrowInternalf(nil, "METER-Dfqsx", "config type %s not supported", c.Type)
|
2020-12-02 08:50:59 +01:00
|
|
|
}
|
|
|
|
|
2022-07-18 10:42:32 +02:00
|
|
|
return t(c.Config)
|
2020-12-02 08:50:59 +01:00
|
|
|
}
|
|
|
|
|
2025-03-27 02:40:27 -04:00
|
|
|
func registerNoopMetrics(rawConfig map[string]interface{}) (err error) {
|
|
|
|
metrics.M = &metrics.NoopMetrics{}
|
2020-12-02 08:50:59 +01:00
|
|
|
return nil
|
|
|
|
}
|