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)
}
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