Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): include jsii runtime version in analytics #1288

Merged
merged 1 commit into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/@aws-cdk/cdk/lib/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ export class App extends Root {
}
}

// add jsii runtime version
libraries['jsii-runtime'] = getJsiiAgentVersion();

return { libraries };
}

Expand Down Expand Up @@ -205,3 +208,15 @@ function findNpmPackage(fileName: string): { name: string, version: string, priv
return s;
}
}

function getJsiiAgentVersion() {
let jsiiAgent = process.env.JSII_AGENT;

// if JSII_AGENT is not specified, we will assume this is a node.js runtime
// and plug in our node.js version
if (!jsiiAgent) {
jsiiAgent = `node.js/${process.version}`;
}

return jsiiAgent;
}
31 changes: 31 additions & 0 deletions packages/@aws-cdk/cdk/test/test.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function withApp(context: { [key: string]: any } | undefined, block: (app: App)
}

const app = new App();

block(app);

app.run();
Expand Down Expand Up @@ -266,6 +267,36 @@ export = {

test.done();
},

'runtime library versions'(test: Test) {
const response = withApp({}, app => {
const stack = new Stack(app, 'stack1');
new Resource(stack, 'MyResource', { type: 'Resource::Type' });
});

const libs = response.runtime.libraries;

const version = require('../package.json').version;
test.deepEqual(libs['@aws-cdk/cdk'], version);
test.deepEqual(libs['@aws-cdk/cx-api'], version);
test.deepEqual(libs['jsii-runtime'], `node.js/${process.version}`);
test.done();
},

'jsii-runtime version loaded from JSII_AGENT'(test: Test) {
process.env.JSII_AGENT = 'Java/1.2.3.4';

const response = withApp({}, app => {
const stack = new Stack(app, 'stack1');
new Resource(stack, 'MyResource', { type: 'Resource::Type' });
});

const libs = response.runtime.libraries;
test.deepEqual(libs['jsii-runtime'], `Java/1.2.3.4`);

delete process.env.JSII_AGENT;
test.done();
}
};

class MyConstruct extends Construct {
Expand Down