MicroticaMicrotica

Streaming logs (SDK)

Iterate Microtica build, deployment, and app logs as typed async streams with the SDK, including follow mode, search, and cancellation.

The SDK exposes logs as typed async streams. Build, deployment, and app logs all normalize to the same LogEntry shape, and every stream is an AsyncIterable<LogEntry> you consume with for await.

A stream comes from one of three namespace methods:

The LogEntry shape

Each entry is one normalized log line or event:

TypeScript
interface LogEntry {
  timestamp: string;   // ISO-8601
  severity: "debug" | "info" | "warn" | "error";
  source: "pipeline" | "deploy-cfn" | "deploy-tf" | "app-pod" | "service-fargate";
  message: string;
  step?: string;       // pipeline source
  resource?: string;   // deploy-cfn source
  status?: string;     // deploy-cfn source — native CFN status, e.g. CREATE_FAILED
  eventId?: string;    // deploy-cfn source — de-dup key
}

The source field tells you where an entry came from — useful when a single stream multiplexes more than one origin (a build step that stitches in its deployment events, for example).

Consume a stream

Iterate the stream, then call result() for the normalized terminal status once iteration ends:

TypeScript
const stream = microtica.pipelines.buildLogs(projectId, pipelineId, buildId);

for await (const entry of stream) {
  console.log(`[${entry.severity}] ${entry.message}`);
}

const { normalized, statusRaw } = await stream.result();
// normalized: "success" | "failed" | "cancelled" | "interrupted"
//           | "disconnected" | "timeout" | "unknown"

Cancel a stream

Every stream option set takes an abortSignal. Use it to cancel follow mode on a timeout or a user interrupt:

TypeScript
const ac = new AbortController();
setTimeout(() => ac.abort(), 20 * 60_000); // give up after 20 minutes

const stream = microtica.envs.deploymentLogs(projectId, envId, deploymentId, {
  follow: true,
  abortSignal: ac.signal,
});
for await (const entry of stream) process.stdout.write(entry.message + "\n");

Build logs

pipelines.buildLogs(projectId, pipelineId, buildId, opts?) streams a build's per-step output.

TypeScript
const stream = microtica.pipelines.buildLogs(projectId, pipelineId, buildId, {
  follow: true,
});
OptionDescription
stepStream a single step by name. Default: every step in order.
rawSend the unfiltered CloudWatch stream.
followStream until the build terminates.
failuresOnlySkip successful steps; mark failing steps' lines as errors. Not allowed with follow.
stitchStitch a deploy step's CFN/Terraform events into the stream. Default true.
pollIntervalMsBuild-status poll interval. Default 5000.
abortSignalCancel the stream.

Deployment logs

envs.deploymentLogs(projectId, envId, deploymentId, opts?) streams one deployment's events. It auto-routes by the environment's IaC tool: CloudFormation events for CFN environments, the realtime Terraform stream for Terraform ones.

TypeScript
const stream = microtica.envs.deploymentLogs(projectId, envId, deploymentId, {
  follow: true,
  onProgress: (phase) => process.stderr.write(`… ${phase}\n`),
});
OptionDescription
followPoll for new events until the deploy terminates.
pollIntervalMsFollow poll interval. Default 5000.
onProgressHook called with progress phases during long pre-emission fetches.
abortSignalCancel the stream.

Get a deploymentId from envs.lastDeploy or pipelines.history.

App logs

apps.logs(projectId, name, opts?) returns a snapshot of a Kubernetes app's pod logs.

TypeScript
const stream = microtica.apps.logs(projectId, "api", { env: envId });
for await (const entry of stream) console.log(entry.message);
OptionDescription
envScope cluster/namespace resolution to one environment.
podPod name. Defaults to the first pod.
cluster / namespaceSet cluster and namespace explicitly.
abortSignalCancel the stream.

App logs are a snapshot. follow and failuresOnly aren't supported for Kubernetes pod logs and throw a kind: "validation" error. Filter entries yourself, or use kubectl logs -f for a live tail.

Next steps

On this page