1

I am creating segments and subsegments in golang to send to XRay, but I am getting a lot of problems with it.

FIrst I don't have continuity with the trace map balls.

Second the subsegments don't appear:

third i am asigning the segment to xRay group but it not works This is my code:

func init() {

    xray.Configure(xray.Config{
        ServiceVersion: "1.2.3",
    })
}

func handler(ctx context.Context, event events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
    
    ctx2, segment := xray.BeginSegment(ctx, "segment1")
    segment.Origin = "XrayGroup"

    ctx3, subseg1 := xray.BeginSubsegment(ctx2, "sub-segment1")
    xray.AddMetadata(ctx2, "key1", "value1") // add metadata to segment 1
    xray.AddMetadata(ctx3, "key2", "value2") // sub add metadata to segment 2

    logger.Info(ctx, ".....Subsegments......", zap.Any("", segment.Subsegments))

    subseg1.ParentID = segment.ID

    defer subseg1.Close(nil)

    defer segment.Close(nil)

    logger.Info(ctx, ".....Subsegments......", zap.Any("", segment.Subsegments))

    _, segment2 := xray.BeginSegment(ctx2, "segment2")

    logger.Info(ctx, ".....Subsegments......", zap.Any("", segment.Subsegments))

    defer segment2.Close(nil)

    return *u.ResponseAPIGWStringMessage(http.StatusBadRequest, "ya casi funciona"), nil
    //return response, err

}

func main() {
    lambda.Start(handler)
}

enter image description here

After all only appear the segment1

If I remove subseg1.ParentID = segment.ID

appear segment2

but client -> segment2

But not with segment1 parent

that the subsegments appear

1 Answers1

0

XRay data model is tricky, some important criteria:

  • Segment is a node in XRay console, Subsegment is not.
  • Subsegment has to have an available parent Segment, else it won't appear in xray console
  • subsegment can have namespace=remote/aws, then it is inferred to be a Segment in xray console
  • In one process, Segment cannot has child Segment, Segment can only has child Subsegment.

That causes some mysterious symptom in using X-Ray SDK. Please try to onboard ADOT instead of XRay SDK for go. The opentelemetry API can satisfy your requirement. Make sure using Span.Kind.Server for XRay Segment, Span.Kind.Client or Internal for XRay Subsegment.

Lei Wang
  • 217
  • 1
  • 4