x-ray error when calling secrets manager

0

I have a very simple node js application. in the code I want to use x-ray and catch the calls I do with the AWS sdk. In my case the secrets manager.

I always get this error "Error: Failed to get the current sub/segment from the context." when I run it localy.

const AWS = require('aws-sdk');
const AWSXRay = require('aws-xray-sdk');
AWS.config.update({ region: 'eu-west-1' });

// Initialize the AWS X-Ray SDK
AWSXRay.captureAWS(require('aws-sdk'));

// Create a Secrets Manager client with X-Ray instrumentation
const secretsManager = AWSXRay.captureAWSClient(new AWS.SecretsManager());

// Retrieve the secret value with X-Ray instrumentation
AWSXRay.captureAsyncFunc('getSecretValue', function(subsegment) {

  // Define the parameters for the secret
  const params = {
    SecretId: 'thesecretId'
  };

  return secretsManager.getSecretValue(params).promise().then(data => {
    if (AWSXRay.getSegment()) {
      AWSXRay.getSegment().addMetadata('SecretId', params.SecretId);
    }
    return JSON.parse(data.SecretString).password;
  });
}).then(password => {
  console.log('got password:');
}).catch(err => {
  console.error(err);
});


Joachim
질문됨 일 년 전719회 조회
1개 답변
0

Hi Joachim,

First could you try to use either captureAWS or csptureAWSClient https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-nodejs-awssdkclients.html

As mentions:

Do not use both captureAWS and captureAWSClient together. This will lead to duplicate subsegments.

Then check if you installed the middleware in the app: https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-nodejs-middleware.html#xray-sdk-nodejs-middleware-express

Let me know

profile picture
전문가
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