Skip to content
Merged
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
69 changes: 69 additions & 0 deletions .github/workflows/typescript-n8n.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: TypeScript n8n

on:
pull_request:
branches: [main, dev]
paths:
- 'typescript/packages/traceai_n8n/**'
- 'typescript/packages/fi-core/**'
- 'typescript/packages/fi-semantic-conventions/**'
- 'typescript/package.json'
- 'typescript/pnpm-lock.yaml'
- 'typescript/pnpm-workspace.yaml'
- 'typescript/tsconfig*.json'
- '.github/workflows/typescript-n8n.yml'
push:
paths:
- 'typescript/packages/traceai_n8n/**'
- 'typescript/packages/fi-core/**'
- 'typescript/packages/fi-semantic-conventions/**'
- 'typescript/package.json'
- 'typescript/pnpm-lock.yaml'
- 'typescript/pnpm-workspace.yaml'
- 'typescript/tsconfig*.json'
- '.github/workflows/typescript-n8n.yml'
workflow_dispatch:

permissions:
contents: read

concurrency:
group: typescript-n8n-${{ github.ref }}
cancel-in-progress: true

jobs:
integration:
name: n8n real-engine integration
runs-on: ubuntu-latest
timeout-minutes: 15
defaults:
run:
working-directory: typescript
env:
N8N_DIAGNOSTICS_ENABLED: 'false'
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: pnpm/action-setup@v4
with:
version: 10.30.1
- uses: actions/setup-node@v4
with:
node-version: '22.21.1'
cache: pnpm
cache-dependency-path: typescript/pnpm-lock.yaml
- name: Install locked dependencies without lifecycle scripts
run: pnpm --filter '@traceai/n8n...' install --frozen-lockfile --ignore-scripts
- name: Build shared dependencies
run: pnpm run build:deps
- name: Build CommonJS and ESM entries
run: pnpm --filter @traceai/n8n build
- name: Check types
run: pnpm --filter @traceai/n8n typecheck
- name: Check formatting
run: pnpm --filter @traceai/n8n lint
- name: Test the real engine and automatic loading
run: pnpm --filter @traceai/n8n test:coverage
- name: Pack the package
run: pnpm --filter @traceai/n8n pack --pack-destination "$RUNNER_TEMP"
3 changes: 2 additions & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,6 @@
"typescript/packages/traceai_elevenlabs": "0.1.0",
"go/bedrock": "0.1.0",
"typescript/packages/traceai_huggingface_transformers": "0.1.0",
"python/frameworks/transformers": "0.1.0"
"python/frameworks/transformers": "0.1.0",
"typescript/packages/traceai_n8n": "0.1.0"
}
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Trace LLM calls, agents, tools, and retrieval. Keep your application code and your observability stack.

**79 integration families · 5 languages · OpenTelemetry-native · Apache 2.0**
**80 integration families · 5 languages · OpenTelemetry-native · Apache 2.0**

[Get started](#quickstart) · [Integrations](#integrations) · [Documentation](https://docs.futureagi.com/docs/tracing) · [Contribute](CONTRIBUTING.md)

Expand Down Expand Up @@ -299,11 +299,11 @@ After a call finishes, open the `traceai-quickstart` project in **Observe** in F

## Integrations

**79 integration families, with language coverage you can inspect.** Each SDK link opens its package source. A dash means no dedicated framework package in this repository—not a promise of unsupported runtime behavior.
**80 integration families, with language coverage you can inspect.** Each SDK link opens its package source. A dash means no dedicated framework package in this repository—not a promise of unsupported runtime behavior.

Python and TypeScript provide framework instrumentors; Java provides client wrappers and framework modules; Go provides middleware and framework integrations. **C# provides [manual spans and activities](csharp/src/FIInstrumentation/), not automatic framework instrumentation**, so its framework cells are intentionally empty.

All 79 families are listed below, grouped by what they integrate. Runtime variants share a row: OpenAI includes Realtime; Google GenAI includes Live; AG2 includes its classic SDK. LangGraph ships in the LangChain integration. Shared SDKs are not counted as integrations. Package availability is not a claim of complete upstream feature compatibility; check each package's source and documentation for its scope.
All 80 families are listed below, grouped by what they integrate. Runtime variants share a row: OpenAI includes Realtime; Google GenAI includes Live; AG2 includes its classic SDK. LangGraph ships in the LangChain integration. Shared SDKs are not counted as integrations. Package availability is not a claim of complete upstream feature compatibility; check each package's source and documentation for its scope.

[Model providers](#model-providers) · [Agent frameworks](#agent-frameworks) · [RAG & vector databases](#rag-vector-databases) · [Tools & search](#tools-search) · [Voice & realtime](#voice-realtime) · [Gateways & proxies](#gateways-proxies) · [Coding agents](#coding-agents) · [Java frameworks](#java-frameworks) · [Other](#other)

Expand Down Expand Up @@ -358,6 +358,7 @@ Agent orchestration, application frameworks, and agent-to-agent communication.
| <img src=".github/assets/integrations/package-tile.svg" width="24" height="24" alt=""> Hermes Agent | [SDK](python/frameworks/hermes-agent/ "traceAI-hermes-agent") | — | — | — | — |
| <img src=".github/assets/integrations/langchain-tile.svg" width="24" height="24" alt=""> LangChain / LangGraph | [SDK](python/frameworks/langchain/ "traceAI-langchain") | [SDK](typescript/packages/traceai_langchain/ "@traceai/langchain") | — | — | — |
| <img src=".github/assets/integrations/mastra-tile.svg" width="24" height="24" alt=""> Mastra | — | [SDK](typescript/packages/traceai_mastra/ "@traceai/mastra") | — | — | — |
| <img src=".github/assets/integrations/package-tile.svg" width="24" height="24" alt=""> n8n (self-hosted) | — | [SDK](typescript/packages/traceai_n8n/ "@traceai/n8n") | — | — | — |
| <img src=".github/assets/integrations/package-tile.svg" width="24" height="24" alt=""> MCP-use | [SDK](python/frameworks/mcp-use/ "traceAI-mcp-use") | — | — | — | — |
| <img src=".github/assets/integrations/package-tile.svg" width="24" height="24" alt=""> Microsoft Agent Framework | [SDK](python/frameworks/agent-framework/ "traceAI-agent-framework") | — | — | — | — |
| <img src=".github/assets/integrations/openai-tile.svg" width="24" height="24" alt=""> OpenAI Agents | [SDK](python/frameworks/openai-agents/ "traceAI-openai-agents") | [SDK](typescript/packages/traceai_openai_agents/ "@traceai/openai-agents") | — | — | — |
Expand Down
8 changes: 8 additions & 0 deletions release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,14 @@
"extra-files": [
"traceai_transformers/version.py"
]
},
"typescript/packages/traceai_n8n": {
"release-type": "node",
"component": "npm-traceai-n8n",
"package-name": "@traceai/n8n",
"extra-files": [
"src/instrumentation.ts"
]
}
}
}
2 changes: 1 addition & 1 deletion typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"build": "pnpm run build:ordered",
"build:deps": "pnpm --filter @traceai/fi-core --filter @traceai/fi-semantic-conventions run build",
"build:consumers": "pnpm --filter @traceai/openai --filter @traceai/anthropic --filter @traceai/langchain --filter @traceai/bedrock --filter @traceai/vercel --filter @traceai/chromadb --filter @traceai/pinecone --filter @traceai/qdrant --filter @traceai/weaviate --filter @traceai/milvus --filter @traceai/lancedb --filter @traceai/mongodb --filter @traceai/pgvector --filter @traceai/redis --filter @traceai/together --filter @traceai/huggingface --filter @traceai/huggingface-transformers --filter @traceai/vllm --filter @traceai/deepseek --filter @traceai/fireworks --filter @traceai/cerebras --filter @traceai/xai --filter @traceai/google-genai-sdk run build",
"build:consumers": "pnpm --filter @traceai/openai --filter @traceai/anthropic --filter @traceai/langchain --filter @traceai/bedrock --filter @traceai/vercel --filter @traceai/chromadb --filter @traceai/pinecone --filter @traceai/qdrant --filter @traceai/weaviate --filter @traceai/milvus --filter @traceai/lancedb --filter @traceai/mongodb --filter @traceai/pgvector --filter @traceai/redis --filter @traceai/together --filter @traceai/huggingface --filter @traceai/huggingface-transformers --filter @traceai/vllm --filter @traceai/deepseek --filter @traceai/fireworks --filter @traceai/cerebras --filter @traceai/xai --filter @traceai/google-genai-sdk --filter @traceai/n8n run build",
"build:ordered": "pnpm run build:deps && pnpm run build:consumers",
"test": "pnpm run -r test",
"test:coverage": "pnpm run -r test:coverage",
Expand Down
10 changes: 10 additions & 0 deletions typescript/packages/traceai_n8n/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changelog

