aws / aws/aws-xray-sdk-node

3.7.0 fails reading 'addAttribute' of undefined

Open
#654 2 comments 8 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
280
Forks
157
PR merge metrics
No merged PRs in 30d

Description

Since the update to 3.7.0 my lambda fails.

Here are the logs of it failing:
```
INIT_START Runtime Version: nodejs:18.v29 Runtime Version ARN: arn:aws:lambda:eu-west-1::runtime:e78f4a8a086bd7395a083454a3b1a85e8bb06f09428b715c8078dfc31ce0c35c
2024-06-06T10:01:18.236Z undefined ERROR _X_AMZN_TRACE_ID is missing required information
2024-06-06T10:01:18.237Z undefined ERROR Empty or non-string trace ID provided
2024-06-06T10:01:18.341Z undefined INFO Found . Setting up proxy.
START RequestId: Version: 453
2024-06-06T10:01:18.469Z ERROR Invoke Error
{
"errorType": "TypeError",
"errorMessage": "Cannot read properties of undefined (reading 'addAttribute')",
"stack": [
"TypeError: Cannot read properties of undefined (reading 'addAttribute')",
" at file:///var/task/index.mjs:7438:18",
" at file:///var/task/index.mjs:16411:16",
" at file:///var/task/index.mjs:11253:14",
" at async file:///var/task/index.mjs:8931:26",
" at async Catalog.getCredentials (file:///var/task/index.mjs:36684:26)",
" at async Runtime.handler (file:///var/task/index.mjs:36631:7)"
]
}

END RequestId:
REPORT RequestId: Duration: 114.86 ms Billed Duration: 115 ms Memory Size: 512 MB Max Memory Used: 85 MB Init Duration: 399.98 ms
XRAY TraceId: 1- SegmentId: 0b2b67f75caf1811 Sampled: true
```

This is how it looked right before the update:
```
INIT_START Runtime Version: nodejs:18.v29 Runtime Version ARN: arn:aws:lambda:eu-west-1::runtime:e78f4a8a086bd7395a083454a3b1a85e8bb06f09428b715c8078dfc31ce0c35c
2024-06-06T10:01:42.058Z undefined INFO Found . Setting up proxy.
START RequestId: Version: 451
END RequestId:
REPORT RequestId: Duration: 295.29 ms Billed Duration: 296 ms Memory Size: 512 MB Max Memory Used: 93 MB Init Duration: 414.31 ms
XRAY TraceId: 1- SegmentId: 2f89a17922b0696d Sampled: true
```

The code consists of two files and gets built/deployed using the cdk node function.
catalog handler:
```typescript
import {captureAWSv3Client} from 'aws-xray-sdk';
import {SecretsManagerClient} from '@aws-sdk/client-secrets-manager';
import {proxyHandler} from '../src/proxy.js';
import {load} from '../env.js';
import {Catalog} from './catalog.js';

const secretsManagerClient = captureAWSv3Client(new SecretsManagerClient({
requestHandler: proxyHandler,
}));
export const handler = new Catalog(secretsManagerClient, load('SECRET_ARN')).handler;

```

catalog:
```typescript
[...]
export class Catalog {
private clientId?: string;

constructor(private readonly secretsManagerClient: SecretsManagerClient, private readonly secretArn: string) {
}

public handler: APIGatewayProxyHandlerV2 = async () => {
if (!this.clientId) {
await this.getCredentials();
}
[...]
};

private async getCredentials() {
const command = new GetSecretValueCommand({
SecretId: this.secretArn,
});
const secretOutput = await this.secretsManagerClient.send(command);
this.clientId = JSON.parse(secretOutput.SecretString!).client_id;
}
}
```

Contributor guide

Open the contributing guide

Research direction

Start with the catalog handler, especially captureAWSv3Client and the SecretsManagerClient setup, then follow Catalog.getCredentials in catalog.ts. Reproduce the shown AWS Lambda/CDK deployment with version 3.7.0 and compare it with the prior version; done means the handler retrieves the secret without the reported addAttribute error.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, node.js, typescript
Domain
backend, cloud, observability-sre
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.