惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
Netflix TechBlog - Medium
J
Java Code Geeks
爱范儿
爱范儿
雷峰网
雷峰网
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 三生石上(FineUI控件)
H
Hackread – Cybersecurity News, Data Breaches, AI and More
B
Blog RSS Feed
Google DeepMind News
Google DeepMind News
Jina AI
Jina AI
The GitHub Blog
The GitHub Blog
I
InfoQ
月光博客
月光博客
博客园 - 聂微东
博客园 - Franky
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
博客园_首页
G
Google Developers Blog
Blog — PlanetScale
Blog — PlanetScale
L
LangChain Blog
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research

Workflow SDK Documentation

Patterns for Defining Tools Human-in-the-Loop Building Durable AI Agents Queueing User Messages Resumable Streams Sleep, Suspense, and Scheduling Streaming Updates from Tools API Reference Workflow Globals Changelog Resilient run start Cookbook Building a World Deploying Astro Express Fastify Hono Getting Started NestJS Next.js Nitro Nuxt Python SvelteKit Vite corrupted-event-log fetch-in-workflow hook-conflict Errors
getWorkflowMetadata
2026-05-31 · via Workflow SDK Documentation

Access run IDs and timing information within workflow functions.

Returns additional metadata available in the current workflow function.

You may want to use this function when you need to:

  • Log workflow run IDs
  • Access timing information of a workflow
  • Detect whether encryption is enabled for the current run
import { getWorkflowMetadata } from "workflow"

async function testWorkflow() {
    "use workflow"

    const ctx = getWorkflowMetadata() 
    console.log(ctx.workflowRunId)
}

Detecting Workflow Runtime

You can use getWorkflowMetadata to detect whether your code is running inside a workflow context. This is useful when building shared utilities that need to behave differently inside and outside of workflows.

Since getWorkflowMetadata throws when called outside a workflow, you can wrap it in a try-catch:

import { getWorkflowMetadata } from "workflow"

function isInWorkflow(): boolean {
    try {
        getWorkflowMetadata()
        return true
    } catch {
        return false
    }
}

For example, a logging utility could include the workflow run ID when available:

import { getWorkflowMetadata } from "workflow"

function log(message: string) {
    try {
        const { workflowRunId } = getWorkflowMetadata()
        console.log(`[workflow:${workflowRunId}] ${message}`)
    } catch {
        console.log(message)
    }
}

Detecting Encryption

The features object indicates which capabilities are active for the current run. Library authors can use features.encryption to control whether sensitive data is included in step return values, which are serialized to the event log:

import { getWorkflowMetadata } from "workflow"

declare function getUserProfile(userId: string): Promise<{ name: string; ssn: string }>; // @setup

async function fetchUserProfile(userId: string) {
    "use step"

    const { features } = getWorkflowMetadata() 
    const profile = await getUserProfile(userId)

    if (!features.encryption) { 
        // Omit sensitive fields from the return value,
        // since it will be stored unencrypted in the event log
        const { ssn, ...safe } = profile
        return safe
    }

    return profile
}

Parameters

This function does not accept any parameters.

Returns

NameTypeDescription
workflowNamestringThe name of the workflow.
workflowRunIdstringUnique identifier for the workflow run.
workflowStartedAtDateTimestamp when the workflow run started.
urlstringThe URL where the workflow can be triggered.
features{ encryption: boolean; }Feature flags indicating which capabilities are active for this workflow run.