Skip to content

Instantly share code, notes, and snippets.

@nathanpeck
Last active December 9, 2020 18:42
Show Gist options
  • Save nathanpeck/f5fbba9e502a4d39991b9024658cfbdd to your computer and use it in GitHub Desktop.
Save nathanpeck/f5fbba9e502a4d39991b9024658cfbdd to your computer and use it in GitHub Desktop.
// This handler function gets called for each SQS message that arrives in my process
mySqsHandler = function(msg) {
var self = this;
if (!msg.Attributes || !msg.Attributes.AWSTraceHeader) {
// This message was not selected for tracing by the sampler in
// a higher level service
runMySqsLogic(msg, function() {
// Noop, no segment to run
});
}
var trace = AWSXRay.utils.processTraceData(msg.Attributes.AWSTraceHeader);
var segment = new AWSXRay.Segment('message-distributor', trace.Root, trace.Parent);
segment.notTraced = (trace.Sampled !== '1');
// Create an instrumented namespace that will create trace spans.
var ns = AWSXRay.getNamespace();
ns.run(function() {
AWSXRay.setSegment(segment);
runMySqsLogic(msg, function() {
// After my SQS logic ran don't forget to close the segment.
segment.close();
});
});
};
@gvasquez95
Copy link

ok, and what about testing this locally on my computer, how would the x-ray agent should be run?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment