From a396e420f353d57ed33e8011b3a906f872d1c94d Mon Sep 17 00:00:00 2001 From: "artur.shiriev" Date: Wed, 11 Dec 2024 13:51:19 +0300 Subject: [PATCH] allow service name redefine for OTL --- README.md | 2 ++ microbootstrap/instruments/opentelemetry_instrument.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b1da8fe..be5b6e8 100644 --- a/README.md +++ b/README.md @@ -301,6 +301,7 @@ class YourSettings(BaseServiceSettings): service_name: str service_version: str + opentelemetry_service_name: str | None = None opentelemetry_container_name: str | None = None opentelemetry_endpoint: str | None = None opentelemetry_namespace: str | None = None @@ -315,6 +316,7 @@ Parameters description: - `service_name` - will be passed to the `Resource`. - `service_version` - will be passed to the `Resource`. +- `opentelemetry_service_name` - if provided, will be passed to the `Resource` instead of `service_name`. - `opentelemetry_endpoint` - will be passed to `OTLPSpanExporter` as endpoint. - `opentelemetry_namespace` - will be passed to the `Resource`. - `opentelemetry_insecure` - is opentelemetry connection secure. diff --git a/microbootstrap/instruments/opentelemetry_instrument.py b/microbootstrap/instruments/opentelemetry_instrument.py index 8e0a90f..393e1b4 100644 --- a/microbootstrap/instruments/opentelemetry_instrument.py +++ b/microbootstrap/instruments/opentelemetry_instrument.py @@ -22,6 +22,7 @@ class OpentelemetryConfig(BaseInstrumentConfig): service_name: str = "micro-service" service_version: str = "1.0.0" + opentelemetry_service_name: str | None = None opentelemetry_container_name: str | None = None opentelemetry_endpoint: str | None = None opentelemetry_namespace: str | None = None @@ -52,7 +53,8 @@ def teardown(self) -> None: def bootstrap(self) -> None: resource: typing.Final = resources.Resource.create( attributes={ - resources.SERVICE_NAME: self.instrument_config.service_name, + resources.SERVICE_NAME: self.instrument_config.opentelemetry_service_name + or self.instrument_config.service_name, resources.TELEMETRY_SDK_LANGUAGE: "python", resources.SERVICE_NAMESPACE: self.instrument_config.opentelemetry_namespace, # type: ignore[dict-item] resources.SERVICE_VERSION: self.instrument_config.service_version,