Skip to content

Commit

Permalink
style changes to semconv changelog entry
Browse files Browse the repository at this point in the history
  • Loading branch information
trentm committed Jan 22, 2025
1 parent 3b786b1 commit fddc720
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 72 deletions.
149 changes: 92 additions & 57 deletions scripts/semconv/changelog-gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function summarizeChanges({prev, curr, prevSrc, currSrc}) {
// 'ns' is the "namespace". The value here is wrong for "FEATURE_FLAG",
// "GEN_AI", etc. But good enough for the usage below.
const ns = /^(ATTR_|METRIC_|)?([^_]+)_/.exec(k)[2];
changes.push({type: 'new', k, v: curr[k], ns});
changes.push({type: 'added', k, v: curr[k], ns});
} else if (valChanged(curr[k], prev[k])) {
changes.push({type: 'changed', k, v: curr[k], prevV: prev[k]});
} else {
Expand All @@ -121,39 +121,44 @@ function summarizeChanges({prev, curr, prevSrc, currSrc}) {
}
}

// Create a summary of changes, grouped by change type.
const summary = [];
const execSummary = [];
// Create a set of summaries, one for each change type.
let haveChanges = changes.length > 0;
const summaryFromChangeType = {
removed: [],
changed: [],
deprecated: [],
added: [],
}
const execSummaryFromChangeType = {
removed: null,
changed: null,
deprecated: null,
added: null,
};

const added = changes.filter(ch => ch.type === 'new');
if (added.length) {
execSummary.push(`${added.length} added`);
summary.push(`// Added (${added.length})`);
let last, lastAttr;
const longest = added.reduce((acc, ch) => Math.max(acc, ch.k.length), 0);
added.forEach(ch => {
const removed = changes.filter(ch => ch.type === 'removed');
let summary = summaryFromChangeType.removed;
if (removed.length) {
execSummaryFromChangeType.removed = `${removed.length} removed exports`;
if (summary.length) { summary.push(''); }
let last;
const longest = removed.reduce((acc, ch) => Math.max(acc, ch.k.length), 0);
removed.forEach(ch => {
if (last && ch.ns !== last.ns) { summary.push(''); }
let indent = '';
if (lastAttr && ch.k.startsWith(lastAttr.k.slice('ATTR_'.length))) {
indent = ' ';
}
const cindent = ' '.repeat(longest - ch.k.length + 1);

const vRepr = ch.k.includes('_VALUE_') ? JSON.stringify(ch.v) : ch.v
summary.push(`${indent}${ch.k}${cindent}// ${vRepr}`);
const prevVRepr = ch.prevV.includes('_VALUE_') ? JSON.stringify(ch.prevV) : ch.prevV;
summary.push(`${ch.k}${cindent}// ${prevVRepr}`);

last = ch;
if (ch.k.startsWith('ATTR_')) {
lastAttr = ch;
}
});
}

const changed = changes.filter(ch => ch.type === 'changed');
summary = summaryFromChangeType.changed;
if (changed.length) {
execSummary.push(`${changed.length} changed value`);
execSummaryFromChangeType.changed = `${changed.length} exported values changed`;
if (summary.length) { summary.push(''); }
summary.push(`// Changed (${changed.length})`);
let last;
const longest = changed.reduce((acc, ch) => Math.max(acc, ch.k.length), 0);
changed.forEach(ch => {
Expand All @@ -169,10 +174,10 @@ function summarizeChanges({prev, curr, prevSrc, currSrc}) {
}

const deprecated = changes.filter(ch => ch.type === 'deprecated');
summary = summaryFromChangeType.deprecated;
if (deprecated.length) {
execSummary.push(`${deprecated.length} newly deprecated`);
execSummaryFromChangeType.deprecated = `${deprecated.length} newly deprecated exports`;
if (summary.length) { summary.push(''); }
summary.push(`// Deprecated (${deprecated.length})`);
let last;
const longest = deprecated.reduce((acc, ch) => Math.max(acc, ch.k.length), 0);
deprecated.forEach(ch => {
Expand All @@ -189,28 +194,35 @@ function summarizeChanges({prev, curr, prevSrc, currSrc}) {
});
}

const removed = changes.filter(ch => ch.type === 'removed');
if (removed.length) {
execSummary.push(`${removed.length} removed`);
if (summary.length) { summary.push(''); }
summary.push(`// Removed (${removed.length})`);
let last;
const longest = removed.reduce((acc, ch) => Math.max(acc, ch.k.length), 0);
removed.forEach(ch => {
const added = changes.filter(ch => ch.type === 'added');
summary = summaryFromChangeType.added;
if (added.length) {
execSummaryFromChangeType.added = `${added.length} added exports`;
let last, lastAttr;
const longest = added.reduce((acc, ch) => Math.max(acc, ch.k.length), 0);
added.forEach(ch => {
if (last && ch.ns !== last.ns) { summary.push(''); }
let indent = '';
if (lastAttr && ch.k.startsWith(lastAttr.k.slice('ATTR_'.length))) {
indent = ' ';
}
const cindent = ' '.repeat(longest - ch.k.length + 1);

const prevVRepr = ch.prevV.includes('_VALUE_') ? JSON.stringify(ch.prevV) : ch.prevV;
summary.push(`${ch.k}${cindent}// ${prevVRepr}`);
const vRepr = ch.k.includes('_VALUE_') ? JSON.stringify(ch.v) : ch.v
summary.push(`${indent}${ch.k}${cindent}// ${vRepr}`);

last = ch;
if (ch.k.startsWith('ATTR_')) {
lastAttr = ch;
}
});
}
if (execSummary.length === 0) {
execSummary.push('*none*');
}

return [execSummary, summary];
return {
haveChanges,
execSummaryFromChangeType,
summaryFromChangeType
};
}


Expand Down Expand Up @@ -238,7 +250,7 @@ function semconvChangelogGen() {
execSync(`curl -sf -o - ${pkgInfo.dist.tarball} | tar xzf -`, { cwd: TMP_DIR });

console.log(`Comparing exports to "${scDir}"`)
const [stableExecSummary, stableSummary] = summarizeChanges({
const stableChInfo = summarizeChanges({
// require('.../build/src/stable_*.js') from previous and current.
prev: Object.assign(...globSync(path.join(TMP_DIR, 'package/build/src/stable_*.js')).map(require)),
curr: Object.assign(...globSync(path.join(scDir, 'build/src/stable_*.js')).map(require)),
Expand All @@ -250,7 +262,7 @@ function semconvChangelogGen() {
.map(f => fs.readFileSync(f, 'utf8'))
.join('\n\n'),
});
const [unstableExecSummary, unstableSummary] = summarizeChanges({
const unstableChInfo = summarizeChanges({
prev: Object.assign(...globSync(path.join(TMP_DIR, 'package/build/src/experimental_*.js')).map(require)),
curr: Object.assign(...globSync(path.join(scDir, 'build/src/experimental_*.js')).map(require)),
prevSrc: globSync(path.join(TMP_DIR, 'package/build/esnext/experimental_*.js'))
Expand All @@ -261,38 +273,61 @@ function semconvChangelogGen() {
.join('\n\n'),
});

// Render the "change info" into a Markdown summary for the changelog.
const changeTypes = ['removed', 'changed', 'deprecated', 'added'];
let execSummaryFromChInfo = (chInfo) => {
const parts = changeTypes
.map(chType => chInfo.execSummaryFromChangeType[chType])
.filter(s => typeof(s) === 'string');
if (parts.length) {
return parts.join(', ');
} else {
return 'none';
}
}
const changelogEntry = [`
* feat: update semantic conventions to ${specVer} [#NNNN]
* Semantic Conventions ${specVer}:
[changelog](https://github.com/open-telemetry/semantic-conventions/blob/main/CHANGELOG.md#${slugify(specVer)}) |
[latest docs](https://opentelemetry.io/docs/specs/semconv/)
* \`@opentelemetry/semantic-conventions\` (stable) export changes: ${stableExecSummary.join(', ')}
* \`@opentelemetry/semantic-conventions/incubating\` (unstable) export changes: ${unstableExecSummary.join(', ')}
* \`@opentelemetry/semantic-conventions\` (stable) changes: *${execSummaryFromChInfo(stableChInfo)}*
* \`@opentelemetry/semantic-conventions/incubating\` (unstable) changes: *${execSummaryFromChInfo(unstableChInfo)}*
`];

if (stableSummary.length) {
changelogEntry.push('');
changelogEntry.push(`##### Stable changes ${specVer}\n`);
changelogEntry.push('```js');
changelogEntry.push(stableSummary.join('\n'));
changelogEntry.push('```');
}
if (stableChInfo.haveChanges) {
changelogEntry.push(`#### Stable changes in ${specVer}\n`);
for (let changeType of changeTypes) {
const summary = stableChInfo.summaryFromChangeType[changeType];
if (summary.length) {
changelogEntry.push(`<details open>
<summary>${stableChInfo.execSummaryFromChangeType[changeType]}</summary>
\`\`\`js
${summary.join('\n')}
\`\`\`
if (unstableSummary.length) {
if (stableSummary.length) {
changelogEntry.push('');
</details>
`);
}
}
changelogEntry.push(`#### Unstable changes ${specVer}`);
changelogEntry.push(`
<details>
<summary>Full unstable changes</summary>
}

if (unstableChInfo.haveChanges) {
changelogEntry.push(`#### Unstable changes in ${specVer}\n`);
for (let changeType of changeTypes) {
const summary = unstableChInfo.summaryFromChangeType[changeType];
if (summary.length) {
changelogEntry.push(`<details>
<summary>${unstableChInfo.execSummaryFromChangeType[changeType]}</summary>
\`\`\`js
${unstableSummary.join('\n')}
${summary.join('\n')}
\`\`\`
</details>
`);
}
}
}

return changelogEntry.join('\n');
Expand Down
35 changes: 20 additions & 15 deletions semantic-conventions/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,31 @@ All notable changes to the semantic-conventions package will be documented in th
* Semantic Conventions v1.29.0:
[changelog](https://github.com/open-telemetry/semantic-conventions/blob/main/CHANGELOG.md#v1290) |
[latest docs](https://opentelemetry.io/docs/specs/semconv/)
* `@opentelemetry/semantic-conventions` (stable) export changes: *none*
* `@opentelemetry/semantic-conventions/incubating` (unstable) export changes: 95 added, 8 newly deprecated
* `@opentelemetry/semantic-conventions` (stable) changes: *none*
* `@opentelemetry/semantic-conventions/incubating` (unstable) changes: *8 newly deprecated exports, 95 added exports*

#### Unstable changes v1.29.0
#### Unstable changes in v1.29.0

<details>
<summary>Full unstable changes</summary>
<summary>8 newly deprecated exports</summary>

```js
ATTR_DB_COSMOSDB_OPERATION_TYPE // No replacement at this time.
ATTR_DB_QUERY_PARAMETER // Replaced by `db.operation.parameter`.
ATTR_PROCESS_EXECUTABLE_BUILD_ID_PROFILING // Replaced by `process.executable.build_id.htlhash`
ATTR_VCS_REPOSITORY_CHANGE_ID // Deprecated, use `vcs.change.id` instead.
ATTR_VCS_REPOSITORY_CHANGE_TITLE // Deprecated, use `vcs.change.title` instead.
ATTR_VCS_REPOSITORY_REF_NAME // Deprecated, use `vcs.ref.head.name` instead.
ATTR_VCS_REPOSITORY_REF_REVISION // Deprecated, use `vcs.ref.head.revision` instead.
ATTR_VCS_REPOSITORY_REF_TYPE // Deprecated, use `vcs.ref.head.type` instead.
```

</details>

<details>
<summary>95 added exports</summary>

```js
// Added (95)
METRIC_CONTAINER_UPTIME // container.uptime

METRIC_DB_CLIENT_COSMOSDB_ACTIVE_INSTANCE_COUNT // db.client.cosmosdb.active_instance.count
Expand Down Expand Up @@ -129,16 +144,6 @@ ATTR_VCS_REF_TYPE // vcs.ref.type
ATTR_VCS_REVISION_DELTA_DIRECTION // vcs.revision_delta.direction
VCS_REVISION_DELTA_DIRECTION_VALUE_AHEAD // "ahead"
VCS_REVISION_DELTA_DIRECTION_VALUE_BEHIND // "behind"

// Deprecated (8)
ATTR_DB_COSMOSDB_OPERATION_TYPE // No replacement at this time.
ATTR_DB_QUERY_PARAMETER // Replaced by `db.operation.parameter`.
ATTR_PROCESS_EXECUTABLE_BUILD_ID_PROFILING // Replaced by `process.executable.build_id.htlhash`
ATTR_VCS_REPOSITORY_CHANGE_ID // Deprecated, use `vcs.change.id` instead.
ATTR_VCS_REPOSITORY_CHANGE_TITLE // Deprecated, use `vcs.change.title` instead.
ATTR_VCS_REPOSITORY_REF_NAME // Deprecated, use `vcs.ref.head.name` instead.
ATTR_VCS_REPOSITORY_REF_REVISION // Deprecated, use `vcs.ref.head.revision` instead.
ATTR_VCS_REPOSITORY_REF_TYPE // Deprecated, use `vcs.ref.head.type` instead.
```

</details>
Expand Down

0 comments on commit fddc720

Please sign in to comment.