Перейти к основному содержанию
Перейти к основному содержанию

AWS Lambda

В этом руководстве настраивается интеграция:

✅ Логи✅ Метрики✅ Трейсы

Установка Lambda-слоёв OpenTelemetry

Проект OpenTelemetry предоставляет отдельные Lambda-слои для следующего:

  1. Автоматической инструментализации кода вашей Lambda-функции с помощью автоинструментирования OpenTelemetry.
  2. Пересылки собранных логов, метрик и трейсов в ClickStack.

Добавление языкового слоя автоинструментации

Специализированные для конкретного языка слои Lambda для автоинструментации автоматически инструментируют код вашей функции Lambda с помощью пакета автоинструментации OpenTelemetry для выбранного языка.

Для каждого языка и региона используется собственный ARN слоя.

Если ваша функция Lambda уже инструментирована с помощью OpenTelemetry SDK, вы можете пропустить этот шаг.

Для начала выполните следующее:

  1. В разделе Layers нажмите «Add a layer».
  2. Выберите вариант «Specify an ARN» и укажите корректный ARN в зависимости от языка, при этом замените <region> на ваш регион (например, us-east-2):
arn:aws:lambda:<region>:184161586896:layer:opentelemetry-nodejs-0_7_0:1

The latest releases of the layers can be found in the OpenTelemetry Lambda Layers GitHub repository.

  1. Configure the following environment variables in your Lambda function under "Configuration" > "Environment variables".
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
AWS_LAMBDA_EXEC_WRAPPER=/opt/otel-handler
OTEL_PROPAGATORS=tracecontext
OTEL_TRACES_SAMPLER=always_on

Installing the OpenTelemetry collector Lambda layer

The collector Lambda layer allows you to forward logs, metrics, and traces from your Lambda function to ClickStack without impacting response times due to exporter latency.

To install the collector layer:

  1. In the Layers section click "Add a layer"
  2. Select specify an ARN and choose the correct ARN based on architecture, ensure you replace the <region> with your region (ex. us-east-2):
    arn:aws:lambda:<region>:184161586896:layer:opentelemetry-collector-amd64-0_8_0:1
  1. Add the following collector.yaml file to your project to configure the collector to send to ClickStack:
# collector.yaml \{#collectoryaml}
receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 'localhost:4317'
      http:
        endpoint: 'localhost:4318'

processors:
  batch:
  decouple:

exporters:
  otlphttp:
    endpoint: "<YOU_OTEL_COLLECTOR_HTTP_ENDPOINT>
    headers:
      authorization: <YOUR_INGESTION_API_KEY>
    compression: gzip

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [batch, decouple]
      exporters: [otlphttp]
    metrics:
      receivers: [otlp]
      processors: [batch, decouple]
      exporters: [otlphttp]
    logs:
      receivers: [otlp]
      processors: [batch, decouple]
      exporters: [otlphttp]
  1. Add the following environment variable:
OPENTELEMETRY_COLLECTOR_CONFIG_FILE=/var/task/collector.yaml

Checking the installation

After deploying the layers, you should now see traces automatically collected from your Lambda function in HyperDX. The decouple and batching processor may introduce a delay in telemetry collection, so traces may be delayed in showing up. To emit custom logs or metrics, you'll need to instrument your code your language-specific OpenTelemetry SDKs.

Troubleshooting

Custom instrumentation not sending

If you're not seeing your manually defined traces or other telemetry, you may be using an incompatible version of the OpenTelemetry API package. Ensure your OpenTelemetry API package is at least the same or lower version than the version included in the AWS lambda.

Enabling SDK debug logs

Set the OTEL_LOG_LEVEL environment variable to DEBUG to enable debug logs from the OpenTelemetry SDK. This will help ensure that the auto-instrumentation layer is correctly instrumenting your application.

Enabling collector debug logs

To debug collector issues, you can enable debug logs by modifying your collector configuration file to add the logging exporter and setting the telemetry log level to debug to enable more verbose logging from the collector lambda layer.

# collector.yaml \{#collectoryaml}
receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 'localhost:4317'
      http:
        endpoint: 'localhost:4318'

exporters:
  logging:
    verbosity: detailed
  otlphttp:
    endpoint: "https://in-otel.hyperdx.io"
    headers:
      authorization: <YOUR_INGESTION_API_KEY>
    compression: gzip

service:
  telemetry:
    logs:
      level: "debug"
  pipelines:
    traces:
      receivers: [otlp]
      processors: [batch, decouple]
      exporters: [otlphttp, logging]
    metrics:
      receivers: [otlp]
      processors: [batch, decouple]
      exporters: [otlphttp, logging]
    logs:
      receivers: [otlp]
      processors: [batch, decouple]
      exporters: [otlphttp, logging]