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

HWKAPM-798 | HTTP recorder allow custom options #30

Conversation

pavolloffay
Copy link
Member

@pavolloffay pavolloffay commented Jan 2, 2017

https://issues.jboss.org/browse/HWKAPM-798

HTTP recorder accepts options object of underlying fetch-node.

@pavolloffay
Copy link
Member Author

@karelhala could you please review?

@pavolloffay pavolloffay force-pushed the HWKAPM-798-http-recorder-custom-options branch 2 times, most recently from f0477cc to a46f216 Compare January 2, 2017 16:39
Copy link

@karelhala karelhala left a comment

Choose a reason for hiding this comment

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

Looks good! Just couple of proposals, so if @pavolloffay does not agree on changing Object.assign to spread operator and simplifying fetch methods by removing brackets. I'm fine with it.

},
};
this[ENDPOINT] = `${url}/hawkular/apm/traces/fragments`;
this[HTTP_OPTIONS] = Object.assign({

Choose a reason for hiding this comment

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

Object.assign is older, you should now use spread operator, advantage is that it will create new object of options and is somewhat more readable. However it needs to be polyfilled with babel, es6 proposal.

this[HTTP_OPTIONS] = {method: 'POST', ...options}

Copy link
Member Author

Choose a reason for hiding this comment

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

This looks nicer! I will give it a try.

Choose a reason for hiding this comment

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

You might have to install rest spread - https://babeljs.io/docs/plugins/transform-object-rest-spread/

Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted to play with it in browser and it does not work :(. It is still in stage 3 proposal, I will stick with assign..

headers: this[HTTP_OPTIONS].headers,
fetch(this[ENDPOINT], Object.assign({}, this[HTTP_OPTIONS], {
body: JSON.stringify([trace])
})).then((response) => {

Choose a reason for hiding this comment

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

Can be simplified by omiting brackets

...
})).then(response => response.status !== 204 && console.log(`Server did not accept trace data: ${response}`))
...

Copy link
Member Author

Choose a reason for hiding this comment

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

I will it as it is, makes it easier to extend.

})).then((response) => {
if (response.status !== 204) {
console.log(`Server did not accept trace data: ${response}`);
}
}).catch((err) => {

Choose a reason for hiding this comment

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

Can be simplified by omiting brackets

...
}).catch(err => console.log(`Error when reporting trace! Error: ${err}`))
...

Copy link
Member Author

Choose a reason for hiding this comment

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

the same as above

@pavolloffay pavolloffay force-pushed the HWKAPM-798-http-recorder-custom-options branch from a46f216 to f92fdaf Compare January 3, 2017 11:01
@objectiser
Copy link
Contributor

@pavolloffay I think this came up when you were initially doing the work on the javascript provider? Looking at the fields in the option object I don't see anything that the application should be able to specify, other than possibly the timeout - so not sure it is a good idea to allow application to provide this object.

I think allowing control over timeout is a good idea and should be consistent across all languages supporting a HTTP recorder.

HTTP recorder accepts options object of underlying fetch-node.
@pavolloffay pavolloffay force-pushed the HWKAPM-798-http-recorder-custom-options branch from f92fdaf to 85313dd Compare January 10, 2017 12:27
@pavolloffay
Copy link
Member Author

PR updated, now it's possible to specify only timeout

@objectiser
Copy link
Contributor

@pavolloffay LGTM 👍

@pavolloffay
Copy link
Member Author

@objectiser @karelhala thanks!

@pavolloffay pavolloffay merged commit 54a2315 into hawkular:master Jan 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants