As far as I can see, if you want to build a segment around function that returns something, you're forced to do this:
let result;
AWSXRay.captureFunc('the thing', function(subsegment) {
const returned = doSomething();
result = result;
subsegment.close();
});
Am I missing something?
Hi Thomas,
The X-Ray SDKs were designed from a no-touch (or least-touch) perspective. They simply wrap the code to give context for the X-Ray segment in progress. For this reason, the local capture functions do not return values.
You need not manually close a subsegment from captureFunc (this is only required for captureAsyncFunc). For automatic mode, exposing the subsegment in the function is optional.
Your basic capture functions (in automatic mode) should look like this.
let result;
AWSXRay.captureFunc('the thing', function() {
result = doSomething();
});
See the automatic mode examples and manual mode examples listed here: https://github.com/aws/aws-xray-sdk-node/tree/master/packages/core
Thanks Sandra,
Although I'd argue that this makes the code heavily effected by x-ray
integration. As we have to completely re-write our functions into methods
that capture and mutate the external scope; which is surprising (e.g. not
what a developer later reading the code would expect from a proper
JavaScript function).
Perhaps a returning version, or an alternative approach would allow people
to quickly inspect their own functions for performance would be useful?
On Wed, 7 Feb 2018, 20:15 Sandra McMullen, notifications@github.com wrote:
Hi Thomas,
The X-Ray SDKs were designed from a no-touch (or least-touch) perspective.
They simply wrap the code for to give context for the X-Ray segment in
progress. For this reason, the local capture functions do not return values.You need not manually close a subsegment from captureFunc (this is only
required for captureAsyncFunc). For automatic mode, exposing the subsegment
in the function is optional.Your basic capture functions (in automatic mode) should look like this.
let result;
AWSXRay.captureFunc('the thing', function() {
result = doSomething();
});See the automatic mode examples and manual mode examples listed here:
https://github.com/aws/aws-xray-sdk-node/tree/master/packages/core—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/aws/aws-xray-sdk-node/issues/22#issuecomment-363896244,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AB3UHWvqODoYSNqxJjb4-KEb-M2N5TKNks5tSgROgaJpZM4R7Vbd
.
Hi Thomas,
We're continually working to create an X-Ray onboarding experience that can best serve all of use cases cross customer. While we do not break existing APIs, we are open to extending them to support more cases in the form of a minor version release. If you'd like, you can open a pull request with the changes required, we'd be happy to review it.
Thanks,
Sandra
Hi Sandra,
Actually it turns out this works just as well:
const traceMeFn = async () => {
const subsegment = AWSXRay.getSegment().addNewSubsegment('traceMeFn');
const someStuff = await functionality(1); // or do all the other things.
const extraStuff = processTheThings(someStuff);
subsegment.close();
return extraStuff;
};
I guess it was just a bit of confusion from the documentation.
Hi Thomas,
I'm glad you're found resolution. If there's anything directly you wish to call out please feel free to do so, any feedback is greatly appreciated. We understand that the SDK onboarding process can require a bit of research and warm-up, and we're trying to correct this to provide a better onboarding experience. We'll follow-up any suggestions accordingly.
Thanks,
Sandra
Most helpful comment
Hi Sandra,
Actually it turns out this works just as well:
I guess it was just a bit of confusion from the documentation.