New Relic Lambdaレイヤーを追加することで、 Lambda関数を計装できます。 これにより、New Relic エージェントが統合され、関数が呼び出されるたびに自動監視が可能になります。
ヒント
We recommend integrating your AWS account using the AWS integration to automatically discover and monitor your Lambda functions. This allows you to leverage the full power of New Relic APM for your serverless functions.
インストゥルメンテーション方法
New Relic包括的な監視のためにAWS Lambda 関数をプランニングするためのいくつかの方法を提供しています。
コマンドラインインターフェース (CLI) : AWS CLI を使用して、 New Relicレイヤーを Lambda 関数にすばやく追加します。
サーバーレス フレームワーク: New Relicインストゥルメンテーションをサーバーレス エンタープライズにシームレスに統合します。
選択した方法に関係なく、New Relic レイヤーは関数に New Relic エージェントを追加します。 このエージェントは、呼び出し時に関数を自動的にインストゥルメントし、ペイロード NR_LAMBDA_MONITORING を生成して、 New Relic Lambda 拡張機能を介してNew Relicに送信します。
Depending on your needs, you can choose to either bypass the extension and only see telemetry in CloudWatch, bypass CloudWatch, or use CloudWatch as a fallback. The CloudWatch section at the end of this doc will guide you through each option.
このコマンドは、 New Relicインストゥルメントを迅速に開始する方法を提供し、 CI/CDパイプラインに簡単に統合できます。 ただし、既存の Lambda 関数リソースが変更されるため、更新されたコードを再デプロイすると、インストゥルメンテーションが誤って削除される可能性があります。 継続的な監視を確実に行うには、各インストーラの後にコマンドを再実行するか、可能であれば、 New Relicレイヤーと設定をインストーラ プロセスに直接組み込みます。
CLIはバッチで多くの関数を操作できることに注意してください。 --function all 、 --function installed 、または--function not-installedを使用して、リージョン内のすべての関数を操作するか、既存のNewRelicインストルメンテーションの有無にかかわらず関数のみを操作します。
AWS's Serverless Application Model, or SAM, is a variant of CloudFormation templates that simplifies relating functions to the resources they depend on, and managing the lifecycle of an entire application. We use SAM and CloudFormation for most of our Lambda example functions, and many other tools are built on top of CloudFormation templates, providing an additional layer of abstraction.
New Relic Terraform プロバイダーを使用して、 AWSインテグレーションをセットアップできます。 プロバイダーをセットアップしたら、必要な環境変数を設定し、 Lambda関数にNR.Apm.Lambda.Mode: trueタグを追加します。
While it's more error-prone and labor-intensive than the approaches above, you can manually alter the configuration of a Lambda function to use New Relic from the AWS Lambda Console, for Node.js, Python, Ruby, and Java.
New Relicランタイムに LambdaRuby を実装する方法の例を次に示します。
AWS ウェブコンソールのLambdaサービスセクションに移動します。 そこから、 New Relicに接続する Lambda関数 を見つけます。
デフォルトのCode [コード]タブで、 Layers [レイヤー]セクションまで下にスクロールし、 Add a layer [レイヤーの追加]ボタンをクリックします。
Create layer [レイヤーの作成]ボタンをクリックします。
Choose a layer [レイヤーの選択]に移動し、 Specify an ARN [ARN の指定]オプションを選択します。
New Relicのレイヤーリストに移動し、ドロップダウンリストを使用して、Lambda 関数がホストされているAWSリージョンを選択します。 そこから、Lambda 関数のRubyバージョンとアーキテクチャに一致する ARN を見つけます。 オプションは X86 と ARM64 の 2 つあります。 Copy to clipboard [クリップボードにコピー]ボタンを使用するか、ARN 文字列を手動でコピーします。
Go の場合、Lambda関数を計装するにはソースコードを変更する必要があることに注意してください。 設定変更だけでは十分ではありません。
データを見つけて使用する
AWS Lambda 関数をセットアップしたら、 New Relic APMインターフェースでデータを検索して使用できるようになります。 データはいくつかの主要な領域に編成されており、それぞれがLambda関数のパフォーマンスと状態に異なるインサイトを提供します。
In the APM interface, you can explore various aspects of your Lambda functions including distributed tracing, service maps, transactions, error analysis, and more. Each of these areas provides detailed insights into the performance, latency, and error rates of your Lambda functions, allowing you to quickly identify and resolve issues.