@noony-serverless/core 0.3.3 → 0.4.0
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/build/core/containerPool.d.ts +129 -26
- package/build/core/containerPool.js +213 -68
- package/build/core/handler.d.ts +2 -2
- package/build/core/handler.js +6 -12
- package/build/core/index.d.ts +1 -0
- package/build/core/index.js +1 -0
- package/build/core/logger.d.ts +89 -1
- package/build/core/logger.js +136 -5
- package/build/core/telemetry/config.d.ts +331 -0
- package/build/core/telemetry/config.js +153 -0
- package/build/core/telemetry/index.d.ts +22 -0
- package/build/core/telemetry/index.js +45 -0
- package/build/core/telemetry/provider.d.ts +203 -0
- package/build/core/telemetry/provider.js +3 -0
- package/build/core/telemetry/providers/console-provider.d.ts +54 -0
- package/build/core/telemetry/providers/console-provider.js +124 -0
- package/build/core/telemetry/providers/index.d.ts +10 -0
- package/build/core/telemetry/providers/index.js +19 -0
- package/build/core/telemetry/providers/noop-provider.d.ts +51 -0
- package/build/core/telemetry/providers/noop-provider.js +67 -0
- package/build/core/telemetry/providers/opentelemetry-provider.d.ts +102 -0
- package/build/core/telemetry/providers/opentelemetry-provider.js +342 -0
- package/build/middlewares/ProcessingMiddleware.d.ts +6 -3
- package/build/middlewares/ProcessingMiddleware.js +3 -0
- package/build/middlewares/dependencyInjectionMiddleware.d.ts +23 -11
- package/build/middlewares/dependencyInjectionMiddleware.js +36 -12
- package/build/middlewares/guards/adapters/CustomTokenVerificationPortAdapter.d.ts +1 -1
- package/build/middlewares/guards/guards/FastAuthGuard.d.ts +5 -5
- package/build/middlewares/guards/guards/FastAuthGuard.js +3 -2
- package/build/middlewares/guards/guards/PermissionGuardFactory.d.ts +7 -9
- package/build/middlewares/guards/resolvers/ExpressionPermissionResolver.d.ts +1 -1
- package/build/middlewares/guards/resolvers/ExpressionPermissionResolver.js +1 -1
- package/build/middlewares/guards/resolvers/PermissionResolver.d.ts +1 -1
- package/build/middlewares/guards/resolvers/PlainPermissionResolver.d.ts +1 -1
- package/build/middlewares/guards/resolvers/WildcardPermissionResolver.d.ts +1 -1
- package/build/middlewares/guards/services/FastUserContextService.d.ts +11 -32
- package/build/middlewares/headerVariablesMiddleware.d.ts +8 -4
- package/build/middlewares/headerVariablesMiddleware.js +5 -1
- package/build/middlewares/httpAttributesMiddleware.d.ts +5 -3
- package/build/middlewares/httpAttributesMiddleware.js +3 -1
- package/build/middlewares/index.d.ts +1 -0
- package/build/middlewares/index.js +1 -0
- package/build/middlewares/openTelemetryMiddleware.d.ts +162 -0
- package/build/middlewares/openTelemetryMiddleware.js +359 -0
- package/build/middlewares/rateLimitingMiddleware.d.ts +8 -6
- package/build/middlewares/rateLimitingMiddleware.js +19 -6
- package/build/middlewares/securityAuditMiddleware.d.ts +6 -3
- package/build/middlewares/securityAuditMiddleware.js +3 -0
- package/build/middlewares/securityHeadersMiddleware.d.ts +5 -2
- package/build/middlewares/securityHeadersMiddleware.js +3 -0
- package/build/middlewares/validationMiddleware.d.ts +8 -4
- package/build/middlewares/validationMiddleware.js +5 -1
- package/build/utils/container.utils.js +4 -1
- package/build/utils/fastify-wrapper.d.ts +74 -0
- package/build/utils/fastify-wrapper.js +175 -0
- package/build/utils/index.d.ts +4 -0
- package/build/utils/index.js +23 -1
- package/build/utils/otel.helper.d.ts +122 -0
- package/build/utils/otel.helper.js +258 -0
- package/build/utils/pubsub-trace.utils.d.ts +102 -0
- package/build/utils/pubsub-trace.utils.js +155 -0
- package/build/utils/wrapper-utils.d.ts +177 -0
- package/build/utils/wrapper-utils.js +236 -0
- package/package.json +61 -2
package/build/core/logger.d.ts
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
|
+
import type { Span, Context as OtelContext } from '@opentelemetry/api';
|
|
2
|
+
import { type OTELLogContext } from '../utils/otel.helper';
|
|
1
3
|
export interface LogOptions {
|
|
2
4
|
structuredData?: boolean;
|
|
3
5
|
[key: string]: boolean | string | number | object | undefined;
|
|
4
6
|
}
|
|
7
|
+
export interface LoggerConfig {
|
|
8
|
+
enableOTEL?: boolean;
|
|
9
|
+
structuredLogging?: boolean;
|
|
10
|
+
debugMode?: boolean;
|
|
11
|
+
}
|
|
5
12
|
declare class Logger {
|
|
6
13
|
private logDataPool;
|
|
7
14
|
private isDebugEnabled;
|
|
8
15
|
private timestampCache;
|
|
9
16
|
private lastTimestamp;
|
|
10
|
-
|
|
17
|
+
private enableOTEL;
|
|
18
|
+
private otelContext?;
|
|
19
|
+
constructor(config?: LoggerConfig);
|
|
11
20
|
/**
|
|
12
21
|
* Performance optimized timestamp generation with caching
|
|
13
22
|
* Cache timestamps for up to 1 second to reduce Date object creation
|
|
@@ -15,6 +24,7 @@ declare class Logger {
|
|
|
15
24
|
private getTimestamp;
|
|
16
25
|
/**
|
|
17
26
|
* Optimized log method with object pooling and lazy evaluation
|
|
27
|
+
* Includes automatic OTEL trace/span ID injection when enabled
|
|
18
28
|
*/
|
|
19
29
|
private log;
|
|
20
30
|
/**
|
|
@@ -28,6 +38,83 @@ declare class Logger {
|
|
|
28
38
|
* Performance monitoring method for internal framework use
|
|
29
39
|
*/
|
|
30
40
|
logPerformance(operation: string, duration: number, metadata?: Record<string, unknown>): void;
|
|
41
|
+
/**
|
|
42
|
+
* Create a child logger with a specific span context
|
|
43
|
+
*
|
|
44
|
+
* This method creates a new logger instance that will automatically include
|
|
45
|
+
* the trace/span IDs from the provided span in all log entries.
|
|
46
|
+
*
|
|
47
|
+
* Useful for passing logger instances to services/functions that need
|
|
48
|
+
* to log within a specific span context.
|
|
49
|
+
*
|
|
50
|
+
* @param span - OpenTelemetry span to attach to logs
|
|
51
|
+
* @returns New logger instance with span context
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* import { trace } from '@opentelemetry/api';
|
|
56
|
+
* import { logger } from '@noony-serverless/core';
|
|
57
|
+
*
|
|
58
|
+
* const tracer = trace.getTracer('my-service');
|
|
59
|
+
* const span = tracer.startSpan('process-order');
|
|
60
|
+
*
|
|
61
|
+
* const spanLogger = logger.withSpan(span);
|
|
62
|
+
* spanLogger.info('Processing order'); // Includes span's trace/span IDs
|
|
63
|
+
*
|
|
64
|
+
* span.end();
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
withSpan(span: Span): Logger;
|
|
68
|
+
/**
|
|
69
|
+
* Create a child logger with a specific OTEL context
|
|
70
|
+
*
|
|
71
|
+
* This method creates a new logger instance that will automatically include
|
|
72
|
+
* trace/span IDs from the provided OTEL context in all log entries.
|
|
73
|
+
*
|
|
74
|
+
* Useful when working with OTEL Context propagation (e.g., Pub/Sub messages).
|
|
75
|
+
*
|
|
76
|
+
* @param context - OpenTelemetry context to extract span from
|
|
77
|
+
* @returns New logger instance with context
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* import { context, propagation } from '@opentelemetry/api';
|
|
82
|
+
* import { logger } from '@noony-serverless/core';
|
|
83
|
+
*
|
|
84
|
+
* // Extract context from Pub/Sub message
|
|
85
|
+
* const extractedContext = propagation.extract(
|
|
86
|
+
* context.active(),
|
|
87
|
+
* message.attributes
|
|
88
|
+
* );
|
|
89
|
+
*
|
|
90
|
+
* const contextLogger = logger.withOTEL(extractedContext);
|
|
91
|
+
* contextLogger.info('Processing message'); // Includes trace/span IDs
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
withOTEL(otelContext: OtelContext): Logger;
|
|
95
|
+
/**
|
|
96
|
+
* Create a child logger with custom OTEL context
|
|
97
|
+
*
|
|
98
|
+
* This method creates a new logger instance with manually specified
|
|
99
|
+
* trace/span IDs. Useful when you have trace context from external sources.
|
|
100
|
+
*
|
|
101
|
+
* @param context - OTEL log context with trace/span IDs
|
|
102
|
+
* @returns New logger instance with custom context
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* import { logger } from '@noony-serverless/core';
|
|
107
|
+
*
|
|
108
|
+
* const customLogger = logger.withContext({
|
|
109
|
+
* traceId: '13ea7e3c2d3b4547baaa399062df1f2d',
|
|
110
|
+
* spanId: '1234567890123456',
|
|
111
|
+
* traceFlags: 1
|
|
112
|
+
* });
|
|
113
|
+
*
|
|
114
|
+
* customLogger.info('Custom trace context'); // Includes specified IDs
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
withContext(context: OTELLogContext): Logger;
|
|
31
118
|
/**
|
|
32
119
|
* Get logger statistics for monitoring
|
|
33
120
|
*/
|
|
@@ -35,6 +122,7 @@ declare class Logger {
|
|
|
35
122
|
poolSize: number;
|
|
36
123
|
maxPoolSize: number;
|
|
37
124
|
debugEnabled: boolean;
|
|
125
|
+
otelEnabled: boolean;
|
|
38
126
|
};
|
|
39
127
|
}
|
|
40
128
|
export declare const logger: Logger;
|
package/build/core/logger.js
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Logger = exports.logger = void 0;
|
|
4
|
+
const otel_helper_1 = require("../utils/otel.helper");
|
|
5
|
+
// Import trace for dynamic OTEL operations
|
|
6
|
+
let trace = null;
|
|
7
|
+
try {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
9
|
+
trace = require('@opentelemetry/api').trace;
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
// OTEL not available
|
|
13
|
+
trace = null;
|
|
14
|
+
}
|
|
4
15
|
// Performance optimization: Object pool for log data to reduce GC pressure
|
|
5
16
|
class LogDataPool {
|
|
6
17
|
pool = [];
|
|
@@ -45,12 +56,20 @@ class Logger {
|
|
|
45
56
|
isDebugEnabled;
|
|
46
57
|
timestampCache = '';
|
|
47
58
|
lastTimestamp = 0;
|
|
48
|
-
|
|
59
|
+
enableOTEL;
|
|
60
|
+
otelContext;
|
|
61
|
+
constructor(config) {
|
|
49
62
|
// Performance optimization: Cache debug mode check
|
|
50
63
|
this.isDebugEnabled =
|
|
51
|
-
|
|
52
|
-
process.env.
|
|
53
|
-
|
|
64
|
+
config?.debugMode ??
|
|
65
|
+
(process.env.NODE_ENV === 'development' ||
|
|
66
|
+
process.env.DEBUG === 'true' ||
|
|
67
|
+
process.env.LOG_LEVEL === 'debug');
|
|
68
|
+
// Enable OTEL integration if configured or in production
|
|
69
|
+
this.enableOTEL =
|
|
70
|
+
config?.enableOTEL ??
|
|
71
|
+
(process.env.OTEL_ENABLED === 'true' ||
|
|
72
|
+
process.env.NODE_ENV === 'production');
|
|
54
73
|
}
|
|
55
74
|
/**
|
|
56
75
|
* Performance optimized timestamp generation with caching
|
|
@@ -67,6 +86,7 @@ class Logger {
|
|
|
67
86
|
}
|
|
68
87
|
/**
|
|
69
88
|
* Optimized log method with object pooling and lazy evaluation
|
|
89
|
+
* Includes automatic OTEL trace/span ID injection when enabled
|
|
70
90
|
*/
|
|
71
91
|
log(level, message, options) {
|
|
72
92
|
// Performance optimization: Early return for debug logs in production
|
|
@@ -78,7 +98,16 @@ class Logger {
|
|
|
78
98
|
logData.timestamp = this.getTimestamp();
|
|
79
99
|
logData.level = level;
|
|
80
100
|
logData.message = message;
|
|
81
|
-
// Add
|
|
101
|
+
// Add OTEL context if enabled (automatic trace/span ID injection)
|
|
102
|
+
if (this.enableOTEL) {
|
|
103
|
+
// Use stored context if available (from withSpan/withOTEL)
|
|
104
|
+
// Otherwise, get from active span (createOTELMixin)
|
|
105
|
+
const otelContext = this.otelContext || (0, otel_helper_1.createOTELMixin)();
|
|
106
|
+
if (otelContext && Object.keys(otelContext).length > 0) {
|
|
107
|
+
Object.assign(logData, otelContext);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// Add options if provided (options override OTEL context if keys conflict)
|
|
82
111
|
if (options) {
|
|
83
112
|
Object.assign(logData, options);
|
|
84
113
|
}
|
|
@@ -119,6 +148,107 @@ class Logger {
|
|
|
119
148
|
});
|
|
120
149
|
}
|
|
121
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Create a child logger with a specific span context
|
|
153
|
+
*
|
|
154
|
+
* This method creates a new logger instance that will automatically include
|
|
155
|
+
* the trace/span IDs from the provided span in all log entries.
|
|
156
|
+
*
|
|
157
|
+
* Useful for passing logger instances to services/functions that need
|
|
158
|
+
* to log within a specific span context.
|
|
159
|
+
*
|
|
160
|
+
* @param span - OpenTelemetry span to attach to logs
|
|
161
|
+
* @returns New logger instance with span context
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* import { trace } from '@opentelemetry/api';
|
|
166
|
+
* import { logger } from '@noony-serverless/core';
|
|
167
|
+
*
|
|
168
|
+
* const tracer = trace.getTracer('my-service');
|
|
169
|
+
* const span = tracer.startSpan('process-order');
|
|
170
|
+
*
|
|
171
|
+
* const spanLogger = logger.withSpan(span);
|
|
172
|
+
* spanLogger.info('Processing order'); // Includes span's trace/span IDs
|
|
173
|
+
*
|
|
174
|
+
* span.end();
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
withSpan(span) {
|
|
178
|
+
const childLogger = new Logger({
|
|
179
|
+
enableOTEL: this.enableOTEL,
|
|
180
|
+
debugMode: this.isDebugEnabled,
|
|
181
|
+
});
|
|
182
|
+
childLogger.otelContext = (0, otel_helper_1.getOTELContextFromSpan)(span);
|
|
183
|
+
return childLogger;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Create a child logger with a specific OTEL context
|
|
187
|
+
*
|
|
188
|
+
* This method creates a new logger instance that will automatically include
|
|
189
|
+
* trace/span IDs from the provided OTEL context in all log entries.
|
|
190
|
+
*
|
|
191
|
+
* Useful when working with OTEL Context propagation (e.g., Pub/Sub messages).
|
|
192
|
+
*
|
|
193
|
+
* @param context - OpenTelemetry context to extract span from
|
|
194
|
+
* @returns New logger instance with context
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```typescript
|
|
198
|
+
* import { context, propagation } from '@opentelemetry/api';
|
|
199
|
+
* import { logger } from '@noony-serverless/core';
|
|
200
|
+
*
|
|
201
|
+
* // Extract context from Pub/Sub message
|
|
202
|
+
* const extractedContext = propagation.extract(
|
|
203
|
+
* context.active(),
|
|
204
|
+
* message.attributes
|
|
205
|
+
* );
|
|
206
|
+
*
|
|
207
|
+
* const contextLogger = logger.withOTEL(extractedContext);
|
|
208
|
+
* contextLogger.info('Processing message'); // Includes trace/span IDs
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
withOTEL(otelContext) {
|
|
212
|
+
if (!trace) {
|
|
213
|
+
// OTEL not available, return this logger unchanged
|
|
214
|
+
return this;
|
|
215
|
+
}
|
|
216
|
+
const span = trace.getSpan(otelContext);
|
|
217
|
+
if (!span) {
|
|
218
|
+
return this;
|
|
219
|
+
}
|
|
220
|
+
return this.withSpan(span);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Create a child logger with custom OTEL context
|
|
224
|
+
*
|
|
225
|
+
* This method creates a new logger instance with manually specified
|
|
226
|
+
* trace/span IDs. Useful when you have trace context from external sources.
|
|
227
|
+
*
|
|
228
|
+
* @param context - OTEL log context with trace/span IDs
|
|
229
|
+
* @returns New logger instance with custom context
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```typescript
|
|
233
|
+
* import { logger } from '@noony-serverless/core';
|
|
234
|
+
*
|
|
235
|
+
* const customLogger = logger.withContext({
|
|
236
|
+
* traceId: '13ea7e3c2d3b4547baaa399062df1f2d',
|
|
237
|
+
* spanId: '1234567890123456',
|
|
238
|
+
* traceFlags: 1
|
|
239
|
+
* });
|
|
240
|
+
*
|
|
241
|
+
* customLogger.info('Custom trace context'); // Includes specified IDs
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
withContext(context) {
|
|
245
|
+
const childLogger = new Logger({
|
|
246
|
+
enableOTEL: this.enableOTEL,
|
|
247
|
+
debugMode: this.isDebugEnabled,
|
|
248
|
+
});
|
|
249
|
+
childLogger.otelContext = context;
|
|
250
|
+
return childLogger;
|
|
251
|
+
}
|
|
122
252
|
/**
|
|
123
253
|
* Get logger statistics for monitoring
|
|
124
254
|
*/
|
|
@@ -127,6 +257,7 @@ class Logger {
|
|
|
127
257
|
poolSize: this.logDataPool['pool'].length,
|
|
128
258
|
maxPoolSize: this.logDataPool['maxPoolSize'],
|
|
129
259
|
debugEnabled: this.isDebugEnabled,
|
|
260
|
+
otelEnabled: this.enableOTEL,
|
|
130
261
|
};
|
|
131
262
|
}
|
|
132
263
|
}
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telemetry Configuration
|
|
3
|
+
*
|
|
4
|
+
* Centralized configuration for OpenTelemetry setup including:
|
|
5
|
+
* - Service resource attributes
|
|
6
|
+
* - Trace exporters and propagators
|
|
7
|
+
* - Metrics configuration
|
|
8
|
+
* - Platform-specific presets
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Span processor configuration for aggressive export in serverless environments
|
|
12
|
+
*/
|
|
13
|
+
export interface SpanProcessorConfig {
|
|
14
|
+
/**
|
|
15
|
+
* Maximum queue size before dropping spans
|
|
16
|
+
* @default 100
|
|
17
|
+
*/
|
|
18
|
+
maxQueueSize?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Maximum number of spans to export in a single batch
|
|
21
|
+
* For scale-to-zero environments, set to 1 for immediate export
|
|
22
|
+
* @default 1 (immediate export for serverless)
|
|
23
|
+
*/
|
|
24
|
+
maxExportBatchSize?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Delay in milliseconds between export attempts
|
|
27
|
+
* For scale-to-zero environments, use aggressive timing (100ms)
|
|
28
|
+
* @default 100 (very aggressive for Cloud Run)
|
|
29
|
+
*/
|
|
30
|
+
scheduledDelayMillis?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Timeout in milliseconds for export operations
|
|
33
|
+
* @default 30000 (30 seconds)
|
|
34
|
+
*/
|
|
35
|
+
exportTimeoutMillis?: number;
|
|
36
|
+
/**
|
|
37
|
+
* Enable detailed export logging for debugging
|
|
38
|
+
* @default false
|
|
39
|
+
*/
|
|
40
|
+
enableExportLogging?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* HTTP instrumentation configuration
|
|
44
|
+
*/
|
|
45
|
+
export interface HttpInstrumentationConfig {
|
|
46
|
+
/**
|
|
47
|
+
* Enable HTTP instrumentation
|
|
48
|
+
* @default true
|
|
49
|
+
*/
|
|
50
|
+
enabled?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Require parent span for incoming HTTP requests
|
|
53
|
+
* Set to false to create root spans for all requests
|
|
54
|
+
* @default false (creates root spans)
|
|
55
|
+
*/
|
|
56
|
+
requireParentforIncomingSpans?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Require parent span for outgoing HTTP requests
|
|
59
|
+
* @default false
|
|
60
|
+
*/
|
|
61
|
+
requireParentforOutgoingSpans?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Ignore health check endpoints
|
|
64
|
+
* @default true
|
|
65
|
+
*/
|
|
66
|
+
ignoreHealthChecks?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Trace OPTIONS requests (CORS preflight)
|
|
69
|
+
* @default false (reduces noise)
|
|
70
|
+
*/
|
|
71
|
+
traceOptionsRequests?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Custom URL patterns to ignore (regex strings)
|
|
74
|
+
*/
|
|
75
|
+
ignoreUrls?: string[];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Auto-instrumentation configuration
|
|
79
|
+
*/
|
|
80
|
+
export interface InstrumentationConfig {
|
|
81
|
+
/**
|
|
82
|
+
* Enable HTTP instrumentation
|
|
83
|
+
* @default true
|
|
84
|
+
*/
|
|
85
|
+
http?: boolean | HttpInstrumentationConfig;
|
|
86
|
+
/**
|
|
87
|
+
* Enable MongoDB instrumentation
|
|
88
|
+
* @default true
|
|
89
|
+
*/
|
|
90
|
+
mongodb?: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Enable Pino logger instrumentation
|
|
93
|
+
* @default true
|
|
94
|
+
*/
|
|
95
|
+
pino?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Enable Fastify instrumentation
|
|
98
|
+
* WARNING: Should be disabled when using HTTP instrumentation to prevent duplicates
|
|
99
|
+
* @default false (prevents duplicate spans)
|
|
100
|
+
*/
|
|
101
|
+
fastify?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Enable DNS instrumentation
|
|
104
|
+
* @default false (reduces noise)
|
|
105
|
+
*/
|
|
106
|
+
dns?: boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Enable Net instrumentation
|
|
109
|
+
* @default false (reduces noise)
|
|
110
|
+
*/
|
|
111
|
+
net?: boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Enable FS instrumentation
|
|
114
|
+
* @default false (reduces noise)
|
|
115
|
+
*/
|
|
116
|
+
fs?: boolean;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Metrics configuration
|
|
120
|
+
*/
|
|
121
|
+
export interface MetricsConfig {
|
|
122
|
+
/**
|
|
123
|
+
* Enable metrics collection
|
|
124
|
+
* @default true
|
|
125
|
+
*/
|
|
126
|
+
enabled?: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Export interval in milliseconds
|
|
129
|
+
* @default 60000 (60 seconds)
|
|
130
|
+
*/
|
|
131
|
+
exportIntervalMillis?: number;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Telemetry configuration interface
|
|
135
|
+
*/
|
|
136
|
+
export interface TelemetryConfig {
|
|
137
|
+
/**
|
|
138
|
+
* Service name for identification in traces
|
|
139
|
+
* @example 'order-service'
|
|
140
|
+
*/
|
|
141
|
+
serviceName: string;
|
|
142
|
+
/**
|
|
143
|
+
* Service version for deployment tracking
|
|
144
|
+
* @example '2.1.0'
|
|
145
|
+
*/
|
|
146
|
+
serviceVersion: string;
|
|
147
|
+
/**
|
|
148
|
+
* Deployment environment
|
|
149
|
+
* @example 'production', 'staging', 'development'
|
|
150
|
+
*/
|
|
151
|
+
environment: string;
|
|
152
|
+
/**
|
|
153
|
+
* Trace exporters configuration
|
|
154
|
+
*/
|
|
155
|
+
exporters?: {
|
|
156
|
+
traces?: Array<{
|
|
157
|
+
endpoint: string;
|
|
158
|
+
headers?: Record<string, string>;
|
|
159
|
+
}>;
|
|
160
|
+
metrics?: Array<{
|
|
161
|
+
endpoint: string;
|
|
162
|
+
headers?: Record<string, string>;
|
|
163
|
+
}>;
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* Sampling configuration for traces
|
|
167
|
+
*/
|
|
168
|
+
sampling?: {
|
|
169
|
+
ratio: number;
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Propagation format configuration
|
|
173
|
+
* Controls which trace context formats to support
|
|
174
|
+
*/
|
|
175
|
+
propagation?: {
|
|
176
|
+
/**
|
|
177
|
+
* Enable Cloud Trace propagation for Google Cloud Platform
|
|
178
|
+
* Uses X-Cloud-Trace-Context header format
|
|
179
|
+
* @default true when running on GCP
|
|
180
|
+
*/
|
|
181
|
+
cloudTrace?: boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Enable W3C Trace Context propagation
|
|
184
|
+
* Uses traceparent/tracestate header format
|
|
185
|
+
* @default true
|
|
186
|
+
*/
|
|
187
|
+
w3c?: boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Additional custom propagators
|
|
190
|
+
*/
|
|
191
|
+
custom?: string[];
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
194
|
+
* Span processor configuration for aggressive export
|
|
195
|
+
* Optimized for scale-to-zero serverless environments
|
|
196
|
+
*/
|
|
197
|
+
spanProcessor?: SpanProcessorConfig;
|
|
198
|
+
/**
|
|
199
|
+
* Auto-instrumentation configuration
|
|
200
|
+
* Controls which libraries are automatically instrumented
|
|
201
|
+
*/
|
|
202
|
+
instrumentation?: InstrumentationConfig;
|
|
203
|
+
/**
|
|
204
|
+
* Metrics configuration
|
|
205
|
+
*/
|
|
206
|
+
metrics?: MetricsConfig;
|
|
207
|
+
/**
|
|
208
|
+
* Auto-initialize SDK at module load
|
|
209
|
+
* When true, OTEL SDK initializes automatically when telemetry.config.ts is imported
|
|
210
|
+
* @default false (manual initialization via middleware)
|
|
211
|
+
*/
|
|
212
|
+
autoInitialize?: boolean;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Platform-specific telemetry presets
|
|
216
|
+
*/
|
|
217
|
+
export declare const TelemetryPresets: {
|
|
218
|
+
/**
|
|
219
|
+
* Google Cloud Platform preset with Cloud Trace integration
|
|
220
|
+
*/
|
|
221
|
+
readonly GCP: {
|
|
222
|
+
readonly propagation: {
|
|
223
|
+
readonly cloudTrace: true;
|
|
224
|
+
readonly w3c: true;
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
/**
|
|
228
|
+
* Cloud Run optimized preset with aggressive span export
|
|
229
|
+
* Prevents data loss during scale-to-zero container termination
|
|
230
|
+
*/
|
|
231
|
+
readonly CLOUD_RUN: {
|
|
232
|
+
readonly propagation: {
|
|
233
|
+
readonly cloudTrace: true;
|
|
234
|
+
readonly w3c: true;
|
|
235
|
+
};
|
|
236
|
+
readonly spanProcessor: {
|
|
237
|
+
readonly maxQueueSize: 100;
|
|
238
|
+
readonly maxExportBatchSize: 1;
|
|
239
|
+
readonly scheduledDelayMillis: 100;
|
|
240
|
+
readonly exportTimeoutMillis: 30000;
|
|
241
|
+
readonly enableExportLogging: true;
|
|
242
|
+
};
|
|
243
|
+
readonly instrumentation: {
|
|
244
|
+
readonly http: {
|
|
245
|
+
readonly enabled: true;
|
|
246
|
+
readonly requireParentforIncomingSpans: false;
|
|
247
|
+
readonly ignoreHealthChecks: true;
|
|
248
|
+
readonly traceOptionsRequests: false;
|
|
249
|
+
};
|
|
250
|
+
readonly mongodb: true;
|
|
251
|
+
readonly pino: true;
|
|
252
|
+
readonly fastify: false;
|
|
253
|
+
readonly dns: false;
|
|
254
|
+
readonly net: false;
|
|
255
|
+
readonly fs: false;
|
|
256
|
+
};
|
|
257
|
+
readonly metrics: {
|
|
258
|
+
readonly enabled: true;
|
|
259
|
+
readonly exportIntervalMillis: 60000;
|
|
260
|
+
};
|
|
261
|
+
readonly autoInitialize: true;
|
|
262
|
+
};
|
|
263
|
+
/**
|
|
264
|
+
* New Relic APM preset
|
|
265
|
+
*/
|
|
266
|
+
readonly NEW_RELIC: {
|
|
267
|
+
readonly propagation: {
|
|
268
|
+
readonly cloudTrace: false;
|
|
269
|
+
readonly w3c: true;
|
|
270
|
+
};
|
|
271
|
+
};
|
|
272
|
+
/**
|
|
273
|
+
* Datadog APM preset
|
|
274
|
+
*/
|
|
275
|
+
readonly DATADOG: {
|
|
276
|
+
readonly propagation: {
|
|
277
|
+
readonly cloudTrace: false;
|
|
278
|
+
readonly w3c: true;
|
|
279
|
+
};
|
|
280
|
+
};
|
|
281
|
+
/**
|
|
282
|
+
* Standard OpenTelemetry preset (OTLP)
|
|
283
|
+
*/
|
|
284
|
+
readonly OTLP: {
|
|
285
|
+
readonly propagation: {
|
|
286
|
+
readonly cloudTrace: false;
|
|
287
|
+
readonly w3c: true;
|
|
288
|
+
};
|
|
289
|
+
};
|
|
290
|
+
/**
|
|
291
|
+
* Jaeger local development preset
|
|
292
|
+
*/
|
|
293
|
+
readonly JAEGER_LOCAL: {
|
|
294
|
+
readonly exporters: {
|
|
295
|
+
readonly traces: readonly [{
|
|
296
|
+
readonly endpoint: "http://localhost:4318/v1/traces";
|
|
297
|
+
}];
|
|
298
|
+
};
|
|
299
|
+
readonly propagation: {
|
|
300
|
+
readonly cloudTrace: false;
|
|
301
|
+
readonly w3c: true;
|
|
302
|
+
};
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* Development preset (console output only)
|
|
306
|
+
*/
|
|
307
|
+
readonly DEVELOPMENT: {
|
|
308
|
+
readonly propagation: {
|
|
309
|
+
readonly cloudTrace: false;
|
|
310
|
+
readonly w3c: true;
|
|
311
|
+
};
|
|
312
|
+
};
|
|
313
|
+
/**
|
|
314
|
+
* Disabled preset (no telemetry)
|
|
315
|
+
*/
|
|
316
|
+
readonly DISABLED: {
|
|
317
|
+
readonly propagation: {
|
|
318
|
+
readonly cloudTrace: false;
|
|
319
|
+
readonly w3c: false;
|
|
320
|
+
};
|
|
321
|
+
};
|
|
322
|
+
};
|
|
323
|
+
/**
|
|
324
|
+
* Detect if running on Google Cloud Platform
|
|
325
|
+
*/
|
|
326
|
+
export declare function isRunningOnGCP(): boolean;
|
|
327
|
+
/**
|
|
328
|
+
* Get default telemetry configuration based on environment
|
|
329
|
+
*/
|
|
330
|
+
export declare function getDefaultTelemetryConfig(): Partial<TelemetryConfig>;
|
|
331
|
+
//# sourceMappingURL=config.d.ts.map
|