Skip to content

Commit c74f0d3

Browse files
authored
feat: check versions of @opentelemetry dependencies (#330)
1 parent b1ba9cc commit c74f0d3

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
1010

1111
- Skip instrumentation of HANA driver, if it does it itself
1212
- `telemetry-to-otlp`: Automatically switch to `gRPC` (from default `http/protobuf`) when exporting to an endpoint with port `4317`
13+
- Version check for `@opentelemetry` dependencies (OpenTelemetry SDK 2.0 is not yet supported)
1314

1415
### Changed
1516

cds-plugin.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
1-
let _startup = true
1+
;(() => {
2+
const cds = require('@sap/cds')
3+
if (!(cds.cli?.command in { '': 1, serve: 1, run: 1 })) return
24

3-
const cds = require('@sap/cds')
4-
if (!(cds.cli?.command in { '': 1, serve: 1, run: 1 })) _startup = false
5+
// cds add XXX currently also has cli.command === ''
6+
const i = process.argv.indexOf('add')
7+
if (i > 1 && process.argv[i - 1].match(/cds(\.js)?$/)) return
58

6-
// cds add XXX currently also has cli.command === ''
7-
const i = process.argv.indexOf('add')
8-
if (i > 1 && process.argv[i - 1].match(/cds(\.js)?$/)) _startup = false
9+
if (!!process.env.NO_TELEMETRY && process.env.NO_TELEMETRY !== 'false') return
910

10-
if (!!process.env.NO_TELEMETRY && process.env.NO_TELEMETRY !== 'false') _startup = false
11+
// check versions of @opentelemetry dependencies
12+
const { dependencies } = require(require('path').join(cds.root, 'package'))
13+
let violations = []
14+
for (const each in dependencies) {
15+
if (!each.match(/^@opentelemetry\//)) continue
16+
const { version } = require(`${each}/package.json`)
17+
const [major, minor] = version.split('.')
18+
if (major >= 2 || minor >= 200) violations.push(`${each}@${version}`)
19+
}
20+
if (violations.length) {
21+
const msg =
22+
'@cap-js/telemetry does not yet support OpenTelemetry SDK 2.0 (^2 and ^0.200):' +
23+
`\n - ${violations.join('\n - ')}\n`
24+
throw new Error(msg)
25+
}
1126

12-
if (_startup) require('./lib')()
27+
require('./lib')()
28+
})()

0 commit comments

Comments
 (0)