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

@@ -30,6 +30,9 @@ API_DOWNLOAD_FROM_DENY_LIST=
API_DOWNLOAD_FROM_MAX_RETRY=4 API_DOWNLOAD_FROM_MAX_RETRY=4
API_DISABLE_DOWNLOAD_FROM=false API_DISABLE_DOWNLOAD_FROM=false
API_DISABLE_HEALTH_CHECK_ROUTE_TELEMETRY=false API_DISABLE_HEALTH_CHECK_ROUTE_TELEMETRY=false
API_DISABLE_ROOT_ROUTE_TELEMETRY=false
API_DISABLE_DEBUG_ROUTE_TELEMETRY=false
API_DISABLE_VERSION_ROUTE_TELEMETRY=false
API_ENABLE_DEBUG_ROUTE=false API_ENABLE_DEBUG_ROUTE=false
CHROMIUM_RESTART_AFTER=100 CHROMIUM_RESTART_AFTER=100
CHROMIUM_MAX_QUEUE_SIZE=0 CHROMIUM_MAX_QUEUE_SIZE=0
@@ -76,6 +79,7 @@ PDFENGINES_EMBED_ENGINES=pdfcpu
PROMETHEUS_NAMESPACE=gotenberg PROMETHEUS_NAMESPACE=gotenberg
PROMETHEUS_COLLECT_INTERVAL=1s PROMETHEUS_COLLECT_INTERVAL=1s
PROMETHEUS_DISABLE_ROUTE_LOGGING=false PROMETHEUS_DISABLE_ROUTE_LOGGING=false
PROMETHEUS_DISABLE_ROUTE_TELEMETRY=false
PROMETHEUS_DISABLE_COLLECT=false PROMETHEUS_DISABLE_COLLECT=false
PROMETHEUS_METRICS_PATH=/prometheus/metrics PROMETHEUS_METRICS_PATH=/prometheus/metrics
OTEL_SERVICE_NAME=gotenberg OTEL_SERVICE_NAME=gotenberg

View File

@@ -32,6 +32,9 @@ services:
- "--api-download-from-max-retry=${API_DOWNLOAD_FROM_MAX_RETRY}" - "--api-download-from-max-retry=${API_DOWNLOAD_FROM_MAX_RETRY}"
- "--api-disable-download-from=${API_DISABLE_DOWNLOAD_FROM}" - "--api-disable-download-from=${API_DISABLE_DOWNLOAD_FROM}"
- "--api-disable-health-check-route-telemetry=${API_DISABLE_HEALTH_CHECK_ROUTE_TELEMETRY}" - "--api-disable-health-check-route-telemetry=${API_DISABLE_HEALTH_CHECK_ROUTE_TELEMETRY}"
- "--api-disable-root-route-telemetry=${API_DISABLE_ROOT_ROUTE_TELEMETRY}"
- "--api-disable-debug-route-telemetry=${API_DISABLE_DEBUG_ROUTE_TELEMETRY}"
- "--api-disable-version-route-telemetry=${API_DISABLE_VERSION_ROUTE_TELEMETRY}"
- "--api-enable-debug-route=${API_ENABLE_DEBUG_ROUTE}" - "--api-enable-debug-route=${API_ENABLE_DEBUG_ROUTE}"
- "--chromium-restart-after=${CHROMIUM_RESTART_AFTER}" - "--chromium-restart-after=${CHROMIUM_RESTART_AFTER}"
- "--chromium-auto-start=${CHROMIUM_AUTO_START}" - "--chromium-auto-start=${CHROMIUM_AUTO_START}"
@@ -78,6 +81,7 @@ services:
- "--prometheus-namespace=${PROMETHEUS_NAMESPACE}" - "--prometheus-namespace=${PROMETHEUS_NAMESPACE}"
- "--prometheus-collect-interval=${PROMETHEUS_COLLECT_INTERVAL}" - "--prometheus-collect-interval=${PROMETHEUS_COLLECT_INTERVAL}"
- "--prometheus-disable-route-logging=${PROMETHEUS_DISABLE_ROUTE_LOGGING}" - "--prometheus-disable-route-logging=${PROMETHEUS_DISABLE_ROUTE_LOGGING}"
- "--prometheus-disable-route-telemetry=${PROMETHEUS_DISABLE_ROUTE_TELEMETRY}"
- "--prometheus-disable-collect=${PROMETHEUS_DISABLE_COLLECT}" - "--prometheus-disable-collect=${PROMETHEUS_DISABLE_COLLECT}"
- "--prometheus-metrics-path=${PROMETHEUS_METRICS_PATH}" - "--prometheus-metrics-path=${PROMETHEUS_METRICS_PATH}"
- "--webhook-enable-sync-mode=${WEBHOOK_ENABLE_SYNC_MODE}" - "--webhook-enable-sync-mode=${WEBHOOK_ENABLE_SYNC_MODE}"

View File

