diff --git a/.changesets/default-service-name-to-app.md b/.changesets/default-service-name-to-app.md new file mode 100644 index 000000000..02757ca60 --- /dev/null +++ b/.changesets/default-service-name-to-app.md @@ -0,0 +1,6 @@ +--- +bump: patch +type: change +--- + +Report `app` instead of `unknown` as the OpenTelemetry service name when the `service_name` configuration option is not set and collector mode is in use. diff --git a/lib/appsignal/opentelemetry.rb b/lib/appsignal/opentelemetry.rb index 4ee32b739..c3422d3e0 100644 --- a/lib/appsignal/opentelemetry.rb +++ b/lib/appsignal/opentelemetry.rb @@ -212,10 +212,12 @@ def shutdown # Build the OpenTelemetry Resource that carries AppSignal config to the # collector. Attributes whose underlying option is nil or an empty array - # are omitted so the collector applies its own defaults. + # are omitted so the collector applies its own defaults. The revision, + # service name and host name are the exception: they fall back to a + # value here, so they are always sent. def build_resource(config) revision = config[:revision].to_s.empty? ? "unknown" : config[:revision] - service_name = config[:service_name].to_s.empty? ? "unknown" : config[:service_name] + service_name = config[:service_name].to_s.empty? ? "app" : config[:service_name] host_name = config[:hostname].to_s.empty? ? "unknown" : config[:hostname] attrs = { diff --git a/spec/lib/appsignal/opentelemetry_spec.rb b/spec/lib/appsignal/opentelemetry_spec.rb index d61d2466d..ce3b7a880 100644 --- a/spec/lib/appsignal/opentelemetry_spec.rb +++ b/spec/lib/appsignal/opentelemetry_spec.rb @@ -364,7 +364,7 @@ def with_leaked_ambient_context .to eq(["IgnoredController#action"]) end - it "falls back to 'unknown' for empty revision, service_name, and hostname" do + it "falls back to defaults for empty revision, service_name, and hostname" do # Other specs in the suite set `ENV["APP_REVISION"]` without clearing # it (the spec_helper before-block only resets APPSIGNAL_* and # _APPSIGNAL_* prefixed vars). Clear it locally so this test is @@ -385,7 +385,7 @@ def with_leaked_ambient_context attrs = resource_attrs(resource) expect(attrs["appsignal.config.revision"]).to eq("unknown") - expect(attrs["service.name"]).to eq("unknown") + expect(attrs["service.name"]).to eq("app") expect(attrs["host.name"]).to eq("unknown") end