Skip to content

Honour OTEL_SERVICE_NAME and send service_version as the Sentry release - #373

Merged
lesnik512 merged 1 commit into
mainfrom
service-name-version-defaults
Oct 29, 2026
Merged

lesnik512 merged 1 commit into
mainfrom
service-name-version-defaults

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Closes #320.

service_name and service_version now default to None instead of "micro-service" and "1.0.0".

  • OpenTelemetry: an unset name or version stays out of the resource, so the SDK takes it from OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES. With neither set, the name is unknown_service. _build_resource already dropped empty values, so it needed no change.
  • Sentry: a service_version that is set goes to sentry_sdk.init as release. An unset one adds no release key, and sentry-sdk falls back to SENTRY_RELEASE, the git revision or CI variables, as before. sentry_additional_params can still override it.

Some readers need a string: FastAPI's title and version, Litestar's OpenAPI title and version, Litestar's Prometheus app_name, the health-check body, and Pyroscope's application_name. They read two new BaseConfig properties, service_name_or_default and service_version_or_default, which fall back to the old strings. You chose that, so for these readers nothing changes from 1.x. The issue's breaking-change list assumed they would get a new fallback.

Tests

Written first. These failed on main:

  • test_opentelemetry_service_name_falls_back_to_otel_service_name[config0-from-env]: with OTEL_SERVICE_NAME set and a default config, the resource had micro-service. This was test_opentelemetry_configured_service_name_wins_over_env. I renamed it because the default case now expects the variable's value. The configured cases are unchanged.
  • test_opentelemetry_service_version_falls_back_to_otel_resource_attributes[None-from-env]: OTEL_RESOURCE_ATTRIBUTES=service.version=... was overridden by 1.0.0.
  • test_sentry_release_follows_service_version[service-version] and [service-version-wins-over-env]: no release was passed.
  • test_service_name_and_version_fall_back_for_readers_that_need_a_string: the properties are new.
  • test_from_object_skips_missing_attribute and test_from_dict_drops_unknown_keys_silently: they assert the defaults, which are now None.

test_sentry_release_follows_service_version[env-when-unset] covers SENTRY_RELEASE with a default config. It passed on main and still does.

These pin the fallback for the string readers and passed on main too: test_built_app_title_and_version_fall_back_when_unset (FastAPI), test_litestar_openapi_and_prometheus_fall_back_to_default_service_name, and test_pyroscope_application_name_falls_back_when_service_name_unset. The health-check body was already covered by test_healthchecks_render_data_default.

test_from_object_skips_none_attribute and test_from_dict_explicit_none_overrides_default used service_name to show that None is skipped or overrides a default. Once the default is None they could no longer tell the difference, so they use service_debug now.

The full suite passes, 588 tests at 100% coverage (just test-ci). just lint (including ty), just adr-check and just docs-build pass too. No floor changes.

Docs

configuration.md has a new "Service name and version" section covering what each backend does when the fields are unset. The Sentry section links to it. The resource paragraph that said OTEL_SERVICE_NAME gets overridden is replaced.

Breaking changes

  • If you never set service_name, service.name now comes from OTEL_SERVICE_NAME where it is set, and is unknown_service otherwise. Before, it was micro-service.
  • If you never set service_version, service.version is gone from the resource unless OTEL_RESOURCE_ATTRIBUTES sets it.
  • If you set service_version, Sentry now gets it as the release, in place of the one sentry-sdk would pick, including SENTRY_RELEASE.
  • Code that reads config.service_name or config.service_version can now get None. Use service_name_or_default and service_version_or_default for the old values.

@lesnik512 lesnik512 added this to the 2.0.0 milestone Oct 29, 2026
@lesnik512
lesnik512 merged commit 02d3b22 into main Oct 29, 2026
37 checks passed
@lesnik512
lesnik512 deleted the service-name-version-defaults branch October 29, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Honour OTEL_SERVICE_NAME and send service_version as the Sentry release

1 participant