@@ -41,6 +41,9 @@ type Api struct {
basicAuthPassword string basicAuthPassword string
downloadFromCfg downloadFromConfig downloadFromCfg downloadFromConfig
disableHealthCheckRouteTelemetry bool disableHealthCheckRouteTelemetry bool
disableRootRouteTelemetry bool
disableDebugRouteTelemetry bool
disableVersionRouteTelemetry bool
enableDebugRoute bool enableDebugRoute bool
routes []Route routes []Route
@@ -197,6 +200,9 @@ func (a *Api) Descriptor() gotenberg.ModuleDescriptor {
fs.Int("api-download-from-max-retry", 4, "Set the maximum number of retries for the download from feature") fs.Int("api-download-from-max-retry", 4, "Set the maximum number of retries for the download from feature")
fs.Bool("api-disable-download-from", false, "Disable the download from feature") fs.Bool("api-disable-download-from", false, "Disable the download from feature")
fs.Bool("api-disable-health-check-route-telemetry", false, "Disable telemetry for health check route") fs.Bool("api-disable-health-check-route-telemetry", false, "Disable telemetry for health check route")
fs.Bool("api-disable-root-route-telemetry", false, "Disable telemetry for the root route")
fs.Bool("api-disable-debug-route-telemetry", false, "Disable telemetry for the debug route")
fs.Bool("api-disable-version-route-telemetry", false, "Disable telemetry for the version route")
fs.Bool("api-enable-debug-route", false, "Enable the debug route") fs.Bool("api-enable-debug-route", false, "Enable the debug route")
// Deprecated flags. // Deprecated flags.
@@ -235,6 +241,9 @@ func (a *Api) Provision(ctx *gotenberg.Context) error {
disable: flags.MustBool("api-disable-download-from"), disable: flags.MustBool("api-disable-download-from"),
} }
a.disableHealthCheckRouteTelemetry = flags.MustDeprecatedBool("api-disable-health-check-logging", "api-disable-health-check-route-telemetry") a.disableHealthCheckRouteTelemetry = flags.MustDeprecatedBool("api-disable-health-check-logging", "api-disable-health-check-route-telemetry")
a.disableRootRouteTelemetry = flags.MustBool("api-disable-root-route-telemetry")
a.disableDebugRouteTelemetry = flags.MustBool("api-disable-debug-route-telemetry")
a.disableVersionRouteTelemetry = flags.MustBool("api-disable-version-route-telemetry")
a.enableDebugRoute = flags.MustBool("api-enable-debug-route") a.enableDebugRoute = flags.MustBool("api-enable-debug-route")
// Port from env? // Port from env?
@@ -453,10 +462,19 @@ func (a *Api) Start() error {
} }
} }
// Check if the user wishes to disable telemetry for the health check route. // Check if the user wishes to disable telemetry for specific routes.
if a.disableHealthCheckRouteTelemetry { if a.disableHealthCheckRouteTelemetry {
disableTelemetryForPaths = append(disableTelemetryForPaths, "health") disableTelemetryForPaths = append(disableTelemetryForPaths, "health")
} }
if a.disableRootRouteTelemetry {
disableTelemetryForPaths = append(disableTelemetryForPaths, "")
}
if a.disableDebugRouteTelemetry {
disableTelemetryForPaths = append(disableTelemetryForPaths, "debug")
}
if a.disableVersionRouteTelemetry {
disableTelemetryForPaths = append(disableTelemetryForPaths, "version")
}
serverName := fmt.Sprintf("%s:%d", a.bindIp, a.port) serverName := fmt.Sprintf("%s:%d", a.bindIp, a.port)

View File

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

View File

@@ -58,7 +58,10 @@ Feature: /debug
"api-correlation-id-header": "Gotenberg-Trace", "api-correlation-id-header": "Gotenberg-Trace",
"api-disable-download-from": "false", "api-disable-download-from": "false",
"api-disable-health-check-logging": "false", "api-disable-health-check-logging": "false",
"api-disable-debug-route-telemetry": "false",
"api-disable-health-check-route-telemetry": "false", "api-disable-health-check-route-telemetry": "false",
"api-disable-root-route-telemetry": "false",
"api-disable-version-route-telemetry": "false",
"api-download-from-allow-list": "[]", "api-download-from-allow-list": "[]",
"api-download-from-deny-list": "[]", "api-download-from-deny-list": "[]",
"api-download-from-max-retry": "4", "api-download-from-max-retry": "4",
@@ -118,6 +121,7 @@ Feature: /debug
"prometheus-collect-interval": "1s", "prometheus-collect-interval": "1s",
"prometheus-disable-collect": "false", "prometheus-disable-collect": "false",
"prometheus-disable-route-logging": "false", "prometheus-disable-route-logging": "false",
"prometheus-disable-route-telemetry": "false",
"prometheus-namespace": "gotenberg", "prometheus-namespace": "gotenberg",
"prometheus-metrics-path": "/prometheus/metrics", "prometheus-metrics-path": "/prometheus/metrics",
"webhook-allow-list": "[]", "webhook-allow-list": "[]",
@@ -186,7 +190,10 @@ Feature: /debug
"api-correlation-id-header": "Gotenberg-Trace", "api-correlation-id-header": "Gotenberg-Trace",
"api-disable-download-from": "false", "api-disable-download-from": "false",
"api-disable-health-check-logging": "false", "api-disable-health-check-logging": "false",
"api-disable-debug-route-telemetry": "false",
"api-disable-health-check-route-telemetry": "false", "api-disable-health-check-route-telemetry": "false",
"api-disable-root-route-telemetry": "false",
"api-disable-version-route-telemetry": "false",
"api-download-from-allow-list": "[]", "api-download-from-allow-list": "[]",
"api-download-from-deny-list": "[]", "api-download-from-deny-list": "[]",
"api-download-from-max-retry": "4", "api-download-from-max-retry": "4",
@@ -246,6 +253,7 @@ Feature: /debug
"prometheus-collect-interval": "1s", "prometheus-collect-interval": "1s",
"prometheus-disable-collect": "false", "prometheus-disable-collect": "false",
"prometheus-disable-route-logging": "false", "prometheus-disable-route-logging": "false",
"prometheus-disable-route-telemetry": "false",
"prometheus-namespace": "gotenberg", "prometheus-namespace": "gotenberg",
"prometheus-metrics-path": "/prometheus/metrics", "prometheus-metrics-path": "/prometheus/metrics",
"webhook-allow-list": "[]", "webhook-allow-list": "[]",