diff --git a/modules/core/src/main/scala/pillars/Observability.scala b/modules/core/src/main/scala/pillars/Observability.scala index 7ca99d67d..00b070529 100644 --- a/modules/core/src/main/scala/pillars/Observability.scala +++ b/modules/core/src/main/scala/pillars/Observability.scala @@ -56,7 +56,7 @@ object Observability: OtelAttributes( appInfo.name.toAttribute("service.name"), appInfo.version.toAttribute("service.version") - ) + ) ++ config.getCustomAttributes ) resource.mergeUnsafe(configured) sdk = otel4s.sdk @@ -74,9 +74,12 @@ object Observability: enabled: Boolean = false, metrics: Config.Metrics = Config.Metrics(), traces: Config.Traces = Config.Traces(), - serviceName: ServiceName = ServiceName("pillars") + serviceName: ServiceName = ServiceName("pillars"), + customAttributes: Map[String, String] = Map.empty ) extends pillars.Config: def isEnabled: Boolean = enabled && (metrics.enabled || traces.enabled) + + def getCustomAttributes: Seq[Attribute[String]] = customAttributes.map((k, v) => v.toAttribute(k)).toSeq end Config object Config: diff --git a/modules/docs/src/docs/user-guide/20_features/50_observability.adoc b/modules/docs/src/docs/user-guide/20_features/50_observability.adoc index 39aebb4d2..d249a45a4 100644 --- a/modules/docs/src/docs/user-guide/20_features/50_observability.adoc +++ b/modules/docs/src/docs/user-guide/20_features/50_observability.adoc @@ -24,6 +24,19 @@ You can configure the following settings in the `application.conf` file: include::{projectRootDir}/modules/example/src/main/resources/config.yaml[tag=observability] ---- +=== Global attributes + +By default, the following attributes are added to all metrics & traces: + +[cols="1,1,1"] +|=== +| Attribute | Description | Type + +| `service.name` | The service name coming from AppInfo | String +| `service.version` | The service version also coming from AppInfo | String +|=== + +With the config `custom-attributes` you can add custom attributes to all metrics & traces === Metrics diff --git a/modules/example/src/main/resources/config.yaml b/modules/example/src/main/resources/config.yaml index 0f49d105a..5bca9fe6f 100644 --- a/modules/example/src/main/resources/config.yaml +++ b/modules/example/src/main/resources/config.yaml @@ -77,6 +77,8 @@ admin: observability: enabled: true service-name: bookstore + custom-attributes: + datacenter: ${DATACENTER} metrics: enabled: true traces: