SAM関数のX-Rayアクティブトレースが未設定

トレースを開始する必要がある関数にはActiveモードを指定してください。

説明

SAM 関数に Tracing: Active を指定すると、Lambda はサンプリングされた呼び出しのトレースを X-Ray に送信します。

想定される影響

トレースがないと、複数サービスのどこで遅延やエラーが発生したかを特定するのに時間がかかります。

対処方法

調査対象の関数でアクティブトレースを有効にします。実行ロールを明示的に指定した場合は X-Ray への書き込み権限を付与します。関数から先の呼び出しを追うには、その呼び出しも計測します。

例

修正例はイメージを使う関数に Tracing: Active を追加します。使用するイメージの URI、エントリーポイント、コマンド、作業ディレクトリを指定します。

変更前

yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  Function:
    Type: AWS::Serverless::Function
    Properties:
      PackageType: Image
      ImageUri: account-id.dkr.ecr.region.amazonaws.com/ecr-repo-name:image-name
      ImageConfig:
        Command:
          - app.lambda_handler
        EntryPoint:
          - entrypoint1
        WorkingDirectory: workDir
      Tags:
        Type: AWS Serverless Function

変更後

yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  Function:
    Type: AWS::Serverless::Function
    Properties:
      PackageType: Image
      ImageUri: account-id.dkr.ecr.region.amazonaws.com/ecr-repo-name:image-name
      ImageConfig:
        Command:
          - app.lambda_handler
        EntryPoint:
          - entrypoint1
        WorkingDirectory: workDir
      Tags:
        Type: AWS Serverless Function
      Tracing: Active

参考資料