Skip to content

Commit c28393e

Browse files
authored
feat: skip instrumentation of HANA driver, if it does it itself (#305)
1 parent 222f9b5 commit c28393e

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
88

99
### Added
1010

11+
- Skip instrumentation of HANA driver, if it does it itself
12+
1113
### Changed
1214

1315
- By default, `@cap-js/hana`'s promisification of the driver API is wrapped

lib/tracing/cds.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,17 @@ module.exports = () => {
8282
if (impl?.match(/^@cap-js\//)) {
8383
cds.once('served', () => {
8484
// HANA
85-
if (impl === '@cap-js/hana' && cds.env.requires.telemetry.tracing._hana_prom) {
85+
if (impl === '@cap-js/hana') {
8686
try {
87+
// REVISIT: when telemetry and hana are loaded from different places this doesn't work
88+
const hanaDriver = require('@cap-js/hana/lib/drivers/base.js')
89+
90+
// driver does instrumentation itself?
91+
if (hanaDriver.isOpenTelemetrySupported) return
92+
93+
// wrap promisified HANA driver
8794
const [major, minor] = require('@cap-js/hana/package.json').version.split('.')
88-
if (major > 1 || (major === 1 && minor >= 7)) {
89-
// REVISIT: when telemetry and hana are loaded from differen places this doesn't work
90-
const hanaDriver = require('@cap-js/hana/lib/drivers/base.js')
95+
if (cds.env.requires.telemetry.tracing._hana_prom && (major > 1 || (major === 1 && minor >= 7))) {
9196
const _prom = hanaDriver.prom
9297
hanaDriver.prom = function (dbc, func) {
9398
const fn = _prom(dbc, func)
@@ -100,11 +105,11 @@ module.exports = () => {
100105
return
101106
}
102107
} catch (err) {
103-
LOG._warning && LOG.warning('Failed to wrap hana driver due to error:', err)
108+
LOG._warn && LOG.warn('Failed to wrap hana driver due to error:', err)
104109
}
105110
}
106111

107-
// other DBs
112+
// other DBs (or non-promisified HANA driver)
108113
const dbService = cds.db.constructor
109114
const { prepare: _prepare, exec: _exec } = dbService.prototype
110115
dbService.prototype.prepare = wrap(_prepare, {

0 commit comments

Comments
 (0)