Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with 'aws-xray-sdk-core' #628

Open
micro-jumbo opened this issue Oct 14, 2024 · 3 comments
Open

Problems with 'aws-xray-sdk-core' #628

micro-jumbo opened this issue Oct 14, 2024 · 3 comments

Comments

@micro-jumbo
Copy link

Hi,

I have this small lambda function:

import {ListBucketsCommand, S3Client} from "@aws-sdk/client-s3";

export const handle = async () => {
    const s3Client = new S3Client();
    const rest = await s3Client.send(new ListBucketsCommand());
    rest.Buckets?.forEach(bucket => {
        console.log(bucket.Name);
    });
    console.log('Hello world');
}

which works great.

But when I want to capture calls to S3 with X-Ray traces using the aws-xray-sdk-core library:

import {captureAWSv3Client} from 'aws-xray-sdk-core';
...
    const s3Client = captureAWSv3Client(new S3Client());
....

it starts failing with error:

2024-10-14T20:11:17.555Z	n/a	FATAL	ReferenceError: Error resolving module '/var/task/assert' from '/var/task/index.mjs'
  at <anonymous> (/var/task/index.mjs:1:4249)
      at <anonymous> (/var/task/index.mjs:1:458)
      at <anonymous> (/var/task/index.mjs:6:16634)
      at <anonymous> (/var/task/index.mjs:1:458)
      at <anonymous> (/var/task/index.mjs:6:89512)
      at <anonymous> (/var/task/index.mjs:1:458)
      at <anonymous> (/var/task/index.mjs:6:91308)
      at <anonymous> (/var/task/index.mjs:1:458)
      at <anonymous> (/var/task/index.mjs:6:91325)
INIT_REPORT Init Duration: 62.39 ms	Phase: init	Status: error	Error Type: Runtime.ExitError
2024-10-14T20:11:18.415Z	n/a	FATAL	ReferenceError: Error resolving module '/var/task/assert' from '/var/task/index.mjs'
  at <anonymous> (/var/task/index.mjs:1:4249)
      at <anonymous> (/var/task/index.mjs:1:458)
      at <anonymous> (/var/task/index.mjs:6:16634)
      at <anonymous> (/var/task/index.mjs:1:458)
      at <anonymous> (/var/task/index.mjs:6:89512)
      at <anonymous> (/var/task/index.mjs:1:458)
      at <anonymous> (/var/task/index.mjs:6:91308)
      at <anonymous> (/var/task/index.mjs:1:458)
      at <anonymous> (/var/task/index.mjs:6:91325)
INIT_REPORT Init Duration: 934.90 ms	Phase: invoke	Status: error	Error Type: Runtime.ExitError
START RequestId: 40310a38-3d40-4569-a631-e8e103a5105c Version: $LATEST
RequestId: 40310a38-3d40-4569-a631-e8e103a5105c Error: Runtime exited with error: exit status 1
Runtime.ExitError
END RequestId: 40310a38-3d40-4569-a631-e8e103a5105c
REPORT RequestId: 40310a38-3d40-4569-a631-e8e103a5105c	Duration: 975.40 ms	Billed Duration: 976 ms	Memory Size: 128 MB	Max Memory Used: 19 MB	
XRAY TraceId: 1-670d7ae5-67eb6e644cea659b394342d3	SegmentId: 44f97b661735d32b	Sampled: true	

Lambda function is created using cdk-lambda-llrt cdk construct:

import {LlrtBinaryType, LlrtFunction} from "cdk-lambda-llrt";

class MyLambda extends LlrtFunction {
    constructor(scope: Construct, id: string) {
        super(scope, id, {
            entry: path.resolve(__dirname, './handlers/my-lambda.ts'),
            handler: 'handle',
            llrtBinaryType: LlrtBinaryType.FULL_SDK,
            tracing: Tracing.ACTIVE,
            architecture: cdk.aws_lambda.Architecture.ARM_64,
        });
        this.addToRolePolicy(new cdk.aws_iam.PolicyStatement({
            actions: ['s3:*'],
            resources: ['*'],
        }));
    }
}

Any idea what the problem might be and how to solve it?

@nabetti1720
Copy link
Contributor

The error message is a bit odd, but it means that the Node.js assert module is not supported by LLRT at this time. The modules that are supported at this time are listed below.
https://github.com/awslabs/llrt?tab=readme-ov-file#compatibility-matrix

@micro-jumbo
Copy link
Author

I just checked the call chain and aws-xray-sdk-core calls cls-hooked, which uses assert.

What would be the best path to follow if I wanted to provide a shim for the assert (or any other) module to llrt?

@richarddavison
Copy link
Contributor

Hi, thanks for your report. It's a bit hard to tell, but for one the assert module is not supported. I also suspect that aws-xray-sdk-core might use a lot of node APIs not yet implemented. I'll take a closer look once I get the opportunity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants