You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

OpenTelemetry Lambda扩展启动失败,报错‘otelcol state is Closed’求助

问题:AWS Lambda Node.js 20 配置官方OTel Layer时扩展启动失败,报错"otelcol state is Closed"

错误日志

{"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"}

配置详情

  • Lambda运行时:Node.js 20
  • OTel Layer:AWS官方OpenTelemetry Lambda Layer
  • collector.yaml(放置于项目根目录):
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]
  • 环境变量(已弃用config_file,改用config_uri):
OPENTELEMETRY_COLLECTOR_CONFIG_URI=/var/task/collector.yaml
OTEL_LOG_LEVEL=DEBUG

Lambda函数代码(POC)

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" }),
    };
  }
};

问题现象

配置完成后,OTel扩展启动失败,报错unable to start, otelcol state is Closed,同时指标无法发送到OpenSearch。

已尝试操作

将配置中的localhost替换为0.0.0.0,问题未解决。


内容的提问来源于stack exchange,提问作者Max Bojorquez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 15:33:21