diff --git a/.changesets/default-service-name-to-app.md b/.changesets/default-service-name-to-app.md new file mode 100644 index 00000000..01137bc4 --- /dev/null +++ b/.changesets/default-service-name-to-app.md @@ -0,0 +1,7 @@ +--- +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/.changesets/report-host-name-when-set-to-none.md b/.changesets/report-host-name-when-set-to-none.md new file mode 100644 index 00000000..ec808c7e --- /dev/null +++ b/.changesets/report-host-name-when-set-to-none.md @@ -0,0 +1,8 @@ +--- +bump: patch +type: fix +--- + +Report `unknown` as the host name in collector mode when the `hostname` +configuration option is set to `None`. Apps that set it that way reported no +host name at all. diff --git a/src/appsignal/opentelemetry.py b/src/appsignal/opentelemetry.py index 5d71ab04..58c01e06 100644 --- a/src/appsignal/opentelemetry.py +++ b/src/appsignal/opentelemetry.py @@ -288,10 +288,10 @@ def _resource(config: Config) -> Resource: "appsignal.config.name": config.options.get("name"), "appsignal.config.environment": config.options.get("environment"), "appsignal.config.push_api_key": config.options.get("push_api_key"), - "appsignal.config.revision": config.options.get("revision", "unknown"), + "appsignal.config.revision": config.options.get("revision") or "unknown", "appsignal.config.language_integration": "python", - "service.name": config.options.get("service_name", "unknown"), - "host.name": config.options.get("hostname", "unknown"), + "service.name": config.options.get("service_name") or "app", + "host.name": config.options.get("hostname") or "unknown", "appsignal.service.process_id": os.getpid(), "appsignal.config.filter_attributes": config.options.get( "filter_attributes" diff --git a/tests/test_config.py b/tests/test_config.py index adfc4694..c75db2b8 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -341,7 +341,7 @@ def test_opentelemetry_resource_with_defaults(): # Test default values assert resource.attributes["appsignal.config.revision"] == "unknown" - assert resource.attributes["service.name"] == "unknown" + assert resource.attributes["service.name"] == "app" assert resource.attributes["appsignal.config.language_integration"] == "python" # Test that None values are excluded @@ -349,6 +349,17 @@ def test_opentelemetry_resource_with_defaults(): assert "appsignal.config.push_api_key" not in resource.attributes +def test_opentelemetry_resource_with_none_values(): + from appsignal.opentelemetry import _resource + + config = Config(Options(revision=None, service_name=None, hostname=None)) + resource = _resource(config) + + assert resource.attributes["appsignal.config.revision"] == "unknown" + assert resource.attributes["service.name"] == "app" + assert resource.attributes["host.name"] == "unknown" + + def test_set_private_environ_valid_log_path(): cwdir = os.getcwd() config = Config(Options(log_path=cwdir))