Skip to content

Commit

Permalink
feat: #209 add custom attibutes from config for metrics & traces (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
moronyoh authored Jan 24, 2025
1 parent 4ed269b commit 5818ca1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
7 changes: 5 additions & 2 deletions modules/core/src/main/scala/pillars/Observability.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions modules/docs/src/docs/user-guide/20_features/50_observability.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions modules/example/src/main/resources/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ admin:
observability:
enabled: true
service-name: bookstore
custom-attributes:
datacenter: ${DATACENTER}
metrics:
enabled: true
traces:
Expand Down

0 comments on commit 5818ca1

Please sign in to comment.