Skip to content

Commit

Permalink
chore: update OTel deps to latest (api@1.6.0) (#3622)
Browse files Browse the repository at this point in the history
This adds a script update-otel-deps.js to assist with this
because it is finnicky.
  • Loading branch information
trentm authored Sep 14, 2023
1 parent e07d826 commit 472cbb8
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 113 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ See the <<upgrade-to-v4>> guide.
[float]
===== Features
* Update <<opentelemetry-bridge>> support to `@opentelemetry/api` version 1.6.0.
{pull}3622[#3622]
[float]
===== Bug fixes
[float]
===== Chores
- Changes to cloud metadata collection for Google Cloud (GCP). Most notably
* Changes to cloud metadata collection for Google Cloud (GCP). Most notably
the `cloud.project.id` field is now the `project-id` from
https://cloud.google.com/compute/docs/metadata/default-metadata-values#project_metadata
rather than the `numeric-project-id`. This matches the value produced by
Expand Down
124 changes: 124 additions & 0 deletions dev-utils/update-otel-deps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#!/usr/bin/env node

/*
* Copyright Elasticsearch B.V. and other contributors where applicable.
* Licensed under the BSD 2-Clause License; you may not use this file except in
* compliance with the BSD 2-Clause License.
*/

'use strict';

// Update OTel deps in the various package-lock.json and .tav.yml files; and
// in the supported-technologies.asciidoc file.
//
// Usage:
// node dev-utils/update-otel-deps.js

const assert = require('assert');
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');

const semver = require('semver');

const TOP = path.resolve(__dirname, '..');

// ---- support functions

function latestPkgVer(pkgName) {
const latest = execSync(`npm info ${pkgName} dist-tags.latest`, {
encoding: 'utf8',
}).trimEnd();
assert(latest);
return latest;
}

async function updateOTelDeps() {
const gitFiles = execSync('git ls-files', {
cwd: TOP,
encoding: 'utf8',
}).split('\n');

const packageJsonFiles = gitFiles.filter(
(f) => path.basename(f) === 'package.json',
);
for (const pjFile of packageJsonFiles) {
const pjAbspath = path.join(TOP, pjFile);
const pj = JSON.parse(fs.readFileSync(pjAbspath));
const otelDeps = [
Object.keys(pj.dependencies || {}).filter((d) =>
d.startsWith('@opentelemetry/'),
),
Object.keys(pj.devDependencies || {}).filter((d) =>
d.startsWith('@opentelemetry/'),
),
].flat();
if (otelDeps.length === 0) {
continue;
}
const cmd = `npm update ${otelDeps.join(' ')}`;
console.log('%s: update %d OTel deps: `%s`', pjFile, otelDeps.length, cmd);
execSync(cmd, { cwd: path.dirname(pjAbspath) });
}

const hasOTelApiBlock = /^"@opentelemetry\/api":/m;
// The `d` RegExp flag requires at least Node.js 16.0.0.
const otelApiBlock =
/^"@opentelemetry\/api":\n\s+versions: '>=[\d.]+ <([\d.]+)'/dm;
// If the current latest is '1.2.3', this will return '1.3.0'.
const nextOTelApiMinor = semver.inc(
latestPkgVer('@opentelemetry/api'),
'minor',
);
const tavYmlFiles = gitFiles.filter((f) => path.basename(f) === '.tav.yml');
for (const tyFile of tavYmlFiles) {
let tyAbspath = path.resolve(TOP, tyFile);
let content = fs.readFileSync(tyAbspath, { encoding: 'utf8' });
if (!hasOTelApiBlock.test(content)) {
continue;
}
const match = otelApiBlock.exec(content);
if (!match) {
throw new Error(
`could not parse "@opentelemetry/api" block in "${tyFile}`,
);
}
if (match[1] === nextOTelApiMinor) {
continue;
}
console.log('%s: update @opentelemetry/api version range', tyFile);
content =
content.slice(0, match.indices[1][0]) +
nextOTelApiMinor +
content.slice(match.indices[1][1]);
fs.writeFileSync(tyAbspath, content, { encoding: 'utf8' });
}

// | <<opentelemetry-bridge,@opentelemetry/api>> | >=1.0.0 <1.5.0
const docFile = 'docs/supported-technologies.asciidoc';
const docAbspath = path.resolve(TOP, docFile);
const otelApiDocBlock = /@opentelemetry\/api>> \| >=[\d.]+ <([\d.]+)$/dm;
let content = fs.readFileSync(docAbspath, { encoding: 'utf8' });
const match = otelApiDocBlock.exec(content);
if (!match) {
throw new Error(`could not parse "@opentelemetry/api" block in ${docFile}`);
}
if (match[1] !== nextOTelApiMinor) {
console.log('%s: update @opentelemetry/api version range', docFile);
content =
content.slice(0, match.indices[1][0]) +
nextOTelApiMinor +
content.slice(match.indices[1][1]);
fs.writeFileSync(docAbspath, content, { encoding: 'utf8' });
}
}

// ---- mainline

async function main() {
await updateOTelDeps();
}

if (require.main === module) {
main();
}
2 changes: 1 addition & 1 deletion docs/supported-technologies.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Metrics API and Metrics SDK to allow
[options="header"]
|=======================================================================
| Framework | Version
| <<opentelemetry-bridge,@opentelemetry/api>> | >=1.0.0 <1.5.0
| <<opentelemetry-bridge,@opentelemetry/api>> | >=1.0.0 <1.7.0
| https://www.npmjs.com/package/@opentelemetry/sdk-metrics[@opentelemetry/sdk-metrics] | >=1.11.0 <2
|=======================================================================

Expand Down
4 changes: 2 additions & 2 deletions examples/opentelemetry-bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"dependencies": {
"@opentelemetry/api": "^1.4.0",
"@opentelemetry/core": "^1.11.0",
"@opentelemetry/instrumentation": "^0.41.0",
"@opentelemetry/instrumentation-http": "^0.41.0",
"@opentelemetry/instrumentation": ">=0.41.0 <2",
"@opentelemetry/instrumentation-http": ">=0.41.0 <2",
"@opentelemetry/sdk-trace-base": "^1.11.0",
"@opentelemetry/sdk-trace-node": "^1.11.0",
"elastic-apm-node": "file:../.."
Expand Down
2 changes: 1 addition & 1 deletion examples/opentelemetry-metrics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"dependencies": {
"@opentelemetry/api": "^1.4.1",
"@opentelemetry/exporter-prometheus": "^0.41.0",
"@opentelemetry/exporter-prometheus": ">=0.41.0 <2",
"@opentelemetry/sdk-metrics": "^1.12.0",
"elastic-apm-node": "file:../.."
}
Expand Down
86 changes: 43 additions & 43 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/opentelemetry-bridge/.tav.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"@opentelemetry/api":
versions: '>=1.0.0 <1.5.0'
versions: '>=1.0.0 <1.7.0'
node: '>=8.0.0'
commands:
- node OTelBridgeNonRecordingSpan.test.js
Expand Down
12 changes: 6 additions & 6 deletions test/opentelemetry-bridge/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/opentelemetry-metrics/fixtures/.tav.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"@opentelemetry/api":
versions: '>=1.3.0 <1.5.0'
versions: '>=1.3.0 <1.7.0'
node: '>=14.0.0'
commands:
- node ../fixtures.test.js
Expand Down
Loading

0 comments on commit 472cbb8

Please sign in to comment.