## 0.1.0 (unreleased)

- Add workflow and node execution attempt spans for `n8n-core >=2.16.1 <3`.
- Preserve workflow results, cancellable promises, parent context and retry
behavior; handle resolved errors and cancellation without duplicate span ends.
- Export execution metadata without item payloads, credentials or error messages.
- Support automatic CommonJS loading and manual instrumentation, with real-engine
integration tests and a self-hosted setup guide.
129 changes: 129 additions & 0 deletions typescript/packages/traceai_n8n/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# @traceai/n8n

OpenTelemetry instrumentation for the self-hosted n8n execution engine. It adds a
workflow span around each engine run and child spans around node execution
attempts, including retries. Existing provider instrumentors can add LLM spans
under the active node span.

## Compatibility

- Node.js 22.16 or newer.
- `n8n-core >=2.16.1 <3`; integration tests use `n8n-core@2.16.1` and its
`n8n-workflow@2.16.0` dependency. Earlier engine versions are not supported.
- Automatic instrumentation uses the CommonJS module loader. Both CommonJS and
ESM package entry points are available, but native ESM loading of n8n itself is
not covered by the automatic loader hook.

This package is a source contribution and has not been released to npm yet. The
commands below build it from this repository:

```sh
cd typescript
pnpm --filter '@traceai/n8n...' install --frozen-lockfile --ignore-scripts
pnpm run build:deps
pnpm --filter @traceai/n8n build
pnpm --filter @traceai/n8n pack --pack-destination /path/to/artifacts
```

Install the resulting tarball in the same application installation that resolves
`n8n-core`. The workspace dependencies must also be available there; when building
them from source, pack and install `@traceai/fi-semantic-conventions` and
`@traceai/fi-core` first. On Windows, use Git Bash for the existing dependency
build scripts.

## Self-hosted setup

Load instrumentation **before** n8n loads its engine, in every process that
executes workflows. For example, create `tracing.cjs` alongside your n8n
installation. It requires `@traceai/fi-core`, `@opentelemetry/api`,
`@opentelemetry/context-async-hooks` and `@opentelemetry/instrumentation` in addition
to this package.

```js
const { context } = require("@opentelemetry/api");
const {
AsyncLocalStorageContextManager,
} = require("@opentelemetry/context-async-hooks");
const { registerInstrumentations } = require("@opentelemetry/instrumentation");
const { register, ProjectType } = require("@traceai/fi-core");
const { N8nInstrumentation } = require("@traceai/n8n");

// If the application already has an OTel context manager/provider, reuse them.
context.setGlobalContextManager(new AsyncLocalStorageContextManager().enable());
const tracerProvider = register({
projectName: "n8n-workflows",
projectType: ProjectType.OBSERVE,
});
const instrumentation = new N8nInstrumentation();
registerInstrumentations({
tracerProvider,
instrumentations: [instrumentation],
});

// Flush on normal process exit; integrate shutdown with the host's lifecycle
// when it has its own shutdown hooks.
process.once("beforeExit", () => tracerProvider.shutdown());
```

Configure `FI_API_KEY` and `FI_SECRET_KEY` in the host environment, then preload
the file when starting the n8n process, for example on Linux:

```sh
NODE_OPTIONS="--require=/absolute/path/to/tracing.cjs" n8n start
```

Preserve any existing `NODE_OPTIONS` when adding the preload. In queue mode,
configure each worker as well as any process that runs manual executions. This
integration creates traces inside an engine process; it does **not** propagate
context through the queue or connect separate processes into one trace.

If the engine was already loaded, use the public manual entry point instead:

```js
instrumentation.manuallyInstrument(require("n8n-core"));
```

Call `instrumentation.disable()` to restore patched engine methods. Runs already
being observed still finish their open spans. OpenTelemetry tracing suppression
is respected.

## Captured data

| Span | Attributes |
| --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| Workflow (`CHAIN`) | `n8n.workflow.id`, `n8n.workflow.name`, `n8n.execution.id` when available, `n8n.execution.mode`, `n8n.execution.status` |
| Node attempt (`TOOL`) | `n8n.node.id`, `n8n.node.name`, `n8n.node.type`, `n8n.node.type_version`, `n8n.node.run_index`, `n8n.node.status`, execution ID and mode |

Span duration records elapsed execution time. Workflow status comes from n8n's
final run result, including errors returned as resolved promises. Rejected node
attempts are marked as errors even if n8n subsequently retries or continues.
Cancellation ends open spans once and preserves n8n's cancellable promise.

The integration does not capture workflow items, node parameters, credentials,
input/output payloads, exception messages or stack traces. Exceptions retain only
their type. Names and identifiers are exported, so avoid putting secrets in them.
Provider instrumentors have their own payload settings; this package does not
change those settings.

This first integration observes engine runs and calls to `runNode`. Pinned nodes
that bypass that method have no node span. Nodes that handle errors internally
and return them as ordinary item data are not classified by inspecting that data.
Waiting and resumed runs are separate spans; there is no persisted trace context
across a restart. It does not install an n8n community node, configure n8n Cloud,
or replace provider-specific LLM instrumentation.

## Development

From `typescript/`, after building dependencies:

```sh
pnpm --filter @traceai/n8n build
pnpm --filter @traceai/n8n typecheck
pnpm --filter @traceai/n8n test:coverage
pnpm --filter @traceai/n8n lint
```

The tests use the actual n8n engine and custom local nodes, with an in-memory
OpenTelemetry exporter. They require no credentials, external services or mocked
n8n modules. A fresh Node process also tests automatic module patching. The
`lint` script checks formatting with Prettier.
69 changes: 69 additions & 0 deletions typescript/packages/traceai_n8n/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"name": "@traceai/n8n",
"version": "0.1.0",
"description": "OpenTelemetry instrumentation for n8n workflow execution",
"main": "./dist/src/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/src/index.d.ts",
"exports": {
".": {
"types": "./dist/src/index.d.ts",
"import": "./dist/esm/index.js",
"require": "./dist/src/index.js"
}
},
"files": [
"dist/**/*.js",
"dist/**/*.d.ts",
"dist/**/*.map",
"dist/esm/package.json",
"README.md",
"CHANGELOG.md"
],
"scripts": {
"build": "tsc --build tsconfig.json && tsc -p tsconfig.esm.json && node scripts/esm-package.cjs",
"test": "node --test test/*.test.cjs",
"test:coverage": "node --experimental-test-coverage --test test/*.test.cjs",
"typecheck": "tsc --build tsconfig.json",
"lint": "prettier --check src test scripts *.json *.md",
"prepublishOnly": "pnpm run build && pnpm test && pnpm run lint"
},
"dependencies": {
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/core": "^2.0.1",
"@opentelemetry/instrumentation": "^0.202.0",
"@traceai/fi-core": "workspace:^",
"@traceai/fi-semantic-conventions": "workspace:^"
},
"peerDependencies": {
"n8n-core": ">=2.16.1 <3"
},
"peerDependenciesMeta": {
"n8n-core": {
"optional": true
}
},
"devDependencies": {
"@opentelemetry/context-async-hooks": "^2.0.1",
"@opentelemetry/sdk-trace-base": "^2.0.1",
"@opentelemetry/sdk-trace-node": "^2.0.1",
"@types/node": "^22.15.29",
"n8n-core": "2.16.1",
"n8n-workflow": "2.16.0",
"prettier": "^3.5.3",
"typescript": "^5.8.3"
},
"engines": {
"node": ">=22.16"
},
"author": "Future AGI <no-reply@futureagi.com>",
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "git+https://github.com/future-agi/traceAI.git",
"directory": "typescript/packages/traceai_n8n"
},
"publishConfig": {
"access": "public"
}
}
3 changes: 3 additions & 0 deletions typescript/packages/traceai_n8n/scripts/esm-package.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { writeFileSync } = require("node:fs");

writeFileSync("dist/esm/package.json", '{"type":"module"}\n');
2 changes: 2 additions & 0 deletions typescript/packages/traceai_n8n/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { N8nInstrumentation } from "./instrumentation.js";
export type { N8nInstrumentationConfig } from "./instrumentation.js";
Loading
Loading