Skip to content

Lambda関数からADOT経由で各シグナルを送るために必要な手順

OpenTelemetry Collector extensionをイメージに含める

Section titled “OpenTelemetry Collector extensionをイメージに含める”

Lambdaからパラメータストアにアクセスすると同じように、Dockerfile にLambda extensionの実行ファイルを含める。ARNは arn:aws:lambda:ap-northeast-1:901920570463:layer:aws-otel-collector-amd64-ver-0-102-1:1 のような形式。

これはデフォルトの localhost:4317 で待ち受けているので、入れるだけで問題ない。

必要なプラグインを構成するような設定を書く。ファイルは OPENTELEMETRY_COLLECTOR_CONFIG_FILE に置く。

2025年2月時点では、ADOTは debugexporter を含まないので loggingexporter を使う必要がある。

アプリケーションでシグナルを計装する

Section titled “アプリケーションでシグナルを計装する”

通常の計装と同じように、メトリクスやトレースを計装する。このときOpenTelemetry SDK for Goのデフォルトエンドポイントはhttpsプロトコルなので注意が必要になる。

以下のようなエラーが発生していたら上記の問題を踏んでいる。

OTel Lambda Error: failed to force a flush, lambda may freeze before instrumentation exported: traces export: context deadline exceeded: rpc error: code = Unavailable desc = connection error: desc = “transport: authentication handshake failed: tls: first record does not look like a TLS handshake”

X-Rayに送る場合は追加の権限が必要

Section titled “X-Rayに送る場合は追加の権限が必要”

権限が不足している場合、以下のエラーが発生する。

Permanent error: AccessDeniedException: User: arn:aws:sts::xxx:assumed-role/role-name is not authorized to perform: xray:PutTraceSegments because no identity-based policy allows the xray:PutTraceSegments action

status code: 403, request id: d270bd25-6d19-415b-b285-7570efe37242

Terraformではこうする。

data "aws_iam_policy_document" "lambda_function_name" {
statement {
actions = [
"xray:PutTraceSegments",
"xray:PutTelemetryRecords",
"xray:GetSamplingRules",
"xray:GetSamplingTargets",
"xray:GetSamplingStatisticSummaries",
]
resources = ["*"]
}
}