Skip to content

Logger.traced ends spans before promises from another realm settle #2753

Open

Description

runCatchFinally checks asynchronous results with "ret instanceof Promise". A native Promise created in another JavaScript realm, such as Node's vm context, fails that check.

Logger.traced therefore calls span.end() immediately when the callback returns a still-pending foreign Promise. Rejection also bypasses the error handler. A conforming thenable without catch/finally methods has the same premature-cleanup behavior.

I reproduced this against current main with real package tests:

  • A Node vm Promise is still pending, but a spy on the public Logger.traced span's end method already records one call.
  • The helper's cleanup runs before fulfillment.
  • A rejected foreign Promise never reaches the helper's catch handler.
  • A then-only PromiseLike also triggers immediate cleanup.

The new focused Vitest tests produce four failures and five passes on the unchanged implementation, including a passing synchronous-return/error control. The logger test uses the SDK's in-memory test logger; it does not call a model or require service credentials.

I plan to recognize PromiseLike results, preserve normal Promise chaining (including subclass behavior), assimilate then-only values when necessary, and add the regression coverage and a patch changeset. I will run the package typing and relevant test checks before opening a PR.

AI assistance: Codex helped inspect the helper and execute these reproductions.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions