@exulu/backend 1.47.0 → 1.48.2

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.
@@ -1,122 +0,0 @@
1
- # Winston Logger Implementation
2
-
3
- This document describes how winston logging has been integrated into the Exulu backend across Express server, MCP server, and worker instances.
4
-
5
- ## Architecture Overview
6
-
7
- The logging system is centralized through a logger factory function in `src/exulu/logger.ts` that creates winston logger instances with conditional OpenTelemetry integration.
8
-
9
- ## Logger Configuration
10
-
11
- ### Core Logger Setup (`src/registry/logger.ts`)
12
-
13
- The `createLogger` function accepts an `enableOtel` boolean parameter to conditionally enable OpenTelemetry transport:
14
-
15
- ```typescript
16
- const createLogger = ({ enableOtel }: { enableOtel: boolean }) => {
17
- const logger = winston.createLogger({
18
- level: 'debug',
19
- format: winston.format.combine(
20
- winston.format.timestamp(),
21
- winston.format.errors({ stack: true }),
22
- winston.format.metadata(),
23
- winston.format.json()
24
- ),
25
- defaultMeta: {
26
- service: 'Exulu',
27
- environment: process.env.NODE_ENV || 'development',
28
- },
29
- transports: [
30
- new winston.transports.Console(),
31
- ...(enableOtel ? [new OpenTelemetryTransportV3()] : []),
32
- ],
33
- })
34
- return logger;
35
- }
36
- ```
37
-
38
- ### Configuration-Driven Telemetry
39
-
40
- The ExuluApp class manages telemetry configuration through the `ExuluConfig` type:
41
-
42
- ```typescript
43
- export type ExuluConfig = {
44
- telemetry?: {
45
- enabled: boolean,
46
- }
47
- workers: {
48
- enabled: boolean,
49
- logsDir?: string,
50
- telemetry?: {
51
- enabled: boolean,
52
- }
53
- }
54
- // ...
55
- }
56
- ```
57
-
58
- ## Integration Points
59
-
60
- ### 1. Express Server Logging
61
-
62
- In `src/exulu/app/index`, the Express server creates a logger instance:
63
-
64
- ```typescript
65
- const logger = createLogger({
66
- enableOtel: this._config?.telemetry?.enabled ?? false
67
- })
68
- ```
69
-
70
- The logger is then passed to `createExpressRoutes()` for use throughout the Express application.
71
-
72
- ### 2. BullMQ Workers Logging
73
-
74
- In `src/exulu/app`, workers create their own logger instance:
75
-
76
- ```typescript
77
- const logger = createLogger({
78
- enableOtel: this._config?.workers?.telemetry?.enabled ?? false
79
- })
80
- ```
81
-
82
- Workers have separate telemetry configuration allowing independent control of logging transport.
83
-
84
- ### 3. MCP Server Logging
85
-
86
- The MCP server receives the logger instance via dependency injection in `src/mcp/index.ts:31`:
87
-
88
- ```typescript
89
- create = async ({ express, contexts, agents, config, tools, tracer, logger }: {
90
- // ... other params
91
- logger: Logger
92
- }) => {
93
- // Logger is passed in and used throughout MCP server
94
- }
95
- ```
96
-
97
- ## Features
98
-
99
- - **Structured JSON Logging**: All logs are formatted as JSON with timestamps and metadata
100
- - **Error Stack Traces**: Automatic stack trace capture for error objects
101
- - **Environment Context**: Automatic service name and environment labeling
102
- - **Conditional OpenTelemetry**: OTel transport enabled based on configuration
103
- - **Console Fallback**: Always includes console transport for development
104
- - **Instance-Level Control**: Express, Workers, and MCP can have independent telemetry settings
105
-
106
- ## Usage
107
-
108
- Configure telemetry in your ExuluApp config:
109
-
110
- ```typescript
111
- const config: ExuluConfig = {
112
- telemetry: {
113
- enabled: true // Enables OTel for Express and MCP
114
- },
115
- workers: {
116
- enabled: true,
117
- telemetry: {
118
- enabled: false // Workers use console-only logging
119
- }
120
- }
121
- }
122
- ```
@@ -1,145 +0,0 @@
1
- # OpenTelemetry (OTEL) Implementation
2
-
3
- ## Overview
4
-
5
- Exulu has built-in OpenTelemetry support for distributed tracing and logging. OTEL can be enabled/disabled individually for different components (workers, MCP, and Express server) through configuration.
6
-
7
- **Current Support**: The implementation currently supports SigNoz (both Cloud and self-hosted) as the observability backend. Future versions may include support for other OTEL-compatible backends.
8
-
9
- ## Architecture
10
-
11
- ### Core Components
12
-
13
- 1. **ExuluOtel Class** (`src/registry/otel.ts`)
14
- - Factory function that creates a NodeSDK instance
15
- - Configures trace and log exporters for SigNoz
16
- - Sets up automatic instrumentation
17
- - Handles graceful shutdown
18
-
19
- 2. **Configuration** (`src/registry/index.ts`)
20
- - Telemetry can be enabled at the app level and component level
21
- - Each component (workers, MCP, Express) has individual telemetry controls
22
-
23
- ## Usage
24
-
25
- ### Basic Setup
26
-
27
- ```typescript
28
- import { ExuluOtel } from "@exulu/backend";
29
-
30
- const otel = ExuluOtel.create({
31
- SIGNOZ_TRACES_URL: process.env.SIGNOZ_TRACES_URL!,
32
- SIGNOZ_LOGS_URL: process.env.SIGNOZ_LOGS_URL!,
33
- SIGNOZ_ACCESS_TOKEN: process.env.SIGNOZ_ACCESS_TOKEN!
34
- });
35
-
36
- otel.start();
37
- ```
38
-
39
- ### Configuration
40
-
41
- ```typescript
42
- const config: ExuluConfig = {
43
- telemetry: {
44
- enabled: true // Global telemetry switch
45
- },
46
- workers: {
47
- enabled: true,
48
- telemetry: {
49
- enabled: true // Worker-specific telemetry
50
- }
51
- },
52
- MCP: {
53
- enabled: true
54
- // MCP uses global telemetry setting
55
- }
56
- };
57
- ```
58
-
59
- ## Implementation Details
60
-
61
- ### Trace Generation
62
-
63
- When telemetry is enabled, Exulu automatically generates trace spans for:
64
-
65
- - **Express Server Routes** (`src/registry/routes.ts:166`)
66
- - **BullMQ Workers** (`src/registry/workers.ts:133`)
67
- - **MCP Operations** (`src/registry/index.ts:176`)
68
-
69
- ### Tracer Initialization
70
-
71
- ```typescript
72
- // Tracer is created when telemetry is enabled
73
- let tracer: Tracer | undefined;
74
- if (config?.telemetry?.enabled) {
75
- tracer = trace.getTracer("exulu", "1.0.0");
76
- }
77
- ```
78
-
79
- ### SigNoz Integration
80
-
81
- The current implementation is specifically designed for SigNoz integration (supports both SigNoz Cloud and self-hosted deployments):
82
-
83
- - **Service Name**: `Exulu`
84
- - **Traces**: Exported to `SIGNOZ_TRACES_URL`
85
- - **Logs**: Exported to `SIGNOZ_LOGS_URL`
86
- - **Authentication**: Uses `signoz-access-token` header
87
- - **Protocol**: OTLP over HTTP with SigNoz-specific headers
88
-
89
- ### Auto-Instrumentation
90
-
91
- Uses `@opentelemetry/auto-instrumentations-node` for automatic instrumentation of:
92
- - HTTP requests/responses
93
- - Database queries
94
- - File system operations
95
- - And more Node.js modules
96
-
97
- ### Graceful Shutdown
98
-
99
- OTEL SDK automatically shuts down on `SIGTERM` signal:
100
-
101
- ```typescript
102
- process.on('SIGTERM', () => {
103
- sdk.shutdown()
104
- .then(() => console.log('Tracing terminated'))
105
- .catch((error) => console.log('Error terminating tracing', error))
106
- .finally(() => process.exit(0));
107
- });
108
- ```
109
-
110
- ## Environment Variables
111
-
112
- Required environment variables for SigNoz integration:
113
-
114
- - `SIGNOZ_TRACES_URL`: URL for trace export
115
- - `SIGNOZ_LOGS_URL`: URL for log export
116
- - `SIGNOZ_ACCESS_TOKEN`: Authentication token
117
-
118
- ## Component-Level Control
119
-
120
- ### Workers
121
- - Controlled by `config.workers.telemetry.enabled`
122
- - Creates tracer instance when enabled
123
- - Passes tracer to worker creation
124
-
125
- ### Express Server
126
- - Controlled by `config.telemetry.enabled`
127
- - Creates tracer for route instrumentation
128
- - Integrates with logger for structured logging
129
-
130
- ### MCP Server
131
- - Uses global `config.telemetry.enabled` setting
132
- - Receives tracer instance from parent ExuluApp
133
- - Traces MCP protocol operations
134
-
135
- ## Logger Integration
136
-
137
- Each component creates an OTEL-aware logger:
138
-
139
- ```typescript
140
- const logger = createLogger({
141
- enableOtel: config?.telemetry?.enabled ?? false
142
- });
143
- ```
144
-
145
- This enables correlation between traces and structured logs.