admin管理员组

文章数量:1398093

i'm trying to set up OpenTelemetry (OTel) for my AWS Lambda function (ts) using the AWS Lambda layer. However, the OTel extension fails to start, and I see the following errors in the logs:

{
  "level": "info",
  "ts": 1742934396.4294243,
  "logger": "telemetryAPI.Client",
  "msg": "Subscribing",
  "baseURL": "http://127.0.0.1:9001/2022-07-01/telemetry"
}
{
  "time": "2025-03-25T20:26:36.430Z",
  "type": "platform.telemetrySubscription",
  "record": {
    "name": "collector",
    "state": "Already subscribed",
    "types": [
      "platform"
    ]
  }
}
{
  "level": "info",
  "ts": 1742934396.4304833,
  "logger": "telemetryAPI.Client",
  "msg": "Subscription success",
  "response": "\"AlreadySubscribed\""
}
{
  "level": "info",
  "ts": 1742934396.4305956,
  "logger": "NewCollector",
  "msg": "Using config URI from environment variable",
  "uri": "/var/task/collector.yaml"
}
{
  "level": "warn",
  "ts": 1742934396.4449484,
  "logger": "lifecycle.manager",
  "msg": "Failed to start the extension",
  "error": "unable to start, otelcol state is Closed"
}
...
}

My Setup including collector.yaml:

  • Lambda Runtime: Node.js 20

  • OTel Layer: Using AWS-provided OpenTelemetry Lambda layer.

  • collector.yaml (placed in the root directory):

receivers:
  otlp:
    protocols:
      grpc:
        endpoint: "localhost:4317"
      http:
        endpoint: "localhost:4318"

exporters:
  logging:
    loglevel: debug
  opensearch:
    endpoint: "https://<endpoint>"
    region: "us-east-2"
    index: "metrics-otel-v1-%{yyyy.MM.dd}"
    insecure: true
    username: "<username>"
    password: "<passowwrd>"

service:
  pipelines:
    traces:
      receivers: [otlp]
      exporters: [awsxray]
    metrics:
      receivers: [otlp]
      exporters: [logging]
  telemetry:
    metrics:
      receivers: [otlp]
      exporters: [logging, opensearch]

Env variables

config_file is depricated using config_uri

OPENTELEMETRY_COLLECTOR_CONFIG_URI=/var/task/collector.yaml
OTEL_LOG_LEVEL=DEBUG

Since this is a POC I wrote a simple typescript lambda function

import { APIGatewayEvent, APIGatewayProxyResult } from "aws-lambda";

interface Sample {
  name: string;
}

export const handler = async (
  event: APIGatewayEvent
): Promise<APIGatewayProxyResult> => {
  try {
    const body: Sample = JSON.parse(event.body || "{}");

    if (!body.name) {
      return {
        statusCode: 400,
        body: JSON.stringify({ message: "Missing 'name' in the request body." }),
      };
    }

    return {
      statusCode: 202,
      body: JSON.stringify({ message: "Accepted" }),
    };
  } catch (error) {
    console.error("Error processing the request:", error);
    return {
      statusCode: 500,
      body: JSON.stringify({ message: "Internal Server Error" }),
    };
  }
};

Issue that I am facing

I'm using OpenTelemetry (OTel) with AWS Lambda and an OTel layer, but the extension fails to start with the error "otelcol state is Closed". Why is the OpenTelemetry extension failing to start, and why aren't metrics being sent to OpenSearch?

things i tried.

moving from localhost to 0.0.0.0 and that didnt work.

本文标签: