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

推荐订阅源

博客园 - 叶小钗
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
美团技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
aimingoo的专栏
aimingoo的专栏
腾讯CDC
WordPress大学
WordPress大学
Apple Machine Learning Research
Apple Machine Learning Research
F
Fortinet All Blogs
G
Google Developers Blog
MongoDB | Blog
MongoDB | Blog
Microsoft Azure Blog
Microsoft Azure Blog
小众软件
小众软件
Engineering at Meta
Engineering at Meta
博客园_首页
B
Blog RSS Feed
D
Docker
M
MIT News - Artificial intelligence
爱范儿
爱范儿
I
InfoQ

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.