feat(otel): flag to disable telemetry for system routes

This commit is contained in:
Julien Neuhart
2026-03-28 14:06:16 +01:00
parent 7549a69f71
commit 72bc6f895a
5 changed files with 51 additions and 9 deletions

View File

@@ -23,11 +23,11 @@ func init() {
// Prometheus is a module that collects metrics and exposes them via an HTTP
// route.
type Prometheus struct {
namespace string
interval time.Duration
disableRouteLogging bool
disableCollect bool
metricsPath string
namespace string
interval time.Duration
disableRouteTelemetry bool
disableCollect bool
metricsPath string
metrics []gotenberg.Metric
registry *prometheus.Registry
@@ -41,10 +41,18 @@ func (mod *Prometheus) Descriptor() gotenberg.ModuleDescriptor {
fs := flag.NewFlagSet("prometheus", flag.ExitOnError)
fs.String("prometheus-namespace", "gotenberg", "Set the namespace of modules' metrics")
fs.Duration("prometheus-collect-interval", time.Duration(1)*time.Second, "Set the interval for collecting modules' metrics")
fs.Bool("prometheus-disable-route-logging", false, "Disable the route logging")
fs.Bool("prometheus-disable-route-telemetry", false, "Disable telemetry for the Prometheus metrics route")
fs.Bool("prometheus-disable-collect", false, "Disable the collect of metrics")
fs.String("prometheus-metrics-path", "/prometheus/metrics", "Path for Prometheus metrics endpoint")
// Deprecated flags.
fs.Bool("prometheus-disable-route-logging", false, "Disable the route logging")
err := fs.MarkDeprecated("prometheus-disable-route-logging", "use --prometheus-disable-route-telemetry instead")
if err != nil {
panic(err)
}
return fs
}(),
New: func() gotenberg.Module { return new(Prometheus) },
@@ -56,7 +64,7 @@ func (mod *Prometheus) Provision(ctx *gotenberg.Context) error {
flags := ctx.ParsedFlags()
mod.namespace = flags.MustString("prometheus-namespace")
mod.interval = flags.MustDuration("prometheus-collect-interval")
mod.disableRouteLogging = flags.MustBool("prometheus-disable-route-logging")
mod.disableRouteTelemetry = flags.MustDeprecatedBool("prometheus-disable-route-logging", "prometheus-disable-route-telemetry")
mod.disableCollect = flags.MustBool("prometheus-disable-collect")
mod.metricsPath = flags.MustString("prometheus-metrics-path")
@@ -179,7 +187,7 @@ func (mod *Prometheus) Routes() ([]api.Route, error) {
{
Method: http.MethodGet,
Path: mod.metricsPath,
DisableTelemetry: mod.disableRouteLogging,
DisableTelemetry: mod.disableRouteTelemetry,
Handler: echo.WrapHandler(
promhttp.HandlerFor(mod.registry, promhttp.HandlerOpts{}),
),