I am trying to ultimately change the a trace-id so tell me if I'm taking a wrong approach. What I'm currently thinking of is to create a segment, and add the parent-id as the trace_id that I want so one trace can follow another trace. The reason I'm trying to do that is because asynchronous parts of aws such as kinesis streams are not supported in aws x-ray.
const segment = new awsXRay.Segment('1-11111111-111111111111111111111111', '1-11111111-111111111111111111111111', '1-11111111-111111111111111111111111')
console.log(segment)
awsXRay.setSegment(segment)
However, I get the error:
TypeError: segment.resolveLambdaTraceData is not a function
Any ideas why I'm getting the error, or how I can connect two events that happened before and after a kinesis stream by connecting their trace_ids?
When the X-Ray SDK is used in Lambda, Lambda creates it's own segment (and sends it out of band of the Lambda function code) and the SDK creates a "facade" on the context as a placeholder given the parent ID and ID of the segment Lambda created (exposed via process.env._x_amzn_trace_id). The SDK only creates subsegments attached to this facade segment, and when the Lambda function concludes, these subsegments are sent and the service pieces it together. Each time the Lambda function fires, and it wasn't a cold start, the facade segment refreshes itself with the new parent ID and ID as supplied by Lambda (with the call to resolveLambdaTraceData). The SDK does not expect a user created segment in Lambda set on the context. With an manually created segment, the resolveLambdaTraceData function is not available, hence the error, and when set on the context, this fires automatically when it detects a separate Lambda execution.
Can you go into more detail for your use-case?