Skip to content

Feature Request: Add Support for Cloudflare Workflows Instrumentation #190

@bhanuka-yd

Description

@bhanuka-yd

First of all thanks for this awesome library 💯 .

Cloudflare recently introduced Workflows, a new way to compose and orchestrate Workers efficiently. Currently, otel-cf-workers provides instrumentation for Durable Objects, but Workflows are not yet supported.

Since Workflows play a crucial role in structuring complex Worker applications, having built-in OpenTelemetry support would be highly beneficial for observability and tracing across workflow executions.

A possible implementation could follow a similar pattern to the existing Durable Object instrumentation. For example:

import { WorkflowEntrypoint, WorkflowEvent, WorkflowStep } from 'cloudflare:workers';
import { instrumentWorkflow, PartialTraceConfig } from '@microlabs/otel-cf-workers'

const config: ResolveConfigFn = (env: Env, _trigger) => {
	return {
		exporter: {
			url: 'https://api.honeycomb.io/v1/traces',
			headers: { 'x-honeycomb-team': env.HONEYCOMB_API_KEY },
		},
		service: { name: 'greetings-do' },
	}
}

type TestWorkflowTypes = {
	data: string,
}

class TestWorkflow extends WorkflowEntrypoint<Env, TestWorkflowTypes> {

	async run({ payload }: WorkflowEvent<TestWorkflowTypes>, step: WorkflowStep) {
		
		await step.do('step1', async () => {
			await sleep(2000);
		});

		await step.do('step2', async () => {
			await sleep(3000);
		});

		span.end();
	}

}

const TestOtelWorkflow = instrumentWorkflow(TestWorkflow, doConfig)

export { TestOtelWorkflow }

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions