Skip to content

feat: AsyncIterable streaming support for library SDK #585

@BYK

Description

@BYK

Currently the SDK library mode rejects streaming flags (--follow, --refresh) with an error. Commands like log list --follow and dashboard view --refresh yield multiple CommandOutput values over time via async generators — in library mode, these should return an AsyncIterable<T> that consumers iterate with for await...of.

Proposed API

const sdk = createSentrySDK({ token: "..." });

// Streaming: returns AsyncIterable
for await (const log of sdk.log.list({ follow: 5 })) {
  console.log(log);
}

// Non-streaming: returns Promise (unchanged)
const logs = await sdk.log.list({ limit: 10 });

Key challenges

  1. Async channelcaptureObject needs to push to a queue/channel instead of a single variable. Consumer reads via for await...of.
  2. Env lifecyclesetEnv() cleanup cannot run until iteration completes. Needs deferred cleanup tied to AsyncGenerator.return().
  3. Telemetry spanwithTelemetry uses callback pattern. Streaming needs a handle-based approach where the span stays open during iteration.
  4. SIGINT handling — Streaming commands use process.once("SIGINT"). Library mode needs to wire teardown to the AsyncGenerator instead.
  5. Codegen overloads — Methods with streaming flags need overloaded signatures: Promise<T> without flag, AsyncIterable<T> with flag.
  6. Concurrent env — Global setEnv prevents concurrent streaming. Accept single-stream limitation or refactor to per-invocation env.

Estimate

~450-570 lines across ~12 files. Core channel is simple (~50 lines), integration is the bulk.

Context

PR #565 added the library SDK. Multi-yield accumulation was fixed (array instead of single var), but streaming flags are still blocked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions