{"id":16453425,"url":"https://github.com/blimmer/xray-async-invocation","last_synced_at":"2026-06-10T18:31:36.838Z","repository":{"id":42569547,"uuid":"433597225","full_name":"blimmer/xray-async-invocation","owner":"blimmer","description":null,"archived":false,"fork":false,"pushed_at":"2022-12-08T02:13:05.000Z","size":280,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-26T20:43:00.958Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/blimmer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-30T21:51:20.000Z","updated_at":"2021-11-30T23:52:37.000Z","dependencies_parsed_at":"2023-01-25T03:15:27.924Z","dependency_job_id":null,"html_url":"https://github.com/blimmer/xray-async-invocation","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/blimmer/xray-async-invocation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blimmer%2Fxray-async-invocation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blimmer%2Fxray-async-invocation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blimmer%2Fxray-async-invocation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blimmer%2Fxray-async-invocation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blimmer","download_url":"https://codeload.github.com/blimmer/xray-async-invocation/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blimmer%2Fxray-async-invocation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34165482,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-10T02:00:07.152Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T10:15:34.692Z","updated_at":"2026-06-10T18:31:36.818Z","avatar_url":"https://github.com/blimmer.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node X-Ray Async Invocation Issue\n\nThis is some simple sample code that illustrates an issue where X-Ray Segments are lost when asynchronously invoking\nanother Node lambda from an instrumented Node lambda.\n\nI opened an issue on the aws-xray-sdk-node GitHub repository: https://github.com/aws/aws-xray-sdk-node/issues/477 to track this issue.\n\n## Code Layout\n\nThere are two lambda functions defined in this repository:\n\n- [triggering lambda](https://github.com/blimmer/xray-async-invocation/blob/main/lib/xray-async-invocation-stack.triggering.ts)\n  - lists all s3 buckets (to generate a segment)\n  - invokes the triggered lambda\n- [triggered lambda](https://github.com/blimmer/xray-async-invocation/blob/main/lib/xray-async-invocation-stack.triggered.ts)\n  - lists all s3 buckets (to generate a segment)\n\nIn both lambdas, the `captureAWS` method from `aws-xray-sdk` is used as recommended by\n[this documentation](https://docs.aws.amazon.com/lambda/latest/dg/nodejs-tracing.html).\n\n## To Deploy\n\nThis is an [aws-cdk](https://aws.amazon.com/cdk/) application.\n\n1. Run `npm install`\n1. Run `npx cdk deploy 'TestXrayAsyncInvocationStack'`\n\nThis will create a CloudFormation stack in your AWS account called `TestXrayAsyncInvocationStack`.\n\n## Reproduction Steps\n\n1. Visit the Lambda console for the `test-xray-triggering`. For instance, if you deploy to `us-east-1` the URL will be https://console.aws.amazon.com/lambda/home?region=us-east-1#/functions/test-xray-triggering?tab=code.\n1. Click the \"Test\" tab and then the \"Test\" button to trigger the lambda. The contents of the event do not matter.\n\n### Observed Behavior\n\nThe last segment is a `202` HTTP status code, meaning that the async invocation of the test lambda\nsucceeded.\n\n![](https://i.imgur.com/KoCp9bZ.png)\n\nHowever, the triggered lambda produced no traces at all:\n\n![](https://i.imgur.com/rvxakBu.png)\n\nEven though it was definitely invoked:\n\n![](https://i.imgur.com/Zzc7mFI.png[/img)\n\n### Expected Behavior\n\nBecause these two lambdas are triggered by the same \"logical request\", I expected the X-Ray\ntracing segment generated by the triggering lambda to be passed as metadata to the async\ninvocation of the triggered lambda.\n\nAt the very least, even if the traces were not linked, I expected a trace to be produced by\nthe triggered lambda.\n\n## Python Example\n\nI'm pretty confident that this is an issue with the Node version of the `aws-xray-sdk` package because everything\nworks as expected when using the Python version of `aws-xray-sdk`.\n\nYou can check out the [`use-python` branch of this repo](https://github.com/blimmer/xray-async-invocation/tree/use-python)\nto see this working.\n\n### Deploying the Python Example\n\nPrerequisites: You must have `docker` installed and running on your machine.\n\n1. `git checkout use-python`\n1. Run `npm install`\n1. Run `npx cdk deploy 'TestXrayAsyncInvocationStack'`\n\n### Running the Python Example\n\nFollow the same steps as [above](#reproduction-steps)\n\nYou'll see that the X-Ray trace includes the asynchronous invocation, which is the expected behavior for Node, as well.\n\n![](https://i.imgur.com/1UNhurY.png)\n\n## Tearing Down the Infrastructure\n\nAfter you're done testing, you can tear down the infrastructure by running:\n\n```\nnpx cdk destroy 'TestXrayAsyncInvocationStack'\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblimmer%2Fxray-async-invocation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblimmer%2Fxray-async-invocation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblimmer%2Fxray-async-invocation/lists"}