AWS Lambda Native Tracing for Python

此页面介绍使用 Python 编写的 Instana AWS Lambda 跟踪 for AWS Lambda 函数的设置。

支持的运行时

  • Python 3.13
  • Python 3.12
  • Python 3.11
  • Python 3.10
  • Python 3.9

从2024年10月14日起, AWS Lambda不再为Lambda函数使用的 Python 3.8 运行时提供安全补丁和其他更新。 使用 Python 3.8 的函数不再享受技术支持,您也不能再创建使用 Python 3.8 运行时的新Lambda函数。

安装

本文档说明如何设置 Python Lambda 函数的跟踪。 确保还执行了 AWS Agent For Lambda 监视 的设置,以确保收集有关 Instana 无法从 AWS Lambda 运行时中收集的版本和某些运行时度量的必要信息。

要启用 Python Lambda 函数的跟踪,请执行以下步骤:

  1. 将 Instana Lambda 层添加到您的函数中。

    1. 在Lambda函数的配置页面中,点击 Layers 框,然后点击 Add a layer层
    2. 在打开的弹出窗口中,选择提供层版本 ARN,然后复制并粘贴与您所在区域匹配的 Instana Lambda 层的 ARN;您可以在 Instana Lambda 层部分找到 Instana Lambda 层的正确 ARN。 层选择
  2. 配置 Lambda 处理程序。 将处理程序设置为instana.lambda_handler。 Instana Lambda 层将自动触发缺省 Python 运行时处理程序: lambda_function.lambda_handler

    要更改 Lambda 处理程序的设置,请在配置页面上找到“基本设置”部分。 基本设置部分编辑按钮

    点击编辑,在“处理程序”字段中输入 instana.lambda_handler编辑基本设置以设置 Instana 的处理程序

    如果使用自定义处理程序值(而不是运行时的默认处理程序,请参阅前面的详细信息),请在环境变量 LAMBDA_HANDLER 中指定处理程序,以便通知 Instana Lambda 层。 即,如果您的处理程序为myModule.myHandler,请将环境变量 LAMBDA_HANDLER 设置为myModule.myHandler。 请参阅下一节以了解需要设置的其他环境变量。

    注:Lambda 配置页面可能显示类似 Lambda can't find the file instana.lambda_handler. 的警告。 稍后返回到配置页面时也可能显示此消息。 不要让这个警告分散您的注意力。 处理程序包含在 Instana Lambda 层中,但 AWS Lambda 配置页面未考虑这一点。

  3. 配置环境变量。 添加以下环境变量:

    您也可以进入 Instana 安装页面,点击更多 -> 代理 -> 安装 Instana 代理 -> 平台,获取这些环境变量的正确值: AWS -> 技术: AWS Lambda。

  4. 保存Lambda函数定义。 保存

前面概述的所有步骤都可以通过 AWS 网络控制台或任何常用的 AWS 管理工具(如)完成:

以下是一个示例 aws CLI 命令,如果想要自动执行 AWS Lambda 表达式的 Instana 集成,那么该命令可能用作起始点:

# Do not copy and paste this verbatim!
# It will overwrite any previously defined collection of layers and
# environment variables.
aws --region $YOUR_REGION lambda update-function-configuration \
  --function-name $YOUR_LAMBDA_FUNCTION_NAME \
  --layers $INSTANA_LAYER_ARN \
  --handler instana.lambda_handler \
  --environment ""Variables={INSTANA_ENDPOINT_URL=... , INSTANA_AGENT_KEY=... , ...}""

Instana Lambda 层

Python 的最新版本的 AWS Lambda 层的 ARN 如下所示(按区域):

区域 ARN
af-south-1 arn:aws:lambda:af-south-1:410797082306:layer:instana-python:76
ap-east-1 arn:aws:lambda:ap-east-1:410797082306:layer:instana-python:76
ap-northeast-1 arn:aws:lambda:ap-northeast-1:410797082306:layer:instana-python:76
ap-northeast-2 arn:aws:lambda:ap-northeast-2:410797082306:layer:instana-python:76
ap-northeast-3 arn:aws:lambda:ap-northeast-3:410797082306:layer:instana-python:76
ap-south-1 arn:aws:lambda:ap-south-1:410797082306:layer:instana-python:76
ap-south-2 arn:aws:lambda:ap-south-2:410797082306:layer:instana-python:76
ap-southeast-1 arn:aws:lambda:ap-southeast-1:410797082306:layer:instana-python:76
ap-southeast-2 arn:aws:lambda:ap-southeast-2:410797082306:layer:instana-python:76
ap-southeast-3 arn:aws:lambda:ap-southeast-3:410797082306:layer:instana-python:76
ap-southeast-4 arn:aws:lambda:ap-southeast-4:410797082306:layer:instana-python:76
ap-southeast-5 arn:aws:lambda:ap-southeast-5:410797082306:layer:instana-python:76
ap-southeast-7 arn:aws:lambda:ap-southeast-7:410797082306:layer:instana-python:76
ca-central-1 arn:aws:lambda:ca-central-1:410797082306:layer:instana-python:76
ca-west-1 arn:aws:lambda:ca-west-1:410797082306:layer:instana-python:76
cn-north-1 arn:aws-cn:lambda:cn-north-1:107998019096:layer:instana-python:null
cn-northwest-1 arn:aws-cn:lambda:cn-northwest-1:107998019096:layer:instana-python:null
eu-central-1 arn:aws:lambda:eu-central-1:410797082306:layer:instana-python:76
eu-central-2 arn:aws:lambda:eu-central-2:410797082306:layer:instana-python:76
eu-north-1 arn:aws:lambda:eu-north-1:410797082306:layer:instana-python:76
eu-south-1 arn:aws:lambda:eu-south-1:410797082306:layer:instana-python:76
eu-south-2 arn:aws:lambda:eu-south-2:410797082306:layer:instana-python:76
eu-west-1 arn:aws:lambda:eu-west-1:410797082306:layer:instana-python:76
eu-west-2 arn:aws:lambda:eu-west-2:410797082306:layer:instana-python:76
eu-west-3 arn:aws:lambda:eu-west-3:410797082306:layer:instana-python:76
il-central-1 arn:aws:lambda:il-central-1:410797082306:layer:instana-python:76
me-central-1 arn:aws:lambda:me-central-1:410797082306:layer:instana-python:76
me-south-1 arn:aws:lambda:me-south-1:410797082306:layer:instana-python:76
sa-east-1 arn:aws:lambda:sa-east-1:410797082306:layer:instana-python:76
us-east-1 arn:aws:lambda:us-east-1:410797082306:layer:instana-python:76
us-east-2 arn:aws:lambda:us-east-2:410797082306:layer:instana-python:76
us-west-1 arn:aws:lambda:us-west-1:410797082306:layer:instana-python:76
us-west-2 arn:aws:lambda:us-west-2:410797082306:layer:instana-python:76

中国区域的模式为 arn:aws-cn:lambda:${region}:107998019096:layer:instana-python:${layer-version} ,其余区域为 arn:aws:lambda:${region}:410797082306:layer:instana-python:${layer-version}

确保始终使用最新版本,并定期更新您正在使用的层版本,以受益于我们在发布层的新版本时提供的新功能和修订。