3

I am running application on lambda and enabled auto xray. I can see xray data on the console and logs on cloudwatch. But I am looking for a way to link my log to xray data. I'd like to see the logs relate to trace data when I click each trace on xray console. Is it possible to do?

If AWS doesn't support linking them automatically, is there any way to achieve that? Like, send log and trace data to elasticsearch. I am able to put all logs from cloudwatch to elasticsearch but I don't know how to push xray data to ES.

Joey Yi Zhao
  • 37,514
  • 71
  • 268
  • 523

3 Answers3

1

So far, only if by setting up CloudWatch Agent on EC2 and at the same time enable EC2 Plugin in X-Ray SDK you would see log group linked in XRay traces.

In Lambda we do not support linking between logs and traces.

pkamb
  • 33,281
  • 23
  • 160
  • 191
Lei Wang
  • 217
  • 1
  • 4
  • If AWS doesn't support it, is there a workaround I can make it work? like send both log and trace to elasticsearch? – Joey Yi Zhao Sep 05 '20 at 04:06
0

You can try using Annotations and Metadata for additional info in X-ray instead of logging. https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-annotations

Jobu
  • 181
  • 1
  • 5
0

It's possible to get the log correlation working with a bit of hacking. In short, you need to include the trace ID in your log messages and you need to set the name of the Cloudwatch Logs group in the segment metadata. For example, when using aws-xray-sdk-python, you'd set this as described in the related Github issue:

log_resources = xray_recorder._aws_metadata.setdefault("cloudwatch_logs", [{}])
log_resources[0]["log_group"] = log_group

I've had success with this approach for my python application.

alanc10n
  • 4,897
  • 7
  • 36
  • 41