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

Node.js 14.x Lambda的OTel CloudWatch日志多行合并问题咨询

解决Lambda + OpenTelemetry日志多行显示问题(合并为单条JSON日志)

核心方案:修改Logging Exporter配置为JSON格式

当前你的OpenTelemetry配置中,logging exporter默认以多行文本格式输出日志,只需添加format: json配置,即可让每条日志以单行JSON结构输出,被CloudWatch识别为单条日志。

修改后的完整配置如下:

receivers:
  otlp:
    protocols:
      grpc:
      http:

exporters:
  logging:
    loglevel: debug
    format: json  # 新增配置,指定输出JSON格式

  awsxray:
  otlp:
    endpoint: <my-endpoint>

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

进阶方案:使用AWS CloudWatch Exporter(更直接的日志控制)

如果需要更精准地控制CloudWatch日志的分组、流等属性,可以替换logging exporter为awscloudwatch exporter,直接将日志发送到CloudWatch,避免依赖Lambda的日志捕获机制:

  1. 添加awscloudwatch exporter配置:
exporters:
  awscloudwatch:
    log_group_name: "/aws/lambda/your-function-name"  # 替换为你的Lambda函数日志组
    log_stream_name: "$LAMBDA_LOG_STREAM_NAME"  # 复用Lambda的日志流变量
    region: "your-aws-region"  # 替换为你的AWS区域
  1. 在service.pipelines中添加日志处理管道:
service:
  pipelines:
    traces:
      receivers: [otlp]
      exporters: [awsxray, otlp]
    logs:
      receivers: [otlp]
      exporters: [awscloudwatch]  # 新增日志管道

注意事项

  • 你的OTel Lambda层版本为v1-5-0:1,对应OpenTelemetry 1.5.0版本,已支持logging exporter的format配置和awscloudwatch exporter。
  • 部署修改后的配置后,需重启Lambda函数确保配置生效。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 15:10:19