Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/interceptors-opentelemetry-v2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# `@temporalio/interceptors-opentelemetry-v2`

[![NPM](https://img.shields.io/npm/v/@temporalio/interceptors-opentelemetry-v2?style=for-the-badge)](https://www.npmjs.com/package/@temporalio/interceptors-opentelemetry-v2)

[Temporal](https://temporal.io)'s [TypeScript SDK](https://docs.temporal.io/typescript/introduction) interceptors for tracing Workflow and Activity executions with [OpenTelemetry](https://opentelemetry.io/) v2.

This package targets OpenTelemetry JS SDK v2. For OpenTelemetry JS SDK v1, use [`@temporalio/interceptors-opentelemetry`](https://www.npmjs.com/package/@temporalio/interceptors-opentelemetry).

- [Interceptors docs](https://docs.temporal.io/typescript/interceptors)
- [OpenTelemetry Interceptor example setup](https://github.com/temporalio/samples-typescript/tree/main/interceptors-opentelemetry)
76 changes: 76 additions & 0 deletions packages/interceptors-opentelemetry-v2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"name": "@temporalio/interceptors-opentelemetry-v2",
"version": "1.15.0",
"description": "Temporal.io SDK interceptors bundle for tracing with opentelemetry v2",
"main": "lib/index.js",
"types": "./lib/index.d.ts",
"scripts": {
"build": "tsc --build",
"test": "ava ./lib/__tests__/test-*.js"
},
"keywords": [
"temporal",
"workflow",
"interceptors",
"opentelemetry"
],
"author": "Temporal Technologies Inc. <sdk@temporal.io>",
"license": "MIT",
"dependencies": {
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/core": "^2.2.0",
"@opentelemetry/resources": "^2.2.0",
"@opentelemetry/sdk-trace-base": "^2.2.0",
"@temporalio/plugin": "workspace:*"
},
"devDependencies": {
"@opentelemetry/exporter-trace-otlp-grpc": "^0.208.0",
"@opentelemetry/sdk-node": "^0.208.0",
"@opentelemetry/semantic-conventions": "^1.38.0",
"@temporalio/activity": "workspace:*",
"@temporalio/client": "workspace:*",
"@temporalio/common": "workspace:*",
"@temporalio/proto": "workspace:*",
"@temporalio/test-helpers": "workspace:*",
"@temporalio/testing": "workspace:*",
"@temporalio/worker": "workspace:*",
"@temporalio/workflow": "workspace:*",
"ava": "^5.3.1",
"uuid": "^11.1.0"
},
"peerDependencies": {
"@temporalio/common": "workspace:*",
"@temporalio/workflow": "workspace:*"
},
"peerDependenciesMeta": {
"@temporalio/workflow": {
"optional": true
}
},
"bugs": {
"url": "https://github.com/temporalio/sdk-typescript/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/temporalio/sdk-typescript.git",
"directory": "packages/interceptors-opentelemetry-v2"
},
"homepage": "https://github.com/temporalio/sdk-typescript/tree/main/packages/interceptors-opentelemetry-v2",
"publishConfig": {
"access": "public"
},
"engines": {
"node": ">= 20.0.0"
},
"files": [
"src",
"lib",
"!src/__tests__",
"!lib/__tests__"
],
"ava": {
"timeout": "120s",
"concurrency": 1,
"workerThreads": false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { WorkflowHandle } from '@temporalio/client';
import { QueryDefinition } from '@temporalio/common';
import { Context } from '@temporalio/activity';

function getSchedulingWorkflowHandle(): WorkflowHandle {
const { info, client } = Context.current();
const { workflowExecution } = info;
return client.workflow.getHandle(workflowExecution.workflowId, workflowExecution.runId);
}

export async function signalSchedulingWorkflow(signalName: string): Promise<void> {
const handle = getSchedulingWorkflowHandle();
await handle.signal(signalName);
}

export async function queryOwnWf<R, A extends any[]>(queryDef: QueryDefinition<R, A>, ...args: A): Promise<R> {
const handle = getSchedulingWorkflowHandle();
return await handle.query(queryDef, ...args);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { activityInfo, Context } from '@temporalio/activity';
import { ApplicationFailure, ApplicationFailureCategory, CancelledFailure } from '@temporalio/common';

export { queryOwnWf, signalSchedulingWorkflow } from './helpers';

export async function echo(message?: string): Promise<string> {
return message ?? 'echo';
}

export async function fakeProgress(sleepIntervalMs = 1000, numIters = 100): Promise<void> {
await signalSchedulingWorkflow('activityStarted');
try {
for (let progress = 1; progress <= numIters; ++progress) {
await Context.current().sleep(sleepIntervalMs);
Context.current().heartbeat(progress);
}
} catch (err) {
if (!(err instanceof CancelledFailure)) {
throw err;
}
throw err;
}
}

async function signalSchedulingWorkflow(signalName: string): Promise<void> {
const { info, client } = Context.current();
const { workflowExecution } = info;
const handle = client.workflow.getHandle(workflowExecution.workflowId, workflowExecution.runId);
await handle.signal(signalName);
}

export async function throwMaybeBenign(): Promise<void> {
if (activityInfo().attempt === 1) {
throw ApplicationFailure.create({ message: 'not benign' });
}
if (activityInfo().attempt === 2) {
throw ApplicationFailure.create({ message: 'benign', category: ApplicationFailureCategory.BENIGN });
}
}
Loading
Loading