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

Fix telemetry header #362

Merged
merged 8 commits into from
May 11, 2019
Merged

Fix telemetry header #362

merged 8 commits into from
May 11, 2019

Conversation

lbalmaceda
Copy link
Contributor

@lbalmaceda lbalmaceda commented May 8, 2019

Changes

  • Fix telemetry. Set the auth0-client in every possible rest client instance.
  • Use new telemetry format
  • Can be removed by explicitly passing telemetry=false

Testing

Added unit tests asserting the header is being set, customized and removed when asked so.

  • This change adds unit test coverage
  • This change adds integration test coverage

Checklist

@lbalmaceda lbalmaceda requested a review from a team May 8, 2019 21:32
@lbalmaceda lbalmaceda added the medium Medium review label May 8, 2019
@@ -299,26 +299,15 @@ var ManagementClient = function(options) {
* @return {Object} Object containing client information.
*/
ManagementClient.prototype.getClientInfo = function() {
var clientInfo = {
return {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it would be a good idea to pull this and AuthenticationClient.prototype.getClientInfo from the same place...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can extract a new file/class and reference it from both places. Initially I thought on adding this header on a common place as well, instead of having each "set of endpoints module" set it. But I don't want to make a huge refactor of this. I know the work for auto-generating the APIs is eventually going to replace all.

name: 'node-auth0',
version: pkg.version,
dependencies: [],
environment: [
env: [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

env should not be an array, should be an object. See the RFC 👈 Auth0 internal link

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch


it('should configure instances with default telemetry header', function() {
sinon.stub(AuthenticationClient.prototype, 'getClientInfo', function() {
return { name: 'test-sdk', version: 'ver-123' };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was env left out of this test object?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just mocking a hardcoded response we can compare against in the tests. In order to avoid depending on versions numbers that can change, etc.

But the default implementation is already being tested here https://github.com/auth0/node-auth0/pull/362/files/ebe7db56674569acdfbcb25458fbe2357e9728ca#diff-16d97c0f0c5a6d9cc470e15de5e52580R72

'Auth0-Client': 'eyJuYW1lIjoidGVzdC1zZGsiLCJ2ZXJzaW9uIjoidmVyLTEyMyJ9',
'Content-Type': 'application/json'
};
expect(client.oauth.oauth.options.headers).to.contain(requestHeaders);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

});

it('should configure instances with custom telemetry header', function() {
var customTelemetry = { name: 'custom', version: 'beta-01', env: { node: 'v10' } };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not to open a can of worms here ... but someone can just pass whatever and it goes through? What about telemetry without a name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. They can. I think the decision for other SDKs was to prevent the telemetry being sent at all if the name was not present, should I do that here as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lbalmaceda - Seems like a good idea to me. Then at least we can filter some of the garbage that might be sent here.

*
* @return {Object} Object containing client information.
*/
utils.generateClientInfo = function() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new utils method to generate consistent telemetry across different api clients

var telemetry = jsonToBase64(options.clientInfo || this.getClientInfo());
managerOptions.headers['Auth0-Client'] = telemetry;
var clientInfo = options.clientInfo || generateClientInfo();
if ('string' === typeof clientInfo.name && clientInfo.name.length > 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if name is empty or not present, skip sending telemetry

@@ -67,7 +67,8 @@ var ManagementTokenProvider = function(options) {
domain: this.options.domain,
clientId: this.options.clientId,
clientSecret: this.options.clientSecret,
telemetry: this.options.telemetry
telemetry: this.options.telemetry,
clientInfo: this.options.clientInfo
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this class creates an AuthenticationClient for itself. I'm just passing down the telemetry customizations to that instance

src/auth/index.js Outdated Show resolved Hide resolved
src/utils.js Outdated Show resolved Hide resolved
Copy link
Contributor

@joshcanhelp joshcanhelp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Committed 2 tiny suggestions to keep this moving.

@lbalmaceda lbalmaceda merged commit 699f285 into master May 11, 2019
@luisrudge luisrudge added this to the v.2.17.1 milestone May 22, 2019
@evansims evansims deleted the update-telemetry branch June 13, 2022 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CH: Fixed medium Medium review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants