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

Đang mở
#2,537 1 bình luận 2 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
aws, node.js, typescript
Lĩnh vực
cloud, observability

Hướng nghiên cứu

Đọc nodejs/packages/layer/src/wrapper.ts, bắt đầu từ quá trình khởi tạo LoggerProvider và đường dẫn hoàn tất của wrapped handler; đồng thời kiểm tra xem có đường dẫn SHUTDOWN của Lambda Extensions API hay không. Tái hiện với handler và endpoint OTLP được cung cấp, sau đó xác minh rằng các log được phát ra mà không gọi forceFlush() thủ công được gửi trước khi invocation hoàn tất hoặc shutdown xảy ra.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Go
Star
433
Fork
249
Merge trung bình
1 ngày 12 giờ
Pull request đã merge (30 ngày)
39

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của open-telemetry/opentelemetry-lambda

Tất cả issue của open-telemetry/opentelemetry-lambda

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.