Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: #209 add custom attibutes from config for metrics & traces #210

Merged
merged 3 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading