Skip to content

Commit b24c3f6

Browse files
committed
feat: add semantic convention aliases
This adds aliases for a bunch of app-info properties that align with OpenTelemetry's Semantic Conventions. This closes #818.
1 parent 5b20fe8 commit b24c3f6

File tree

4 files changed

+94
-3
lines changed

4 files changed

+94
-3
lines changed

packages/app-info/README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ A utility to get application information (e.g. the system code) in a consistent
1212
* [`appInfo.systemCode`](#appinfosystemcode)
1313
* [`appInfo.processType`](#appinfoprocesstype)
1414
* [`appInfo.cloudProvider`](#appinfocloudprovider)
15-
* [`appInfo.herokuAppId`](#appinfoherokuappId)
16-
* [`appInfo.herokuDynoId`](#appinfoherokudynoId)
15+
* [`appInfo.herokuAppId`](#appinfoherokuappid)
16+
* [`appInfo.herokuDynoId`](#appinfoherokudynoid)
17+
* [`appInfo.semanticConventions`](#appinfosemanticconventions)
1718
* [Migrating](#migrating)
1819
* [Contributing](#contributing)
1920
* [License](#license)
@@ -99,6 +100,16 @@ Get the `process.env.HEROKU_DYNO_ID` which is the dyno identifier
99100

100101
This is derived from the dyno metadata
101102

103+
### `appInfo.semanticConventions`
104+
105+
This object contains aliases for the main `appInfo` properties that correspond to OpenTelemetry's [Semantic Conventions](https://opentelemetry.io/docs/concepts/semantic-conventions/). We use the following mapping:
106+
107+
* `appInfo.semanticConventions.cloud.provider` aliases `appInfo.cloudProvider`
108+
* `appInfo.semanticConventions.cloud.region` aliases `appInfo.region`
109+
* `appInfo.semanticConventions.deployment.environment` aliases `appInfo.environment`
110+
* `appInfo.semanticConventions.service.name` aliases `appInfo.systemCode`
111+
* `appInfo.semanticConventions.service.version` aliases `appInfo.releaseVersion`
112+
102113

103114
## Migrating
104115

packages/app-info/lib/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,23 @@ exports.herokuAppId = process.env.HEROKU_APP_ID || null;
149149
*/
150150
exports.herokuDynoId = process.env.HEROKU_DYNO_ID || null;
151151

152+
/**
153+
* @type {import('@dotcom-reliability-kit/app-info').SemanticConventions}
154+
*/
155+
exports.semanticConventions = {
156+
cloud: {
157+
provider: exports.cloudProvider,
158+
region: exports.region
159+
},
160+
deployment: {
161+
environment: exports.environment
162+
},
163+
service: {
164+
name: exports.systemCode,
165+
version: exports.releaseVersion
166+
}
167+
};
168+
152169
// @ts-ignore
153170
module.exports.default = module.exports;
154171
module.exports = Object.freeze(module.exports);

packages/app-info/test/unit/lib/index.spec.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ describe('@dotcom-reliability-kit/app-info', () => {
349349
});
350350
});
351351
});
352+
352353
describe('.herokuAppId', () => {
353354
it('returns HEROKU_APP_ID when process.env.HEROKU_APP_ID exists', () => {
354355
expect(appInfo.herokuAppId).toBe('mock-heroku-app-id');
@@ -361,6 +362,7 @@ describe('@dotcom-reliability-kit/app-info', () => {
361362
expect(appInfo.herokuAppId).toBe(null);
362363
});
363364
});
365+
364366
describe('.herokuDynoId', () => {
365367
it('returns HEROKU_DYNO_ID when `process.env.HEROKU_DYNO_ID` exists', () => {
366368
expect(appInfo.herokuDynoId).toBe('mock-heroku-dyno-id');
@@ -372,4 +374,50 @@ describe('@dotcom-reliability-kit/app-info', () => {
372374
expect(appInfo.herokuDynoId).toBe(null);
373375
});
374376
});
377+
378+
describe('.semanticConventions', () => {
379+
describe('.cloud', () => {
380+
describe('.provider', () => {
381+
it('is an alias of `cloudProvider`', () => {
382+
expect(appInfo.semanticConventions.cloud.provider).toBe(
383+
appInfo.cloudProvider
384+
);
385+
});
386+
});
387+
388+
describe('.region', () => {
389+
it('is an alias of `region`', () => {
390+
expect(appInfo.semanticConventions.cloud.region).toBe(appInfo.region);
391+
});
392+
});
393+
});
394+
395+
describe('.deployment', () => {
396+
describe('.environment', () => {
397+
it('is an alias of `environment`', () => {
398+
expect(appInfo.semanticConventions.deployment.environment).toBe(
399+
appInfo.environment
400+
);
401+
});
402+
});
403+
});
404+
405+
describe('.service', () => {
406+
describe('.name', () => {
407+
it('is an alias of `systemCode`', () => {
408+
expect(appInfo.semanticConventions.service.name).toBe(
409+
appInfo.systemCode
410+
);
411+
});
412+
});
413+
414+
describe('.version', () => {
415+
it('is an alias of `releaseVersion`', () => {
416+
expect(appInfo.semanticConventions.service.version).toBe(
417+
appInfo.releaseVersion
418+
);
419+
});
420+
});
421+
});
422+
});
375423
});

packages/app-info/types/index.d.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ declare module '@dotcom-reliability-kit/app-info' {
1010
export const herokuAppId: string | null;
1111
export const herokuDynoId: string | null;
1212

13+
export type SemanticConventions = {
14+
cloud: {
15+
provider: string | null,
16+
region: string | null
17+
},
18+
deployment: {
19+
environment: string | null
20+
},
21+
service: {
22+
name: string | null
23+
version: string | null
24+
}
25+
};
26+
1327
type appInfo = {
1428
systemCode: typeof systemCode,
1529
processType: typeof processType,
@@ -20,7 +34,8 @@ declare module '@dotcom-reliability-kit/app-info' {
2034
releaseVersion: typeof releaseVersion,
2135
cloudProvider: typeof cloudProvider,
2236
herokuAppId: typeof herokuAppId,
23-
herokuDynoId: typeof herokuDynoId
37+
herokuDynoId: typeof herokuDynoId,
38+
semanticConventions: SemanticConventions
2439
};
2540

2641
export default appInfo;

0 commit comments

Comments
 (0)