@payloops/processor-core 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -133,7 +133,7 @@ Activities are the building blocks that workflows orchestrate:
|
|
|
133
133
|
### Prerequisites
|
|
134
134
|
|
|
135
135
|
- Node.js 22+
|
|
136
|
-
-
|
|
136
|
+
- npm
|
|
137
137
|
- Temporal server (via Docker)
|
|
138
138
|
- PostgreSQL (via Docker)
|
|
139
139
|
|
|
@@ -141,7 +141,7 @@ Activities are the building blocks that workflows orchestrate:
|
|
|
141
141
|
|
|
142
142
|
```bash
|
|
143
143
|
# Install dependencies
|
|
144
|
-
|
|
144
|
+
npm install
|
|
145
145
|
|
|
146
146
|
# Copy environment template
|
|
147
147
|
cp .env.example .env
|
|
@@ -150,18 +150,18 @@ cp .env.example .env
|
|
|
150
150
|
docker-compose up -d temporal
|
|
151
151
|
|
|
152
152
|
# Start worker in development mode
|
|
153
|
-
|
|
153
|
+
npm dev
|
|
154
154
|
```
|
|
155
155
|
|
|
156
156
|
### Available Scripts
|
|
157
157
|
|
|
158
158
|
| Command | Description |
|
|
159
159
|
|---------|-------------|
|
|
160
|
-
| `
|
|
161
|
-
| `
|
|
162
|
-
| `
|
|
163
|
-
| `
|
|
164
|
-
| `
|
|
160
|
+
| `npm dev` | Start worker with hot reload |
|
|
161
|
+
| `npm build` | Build for production |
|
|
162
|
+
| `npm start` | Run production worker |
|
|
163
|
+
| `npm typecheck` | Run TypeScript compiler |
|
|
164
|
+
| `npm lint` | Run ESLint |
|
|
165
165
|
|
|
166
166
|
## Configuration
|
|
167
167
|
|
|
@@ -1 +1,49 @@
|
|
|
1
1
|
export * from '@payloops/observability';
|
|
2
|
+
export { OpenTelemetryActivityInboundInterceptor, makeWorkflowExporter } from '@temporalio/interceptors-opentelemetry';
|
|
3
|
+
import { Context } from '@temporalio/activity';
|
|
4
|
+
import { ActivityInboundCallsInterceptor, ActivityExecuteInput, Next } from '@temporalio/worker';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Temporal Worker Interceptors with OpenTelemetry trace context propagation
|
|
8
|
+
*
|
|
9
|
+
* This module provides interceptors that:
|
|
10
|
+
* 1. Propagate trace context from workflow headers to activity spans
|
|
11
|
+
* 2. Add structured logging with trace context
|
|
12
|
+
* 3. Create proper parent-child span relationships
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
interface WorkerInterceptorsConfig {
|
|
16
|
+
/** Service/processor name for logging */
|
|
17
|
+
serviceName: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates an activity interceptor that combines OpenTelemetry tracing with structured logging
|
|
21
|
+
*
|
|
22
|
+
* Uses Temporal's OpenTelemetryActivityInboundInterceptor for trace propagation,
|
|
23
|
+
* and wraps it with additional structured logging that includes trace IDs.
|
|
24
|
+
*/
|
|
25
|
+
declare class TracingActivityInterceptor implements ActivityInboundCallsInterceptor {
|
|
26
|
+
private readonly otelInterceptor;
|
|
27
|
+
private readonly config;
|
|
28
|
+
private readonly ctx;
|
|
29
|
+
constructor(ctx: Context, config: WorkerInterceptorsConfig);
|
|
30
|
+
execute(input: ActivityExecuteInput, next: Next<ActivityInboundCallsInterceptor, 'execute'>): Promise<unknown>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Creates worker interceptors configuration with OpenTelemetry trace propagation
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* import { createWorkerInterceptors } from '@payloops/processor-core/observability';
|
|
38
|
+
*
|
|
39
|
+
* const worker = await Worker.create({
|
|
40
|
+
* // ... other config
|
|
41
|
+
* interceptors: createWorkerInterceptors({ serviceName: 'stripe-processor' }),
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
declare function createWorkerInterceptors(config: WorkerInterceptorsConfig): {
|
|
46
|
+
activityInbound: ((ctx: Context) => TracingActivityInterceptor)[];
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export { type WorkerInterceptorsConfig, createWorkerInterceptors };
|
|
@@ -1,2 +1,83 @@
|
|
|
1
1
|
// src/lib/observability/index.ts
|
|
2
2
|
export * from "@payloops/observability";
|
|
3
|
+
import {
|
|
4
|
+
makeWorkflowExporter,
|
|
5
|
+
OpenTelemetryActivityInboundInterceptor as OpenTelemetryActivityInboundInterceptor2
|
|
6
|
+
} from "@temporalio/interceptors-opentelemetry";
|
|
7
|
+
|
|
8
|
+
// src/lib/observability/interceptors.ts
|
|
9
|
+
import { trace } from "@opentelemetry/api";
|
|
10
|
+
import {
|
|
11
|
+
OpenTelemetryActivityInboundInterceptor
|
|
12
|
+
} from "@temporalio/interceptors-opentelemetry";
|
|
13
|
+
import { logger } from "@payloops/observability";
|
|
14
|
+
var TracingActivityInterceptor = class {
|
|
15
|
+
otelInterceptor;
|
|
16
|
+
config;
|
|
17
|
+
ctx;
|
|
18
|
+
constructor(ctx, config) {
|
|
19
|
+
this.ctx = ctx;
|
|
20
|
+
this.config = config;
|
|
21
|
+
this.otelInterceptor = new OpenTelemetryActivityInboundInterceptor(ctx);
|
|
22
|
+
}
|
|
23
|
+
async execute(input, next) {
|
|
24
|
+
const activityType = this.ctx.info.activityType;
|
|
25
|
+
const workflowId = this.ctx.info.workflowExecution.workflowId;
|
|
26
|
+
const startTime = Date.now();
|
|
27
|
+
const currentSpan = trace.getActiveSpan();
|
|
28
|
+
const spanContext = currentSpan?.spanContext();
|
|
29
|
+
logger.info(
|
|
30
|
+
{
|
|
31
|
+
activity: activityType,
|
|
32
|
+
workflowId,
|
|
33
|
+
processor: this.config.serviceName,
|
|
34
|
+
trace_id: spanContext?.traceId,
|
|
35
|
+
span_id: spanContext?.spanId
|
|
36
|
+
},
|
|
37
|
+
"Activity started"
|
|
38
|
+
);
|
|
39
|
+
try {
|
|
40
|
+
const result = await this.otelInterceptor.execute(input, next);
|
|
41
|
+
const finalSpan = trace.getActiveSpan();
|
|
42
|
+
const finalSpanContext = finalSpan?.spanContext();
|
|
43
|
+
logger.info(
|
|
44
|
+
{
|
|
45
|
+
activity: activityType,
|
|
46
|
+
workflowId,
|
|
47
|
+
duration: Date.now() - startTime,
|
|
48
|
+
trace_id: finalSpanContext?.traceId ?? spanContext?.traceId,
|
|
49
|
+
span_id: finalSpanContext?.spanId ?? spanContext?.spanId
|
|
50
|
+
},
|
|
51
|
+
"Activity completed"
|
|
52
|
+
);
|
|
53
|
+
return result;
|
|
54
|
+
} catch (error) {
|
|
55
|
+
const finalSpan = trace.getActiveSpan();
|
|
56
|
+
const finalSpanContext = finalSpan?.spanContext();
|
|
57
|
+
logger.error(
|
|
58
|
+
{
|
|
59
|
+
activity: activityType,
|
|
60
|
+
workflowId,
|
|
61
|
+
error,
|
|
62
|
+
duration: Date.now() - startTime,
|
|
63
|
+
trace_id: finalSpanContext?.traceId ?? spanContext?.traceId,
|
|
64
|
+
span_id: finalSpanContext?.spanId ?? spanContext?.spanId
|
|
65
|
+
},
|
|
66
|
+
"Activity failed"
|
|
67
|
+
);
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
function createWorkerInterceptors(config) {
|
|
73
|
+
return {
|
|
74
|
+
activityInbound: [
|
|
75
|
+
(ctx) => new TracingActivityInterceptor(ctx, config)
|
|
76
|
+
]
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export {
|
|
80
|
+
OpenTelemetryActivityInboundInterceptor2 as OpenTelemetryActivityInboundInterceptor,
|
|
81
|
+
createWorkerInterceptors,
|
|
82
|
+
makeWorkflowExporter
|
|
83
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloops/processor-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -30,12 +30,18 @@
|
|
|
30
30
|
"release:major": "npm run build && npm run typecheck && npm version major && git push && git push --tags"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@payloops/observability": "^0.0.
|
|
33
|
+
"@payloops/observability": "^0.0.13",
|
|
34
|
+
"@temporalio/interceptors-opentelemetry": "^1.11.7",
|
|
35
|
+
"@temporalio/worker": "^1.11.7",
|
|
36
|
+
"@opentelemetry/api": "^1.9.0",
|
|
37
|
+
"@opentelemetry/sdk-trace-base": "^1.25.1"
|
|
34
38
|
},
|
|
35
39
|
"devDependencies": {
|
|
40
|
+
"@eslint/js": "^9.39.2",
|
|
36
41
|
"@types/node": "^22.0.0",
|
|
37
42
|
"eslint": "^9.0.0",
|
|
38
43
|
"tsup": "^8.3.5",
|
|
39
|
-
"typescript": "^5.9.3"
|
|
44
|
+
"typescript": "^5.9.3",
|
|
45
|
+
"typescript-eslint": "^8.53.0"
|
|
40
46
|
}
|
|
41
47
|
}
|