Node layer never flushes LoggerProvider on invocation completion — logs silently dropped without manual forceFlush()

オープン
#2,537 コメント 1 件 リアクション 2 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
aws, node.js, typescript

調査の方向性

nodejs/packages/layer/src/wrapper.ts を読み、LoggerProvider の構築と wrapped-handler の完了パスから確認します。また、Lambda Extensions API の SHUTDOWN パスが存在するかどうかも調べます。提供された handler と OTLP endpoint で再現し、手動の forceFlush() なしで出力されたログが、invocation の完了または shutdown の前に配信されることを確認します。

索引モデルが issue の本文から書いたものです。

説明

bug javascript

Describe the bug
When using the Node layer with AWS_LAMBDA_EXEC_WRAPPER=/opt/otel-handler and OTLP logs export, logs emitted via the Logs API are unreliably delivered to the backend. They are only reliably delivered if the application explicitly calls forceFlush() on the logger provider before the handler returns. wrapper.ts constructs the LoggerProvider with a BatchLogRecordProcessor but no code path calls forceFlush()/shutdown() on it after the wrapped handler resolves, nor on a Lambda Extensions API SHUTDOWN event. AWS may freeze the execution environment shortly after the handler returns, before the batch processor's timer fires, dropping any log not yet exported.

Steps to reproduce
Deploy a Lambda with the layer below and AWS_LAMBDA_EXEC_WRAPPER=/opt/otel-handler, OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=<your OTLP endpoint>, using this handler:

import { logs, SeverityNumber } from '@opentelemetry/api-logs'
import { randomUUID } from 'node:crypto'

export async function handler() {
    const experimentId = randomUUID()

    logs.getLogger('otel-logs').emit({
        body: 'Lambda test log',
        severityNumber: SeverityNumber.INFO,
        severityText: 'INFO',
        attributes: {
            experiment_id: experimentId,
        },
    })

    // works only with this line uncommented
    // await (logs.getLoggerProvider() as any).forceFlush?.()

    return {
        experimentId,
    }
}

Invoke repeatedly with the forceFlush() line commented out: log records are missing in the backend intermittently. Uncommenting the forceFlush() line (or alternatively sleeping ~5s before returning) makes delivery reliable.

What did you expect to see?
Logs emitted during a Lambda invocation are flushed/delivered automatically by the layer before the execution environment is frozen, the same "zero code change" guarantee the layer provides for traces.

What did you see instead?
Log records queued in the (default) BatchLogRecordProcessor are lost intermittently, with no application-level indication of the drop.

What version of collector/language SDK version did you use?
Version: layer opentelemetry-nodejs-0_23_0 (arn:aws:lambda:eu-central-1:184161586896:layer:opentelemetry-nodejs-0_23_0:1)

What language layer did you use?
Config: Node.js

Additional context
Relevant code: wrapper.ts constructs the LoggerProvider with a BatchLogRecordProcessor (no schedule-delay override), but no flush/shutdown call exists in the wrapper for the logger (or tracer/meter) provider.

Suggested fix: flush all registered providers (logger, tracer, meter) automatically once the wrapped handler settles, before returning control to the Lambda runtime, and/or register a Lambda Extensions API SHUTDOWN handler to flush on environment termination so in-flight logs aren't lost if the process is killed abnormally.

Workaround: manually call await (logs.getLoggerProvider() as any).forceFlush?.() at the end of every handler.

Possibly related (metrics, not logs, but similar auto-flush gap): #1949

主要言語
Go
スター
433
フォーク
249
平均マージ
1日 12時間
マージ済み PR(30日)
39

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

open-telemetry/opentelemetry-lambda のほかの issue

open-telemetry/opentelemetry-lambda の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。