Skip to content

Commit

Permalink
server: add configuration to for changing service name on OpenTelemet…
Browse files Browse the repository at this point in the history
…ry (#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.
  • Loading branch information
LeoZ100 authored Jul 19, 2024
1 parent 62e6e0d commit 96be5ff
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions server/svix-server/config.default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 2 additions & 0 deletions server/svix-server/src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<f64>,
/// 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,
Expand Down
5 changes: 4 additions & 1 deletion server/svix-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 96be5ff

Please sign in to comment.