|
1 | | -let _startup = true |
| 1 | +;(() => { |
| 2 | + const cds = require('@sap/cds') |
| 3 | + if (!(cds.cli?.command in { '': 1, serve: 1, run: 1 })) return |
2 | 4 |
|
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 |
5 | 8 |
|
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 |
9 | 10 |
|
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 | + } |
11 | 26 |
|
12 | | -if (_startup) require('./lib')() |
| 27 | + require('./lib')() |
| 28 | +})() |
0 commit comments