aws/aws-xray-sdk-ruby

Lambda functions - adding annotations to segments "Can not find any active segment or subsegment."

wizardofelves opened this issue · 1 comments

Hello,

Is it possible with the latest version of the SDK to add annotations to the underlying segment? What is the recommended approach?

I want to to add an annotation to my lambda function so that I can search for the segment in the XRay console. I've tried to add annotations to the parent segment and a new subsegment, but when i do i receive an error

"Can not find any active segment or subsegment." when accessing the segment

  • I've also verified my function has the proper permissions to write:
- Effect: Allow
      Action:
        - "xray:PutTraceSegments"
        - "xray:PutTelemetryRecords"
      Resource:
        - "*"
require 'aws-xray-sdk/lambda'
....

handler :my_function do |event:, context:|
    document = XRay.recorder.begin_subsegment name: 'annotations', namespace: 'remote'
    lambda_annotation = {lambda_annotation: 'true' }
    document.annotations.update lambda_annotation
    XRay.recorder.end_subsegment
end

and

handler :my_function do |event:, context:|
    document = XRay.recorder.current_segment
    lambda_annotation = {lambda_annotation: 'true' }
    document.annotations.update lambda_annotation
end

Thanks

Closing this - you cannot add annotations to the parent segment. I ended up doing

    XRay.recorder.capture('annotations') do |subsegment|
      subsegment.annotations['lambda_annotation'] = 'cat'
    end