Skip to content

Commit f06de18

Browse files
author
Elad Ben-Israel
authored
feat(core): include jsii runtime version in analytics (#1288)
Add the jsii runtime version to the library version reporting under "jsii-runtime". jsii runtime clients populate the JSII_AGENT environment variable with this information (see aws/jsii#325). If JSII_AGENT is not defined, we assume this is a node.js runtime and include the node.js version. Fixes #1258 Fixes awslabs/cdk-ops#127
1 parent 5478913 commit f06de18

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

packages/@aws-cdk/cdk/lib/app.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ export class App extends Root {
133133
}
134134
}
135135

136+
// add jsii runtime version
137+
libraries['jsii-runtime'] = getJsiiAgentVersion();
138+
136139
return { libraries };
137140
}
138141

@@ -205,3 +208,15 @@ function findNpmPackage(fileName: string): { name: string, version: string, priv
205208
return s;
206209
}
207210
}
211+
212+
function getJsiiAgentVersion() {
213+
let jsiiAgent = process.env.JSII_AGENT;
214+
215+
// if JSII_AGENT is not specified, we will assume this is a node.js runtime
216+
// and plug in our node.js version
217+
if (!jsiiAgent) {
218+
jsiiAgent = `node.js/${process.version}`;
219+
}
220+
221+
return jsiiAgent;
222+
}

packages/@aws-cdk/cdk/test/test.app.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function withApp(context: { [key: string]: any } | undefined, block: (app: App)
1717
}
1818

1919
const app = new App();
20+
2021
block(app);
2122

2223
app.run();
@@ -266,6 +267,36 @@ export = {
266267

267268
test.done();
268269
},
270+
271+
'runtime library versions'(test: Test) {
272+
const response = withApp({}, app => {
273+
const stack = new Stack(app, 'stack1');
274+
new Resource(stack, 'MyResource', { type: 'Resource::Type' });
275+
});
276+
277+
const libs = response.runtime.libraries;
278+
279+
const version = require('../package.json').version;
280+
test.deepEqual(libs['@aws-cdk/cdk'], version);
281+
test.deepEqual(libs['@aws-cdk/cx-api'], version);
282+
test.deepEqual(libs['jsii-runtime'], `node.js/${process.version}`);
283+
test.done();
284+
},
285+
286+
'jsii-runtime version loaded from JSII_AGENT'(test: Test) {
287+
process.env.JSII_AGENT = 'Java/1.2.3.4';
288+
289+
const response = withApp({}, app => {
290+
const stack = new Stack(app, 'stack1');
291+
new Resource(stack, 'MyResource', { type: 'Resource::Type' });
292+
});
293+
294+
const libs = response.runtime.libraries;
295+
test.deepEqual(libs['jsii-runtime'], `Java/1.2.3.4`);
296+
297+
delete process.env.JSII_AGENT;
298+
test.done();
299+
}
269300
};
270301

271302
class MyConstruct extends Construct {

0 commit comments

Comments
 (0)