Skip to content

Commit ae3e619

Browse files
authored
feat: custom resource attributes (#394)
1 parent b185c16 commit ae3e619

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org/).
55
The format is based on [Keep a Changelog](http://keepachangelog.com/).
66

7-
## Version 1.5.5 - 2025-11-XX
7+
## Version 1.6.0 - 2025-11-XX
8+
9+
### Added
10+
11+
- Provide custom resource attributes via `cds.requires.telemetry.resource.attributes`
812

913
### Fixed
1014

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Documentation can be found at [cap.cloud.sap](https://cap.cloud.sap/docs) and [o
3434
- [`telemetry-to-otlp`](#telemetry-to-otlp)
3535
- [Detailed Configuration Options](#detailed-configuration-options)
3636
- [Configuration Pass Through](#configuration-pass-through)
37+
- [Resource Attributes](#resource-attributes)
3738
- [Instrumentations](#instrumentations)
3839
- [Sampler](#sampler)
3940
- [Propagators](#propagators)
@@ -367,6 +368,23 @@ For example, it is possible to specify the `temporalityPreference` setting of th
367368
```
368369

369370

371+
### Resource Attributes
372+
373+
Resource attributes describe the entity producing telemetry.
374+
See [Resources](https://opentelemetry.io/docs/concepts/resources) and [Resource semantic conventions](https://opentelemetry.io/docs/specs/semconv/resource) for more details.
375+
376+
`@cap-js/telemetry` automatically derives resource attributes from the app's info (`package.json`) as well as the app's environment ().
377+
You can configure additional attributes or also overwrite the derived attributes via `cds.requires.telemetry.resource.attributes = { <key>: <value>, ... }`
378+
379+
Example:
380+
```json
381+
{
382+
"service.version": "1.2.3",
383+
"my.custom.attribute": "foo"
384+
}
385+
```
386+
387+
370388
### Instrumentations
371389

372390
Configure via `cds.requires.telemetry.instrumentations = { <name>: { module, class, config? } }`

lib/utils.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ function getResource() {
7272
attributes['sap.cf.process.type'] = VCAP_APPLICATION.process_type
7373
}
7474

75+
if (cds.env.requires.telemetry?.resource?.attributes)
76+
Object.assign(attributes, cds.env.requires.telemetry.resource.attributes)
77+
7578
return new Resource(attributes)
7679
}
7780

0 commit comments

Comments
 (0)