From 96be5ffa3c5f6c11d61c35ec612de7c7d3075e4f Mon Sep 17 00:00:00 2001 From: LeoZ Date: Fri, 19 Jul 2024 14:35:48 -0400 Subject: [PATCH] server: add configuration to for changing service name on OpenTelemetry (#1371) Currently, the OpenTelemetry service name for svix-server is hardcoded to "svix_server". This lack of configurability limits the flexibility for users who want to customize the service name in their OpenTelemetry setup, especially in environments where multiple services are being monitored, like having several servers in "worker mode". This change aims to provide users with the ability to set a custom OpenTelemetry service name, for better integration with their existing monitoring, observability infrastructure or naming convention. The solution implements a configurable OpenTelemetry service name for svix-server: 1. Added a new configuration option `opentelemetry_service_name` in the `ConfigurationInner` struct. 2. Updated the default configuration file (`config.default.toml`) to include the new option with a comment explaining its usage. 3. Modified the `setup_tracing` function to use the configured service name when setting up OpenTelemetry. Users can set a custom OpenTelemetry service name through configuration files or environment variables (e.g., `SVIX_OPENTELEMETRY_SERVICE_NAME`). If not specified, it defaults to "svix_server" to maintain backward compatibility. --- server/svix-server/config.default.toml | 3 +++ server/svix-server/src/cfg.rs | 2 ++ server/svix-server/src/lib.rs | 5 ++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/server/svix-server/config.default.toml b/server/svix-server/config.default.toml index 68d0ea9e4..c8dc27387 100644 --- a/server/svix-server/config.default.toml +++ b/server/svix-server/config.default.toml @@ -39,6 +39,9 @@ log_format = "default" # always sending. If the OpenTelemetry address is not set, this will do nothing. # opentelemetry_sample_ratio = 1.0 +# The name of the service to use when sending spans to OpenTelemetry. +opentelemetry_service_name = "svix_server" + # The Sentry DSN to use for error reporting. Disabled when omitted/null # sentry_dsn = "https://somedsn.ingest.sentry.io/12345" diff --git a/server/svix-server/src/cfg.rs b/server/svix-server/src/cfg.rs index 3e6fae0c4..0f2284af1 100644 --- a/server/svix-server/src/cfg.rs +++ b/server/svix-server/src/cfg.rs @@ -109,6 +109,8 @@ pub struct ConfigurationInner { /// The ratio at which to sample spans when sending to OpenTelemetry. When not given it defaults /// to always sending. If the OpenTelemetry address is not set, this will do nothing. pub opentelemetry_sample_ratio: Option, + /// The service name to use for OpenTelemetry. If not provided, it defaults to "svix_server". + pub opentelemetry_service_name: String, /// Whether to enable the logging of the databases at the configured log level. This may be /// useful for analyzing their response times. pub db_tracing: bool, diff --git a/server/svix-server/src/lib.rs b/server/svix-server/src/lib.rs index 6b20376b5..6a0689642 100644 --- a/server/svix-server/src/lib.rs +++ b/server/svix-server/src/lib.rs @@ -270,7 +270,10 @@ pub fn setup_tracing( .unwrap_or(opentelemetry_sdk::trace::Sampler::AlwaysOn), ) .with_resource(opentelemetry_sdk::Resource::new(vec![ - opentelemetry::KeyValue::new("service.name", "svix_server"), + opentelemetry::KeyValue::new( + "service.name", + cfg.opentelemetry_service_name.clone(), + ), ])), ) .install_batch(Tokio)