@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
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Telemetry Configuration
|
|
4
|
+
*
|
|
5
|
+
* Centralized configuration for OpenTelemetry setup including:
|
|
6
|
+
* - Service resource attributes
|
|
7
|
+
* - Trace exporters and propagators
|
|
8
|
+
* - Metrics configuration
|
|
9
|
+
* - Platform-specific presets
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TelemetryPresets = void 0;
|
|
13
|
+
exports.isRunningOnGCP = isRunningOnGCP;
|
|
14
|
+
exports.getDefaultTelemetryConfig = getDefaultTelemetryConfig;
|
|
15
|
+
/**
|
|
16
|
+
* Platform-specific telemetry presets
|
|
17
|
+
*/
|
|
18
|
+
exports.TelemetryPresets = {
|
|
19
|
+
/**
|
|
20
|
+
* Google Cloud Platform preset with Cloud Trace integration
|
|
21
|
+
*/
|
|
22
|
+
GCP: {
|
|
23
|
+
propagation: {
|
|
24
|
+
cloudTrace: true,
|
|
25
|
+
w3c: true,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
/**
|
|
29
|
+
* Cloud Run optimized preset with aggressive span export
|
|
30
|
+
* Prevents data loss during scale-to-zero container termination
|
|
31
|
+
*/
|
|
32
|
+
CLOUD_RUN: {
|
|
33
|
+
propagation: {
|
|
34
|
+
cloudTrace: true,
|
|
35
|
+
w3c: true,
|
|
36
|
+
},
|
|
37
|
+
spanProcessor: {
|
|
38
|
+
maxQueueSize: 100,
|
|
39
|
+
maxExportBatchSize: 1, // Immediate export
|
|
40
|
+
scheduledDelayMillis: 100, // Very aggressive (vs 5s default)
|
|
41
|
+
exportTimeoutMillis: 30000,
|
|
42
|
+
enableExportLogging: true,
|
|
43
|
+
},
|
|
44
|
+
instrumentation: {
|
|
45
|
+
http: {
|
|
46
|
+
enabled: true,
|
|
47
|
+
requireParentforIncomingSpans: false, // Create root spans
|
|
48
|
+
ignoreHealthChecks: true,
|
|
49
|
+
traceOptionsRequests: false,
|
|
50
|
+
},
|
|
51
|
+
mongodb: true,
|
|
52
|
+
pino: true,
|
|
53
|
+
fastify: false, // Prevent duplicate spans
|
|
54
|
+
dns: false,
|
|
55
|
+
net: false,
|
|
56
|
+
fs: false,
|
|
57
|
+
},
|
|
58
|
+
metrics: {
|
|
59
|
+
enabled: true,
|
|
60
|
+
exportIntervalMillis: 60000,
|
|
61
|
+
},
|
|
62
|
+
autoInitialize: true,
|
|
63
|
+
},
|
|
64
|
+
/**
|
|
65
|
+
* New Relic APM preset
|
|
66
|
+
*/
|
|
67
|
+
NEW_RELIC: {
|
|
68
|
+
propagation: {
|
|
69
|
+
cloudTrace: false,
|
|
70
|
+
w3c: true,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
/**
|
|
74
|
+
* Datadog APM preset
|
|
75
|
+
*/
|
|
76
|
+
DATADOG: {
|
|
77
|
+
propagation: {
|
|
78
|
+
cloudTrace: false,
|
|
79
|
+
w3c: true,
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
/**
|
|
83
|
+
* Standard OpenTelemetry preset (OTLP)
|
|
84
|
+
*/
|
|
85
|
+
OTLP: {
|
|
86
|
+
propagation: {
|
|
87
|
+
cloudTrace: false,
|
|
88
|
+
w3c: true,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
/**
|
|
92
|
+
* Jaeger local development preset
|
|
93
|
+
*/
|
|
94
|
+
JAEGER_LOCAL: {
|
|
95
|
+
exporters: {
|
|
96
|
+
traces: [{ endpoint: 'http://localhost:4318/v1/traces' }],
|
|
97
|
+
},
|
|
98
|
+
propagation: {
|
|
99
|
+
cloudTrace: false,
|
|
100
|
+
w3c: true,
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
/**
|
|
104
|
+
* Development preset (console output only)
|
|
105
|
+
*/
|
|
106
|
+
DEVELOPMENT: {
|
|
107
|
+
propagation: {
|
|
108
|
+
cloudTrace: false,
|
|
109
|
+
w3c: true,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
/**
|
|
113
|
+
* Disabled preset (no telemetry)
|
|
114
|
+
*/
|
|
115
|
+
DISABLED: {
|
|
116
|
+
propagation: {
|
|
117
|
+
cloudTrace: false,
|
|
118
|
+
w3c: false,
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Detect if running on Google Cloud Platform
|
|
124
|
+
*/
|
|
125
|
+
function isRunningOnGCP() {
|
|
126
|
+
return !!(process.env.GOOGLE_CLOUD_PROJECT ||
|
|
127
|
+
process.env.GCLOUD_PROJECT ||
|
|
128
|
+
process.env.GCP_PROJECT ||
|
|
129
|
+
process.env.K_SERVICE || // Cloud Run
|
|
130
|
+
process.env.FUNCTION_NAME || // Cloud Functions
|
|
131
|
+
process.env.GAE_APPLICATION // App Engine
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Get default telemetry configuration based on environment
|
|
136
|
+
*/
|
|
137
|
+
function getDefaultTelemetryConfig() {
|
|
138
|
+
const isGCP = isRunningOnGCP();
|
|
139
|
+
return {
|
|
140
|
+
serviceName: process.env.OTEL_SERVICE_NAME ||
|
|
141
|
+
process.env.SERVICE_NAME ||
|
|
142
|
+
'noony-service',
|
|
143
|
+
serviceVersion: process.env.OTEL_SERVICE_VERSION ||
|
|
144
|
+
process.env.SERVICE_VERSION ||
|
|
145
|
+
'1.0.0',
|
|
146
|
+
environment: process.env.NODE_ENV || 'production',
|
|
147
|
+
propagation: {
|
|
148
|
+
cloudTrace: isGCP, // Enable Cloud Trace propagation on GCP
|
|
149
|
+
w3c: true, // Always enable W3C Trace Context
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telemetry Module
|
|
3
|
+
*
|
|
4
|
+
* Provides OpenTelemetry integration for the Noony framework with:
|
|
5
|
+
* - Extensible provider system (OTEL, New Relic, Datadog, Console, Noop)
|
|
6
|
+
* - Auto-detection from environment variables
|
|
7
|
+
* - Graceful degradation when configuration is missing
|
|
8
|
+
* - Zero-configuration local development support
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* import { OpenTelemetryMiddleware } from '@noony-serverless/core';
|
|
12
|
+
*
|
|
13
|
+
* const handler = new Handler()
|
|
14
|
+
* .use(new OpenTelemetryMiddleware()) // Auto-detects provider
|
|
15
|
+
* .handle(async (context) => {
|
|
16
|
+
* // Your business logic
|
|
17
|
+
* });
|
|
18
|
+
*/
|
|
19
|
+
export * from './provider';
|
|
20
|
+
export { TelemetryPresets, isRunningOnGCP, getDefaultTelemetryConfig, } from './config';
|
|
21
|
+
export * from './providers';
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Telemetry Module
|
|
4
|
+
*
|
|
5
|
+
* Provides OpenTelemetry integration for the Noony framework with:
|
|
6
|
+
* - Extensible provider system (OTEL, New Relic, Datadog, Console, Noop)
|
|
7
|
+
* - Auto-detection from environment variables
|
|
8
|
+
* - Graceful degradation when configuration is missing
|
|
9
|
+
* - Zero-configuration local development support
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* import { OpenTelemetryMiddleware } from '@noony-serverless/core';
|
|
13
|
+
*
|
|
14
|
+
* const handler = new Handler()
|
|
15
|
+
* .use(new OpenTelemetryMiddleware()) // Auto-detects provider
|
|
16
|
+
* .handle(async (context) => {
|
|
17
|
+
* // Your business logic
|
|
18
|
+
* });
|
|
19
|
+
*/
|
|
20
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
23
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
24
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
25
|
+
}
|
|
26
|
+
Object.defineProperty(o, k2, desc);
|
|
27
|
+
}) : (function(o, m, k, k2) {
|
|
28
|
+
if (k2 === undefined) k2 = k;
|
|
29
|
+
o[k2] = m[k];
|
|
30
|
+
}));
|
|
31
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
32
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.getDefaultTelemetryConfig = exports.isRunningOnGCP = exports.TelemetryPresets = void 0;
|
|
36
|
+
// Core interfaces and types
|
|
37
|
+
__exportStar(require("./provider"), exports);
|
|
38
|
+
// Configuration and presets (explicit exports to avoid conflict)
|
|
39
|
+
var config_1 = require("./config");
|
|
40
|
+
Object.defineProperty(exports, "TelemetryPresets", { enumerable: true, get: function () { return config_1.TelemetryPresets; } });
|
|
41
|
+
Object.defineProperty(exports, "isRunningOnGCP", { enumerable: true, get: function () { return config_1.isRunningOnGCP; } });
|
|
42
|
+
Object.defineProperty(exports, "getDefaultTelemetryConfig", { enumerable: true, get: function () { return config_1.getDefaultTelemetryConfig; } });
|
|
43
|
+
// Provider implementations
|
|
44
|
+
__exportStar(require("./providers"), exports);
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { Context } from '../core';
|
|
2
|
+
/**
|
|
3
|
+
* Validation result from TelemetryProvider.validate()
|
|
4
|
+
*/
|
|
5
|
+
export interface ValidationResult {
|
|
6
|
+
valid: boolean;
|
|
7
|
+
reason?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Generic span interface that works across different telemetry providers
|
|
11
|
+
* This provides a common interface for OTEL, New Relic, Datadog, etc.
|
|
12
|
+
*/
|
|
13
|
+
export interface GenericSpan {
|
|
14
|
+
setAttributes(attributes: Record<string, unknown>): void;
|
|
15
|
+
recordException(error: Error): void;
|
|
16
|
+
setStatus(status: {
|
|
17
|
+
code: number;
|
|
18
|
+
message?: string;
|
|
19
|
+
}): void;
|
|
20
|
+
end(): void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Base interface for telemetry providers
|
|
24
|
+
*
|
|
25
|
+
* This interface allows custom implementations for different APM platforms:
|
|
26
|
+
* - Standard OpenTelemetry SDK
|
|
27
|
+
* - New Relic Agent
|
|
28
|
+
* - Datadog Tracer
|
|
29
|
+
* - Custom implementations
|
|
30
|
+
*
|
|
31
|
+
* All providers must implement validation to ensure graceful degradation
|
|
32
|
+
* when configuration is missing or invalid.
|
|
33
|
+
*/
|
|
34
|
+
export interface TelemetryProvider {
|
|
35
|
+
/**
|
|
36
|
+
* Provider name for identification
|
|
37
|
+
* Examples: 'opentelemetry', 'newrelic', 'datadog', 'console', 'noop'
|
|
38
|
+
*/
|
|
39
|
+
readonly name: string;
|
|
40
|
+
/**
|
|
41
|
+
* Validate provider configuration before initialization
|
|
42
|
+
*
|
|
43
|
+
* This method checks:
|
|
44
|
+
* - Required environment variables are set
|
|
45
|
+
* - Required npm packages are installed
|
|
46
|
+
* - Configuration is valid (e.g., valid URLs)
|
|
47
|
+
*
|
|
48
|
+
* @returns Validation result with optional reason if invalid
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* const result = await provider.validate();
|
|
52
|
+
* if (!result.valid) {
|
|
53
|
+
* console.warn(`Provider validation failed: ${result.reason}`);
|
|
54
|
+
* // Fall back to NoopProvider
|
|
55
|
+
* }
|
|
56
|
+
*/
|
|
57
|
+
validate(): Promise<ValidationResult>;
|
|
58
|
+
/**
|
|
59
|
+
* Initialize the telemetry provider with configuration
|
|
60
|
+
*
|
|
61
|
+
* This is called once at application startup, not per-request.
|
|
62
|
+
* Providers should set up SDK, exporters, and any global configuration.
|
|
63
|
+
*
|
|
64
|
+
* @param config Telemetry configuration
|
|
65
|
+
* @throws Should not throw - errors should be caught and logged internally
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* await provider.initialize({
|
|
69
|
+
* serviceName: 'order-service',
|
|
70
|
+
* serviceVersion: '1.0.0',
|
|
71
|
+
* environment: 'production'
|
|
72
|
+
* });
|
|
73
|
+
*/
|
|
74
|
+
initialize(config: TelemetryConfig): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Create a span for the current request
|
|
77
|
+
*
|
|
78
|
+
* This is called in the middleware `before` hook for each request.
|
|
79
|
+
* Returns undefined if provider is not ready or span creation fails.
|
|
80
|
+
*
|
|
81
|
+
* @param context The Noony request context
|
|
82
|
+
* @returns Span object or undefined if span creation fails
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* const span = provider.createSpan(context);
|
|
86
|
+
* if (span) {
|
|
87
|
+
* span.setAttributes({ 'user.id': context.user?.id });
|
|
88
|
+
* context.businessData.set('otel_span', span);
|
|
89
|
+
* }
|
|
90
|
+
*/
|
|
91
|
+
createSpan(context: Context<unknown, unknown>): GenericSpan | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* Record a metric (histogram, counter, gauge, etc.)
|
|
94
|
+
*
|
|
95
|
+
* @param name Metric name (e.g., 'http.request.duration')
|
|
96
|
+
* @param value Metric value
|
|
97
|
+
* @param attributes Optional metric attributes/tags
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* provider.recordMetric('http.request.duration', 123.45, {
|
|
101
|
+
* 'http.method': 'POST',
|
|
102
|
+
* 'http.status_code': 200
|
|
103
|
+
* });
|
|
104
|
+
*/
|
|
105
|
+
recordMetric(name: string, value: number, attributes?: Record<string, unknown>): void;
|
|
106
|
+
/**
|
|
107
|
+
* Log with trace correlation
|
|
108
|
+
*
|
|
109
|
+
* Logs should include trace and span IDs when available for correlation.
|
|
110
|
+
*
|
|
111
|
+
* @param level Log level (info, error, warn, debug)
|
|
112
|
+
* @param message Log message
|
|
113
|
+
* @param attributes Additional log attributes
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* provider.log('error', 'Request failed', {
|
|
117
|
+
* 'error.type': 'ValidationError',
|
|
118
|
+
* 'user.id': userId
|
|
119
|
+
* });
|
|
120
|
+
*/
|
|
121
|
+
log(level: string, message: string, attributes?: Record<string, unknown>): void;
|
|
122
|
+
/**
|
|
123
|
+
* Check if provider is initialized and ready to use
|
|
124
|
+
*
|
|
125
|
+
* @returns True if provider is ready, false otherwise
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* if (!provider.isReady()) {
|
|
129
|
+
* console.warn('Provider not ready, skipping telemetry');
|
|
130
|
+
* }
|
|
131
|
+
*/
|
|
132
|
+
isReady(): boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Shutdown the provider gracefully
|
|
135
|
+
*
|
|
136
|
+
* Called during application shutdown to flush any pending telemetry data.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* process.on('SIGTERM', async () => {
|
|
140
|
+
* await provider.shutdown();
|
|
141
|
+
* process.exit(0);
|
|
142
|
+
* });
|
|
143
|
+
*/
|
|
144
|
+
shutdown(): Promise<void>;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Telemetry configuration interface
|
|
148
|
+
*/
|
|
149
|
+
export interface TelemetryConfig {
|
|
150
|
+
/** Enable telemetry (defaults to true) */
|
|
151
|
+
enabled?: boolean;
|
|
152
|
+
/** Service name for telemetry */
|
|
153
|
+
serviceName: string;
|
|
154
|
+
/** Service version (optional) */
|
|
155
|
+
serviceVersion?: string;
|
|
156
|
+
/** Environment (e.g., 'production', 'staging', 'development') */
|
|
157
|
+
environment?: string;
|
|
158
|
+
/** Exporter configurations */
|
|
159
|
+
exporters?: {
|
|
160
|
+
traces?: OTLPExporterConfig[];
|
|
161
|
+
metrics?: OTLPExporterConfig[];
|
|
162
|
+
logs?: OTLPExporterConfig[];
|
|
163
|
+
};
|
|
164
|
+
/** Sampling configuration */
|
|
165
|
+
sampling?: {
|
|
166
|
+
/** Sampling ratio (0.0 to 1.0) */
|
|
167
|
+
ratio?: number;
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Propagation format configuration
|
|
171
|
+
* Controls which trace context formats to support
|
|
172
|
+
*/
|
|
173
|
+
propagation?: {
|
|
174
|
+
/**
|
|
175
|
+
* Enable Cloud Trace propagation for Google Cloud Platform
|
|
176
|
+
* Uses X-Cloud-Trace-Context header format
|
|
177
|
+
* @default true when running on GCP
|
|
178
|
+
*/
|
|
179
|
+
cloudTrace?: boolean;
|
|
180
|
+
/**
|
|
181
|
+
* Enable W3C Trace Context propagation
|
|
182
|
+
* Uses traceparent/tracestate header format
|
|
183
|
+
* @default true
|
|
184
|
+
*/
|
|
185
|
+
w3c?: boolean;
|
|
186
|
+
/**
|
|
187
|
+
* Additional custom propagators
|
|
188
|
+
*/
|
|
189
|
+
custom?: string[];
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* OTLP Exporter configuration
|
|
194
|
+
*/
|
|
195
|
+
export interface OTLPExporterConfig {
|
|
196
|
+
/** Exporter endpoint URL */
|
|
197
|
+
endpoint: string;
|
|
198
|
+
/** Optional headers (e.g., API keys) */
|
|
199
|
+
headers?: Record<string, string>;
|
|
200
|
+
/** Timeout in milliseconds (optional) */
|
|
201
|
+
timeout?: number;
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Context } from '../../core';
|
|
2
|
+
import { TelemetryProvider, ValidationResult, GenericSpan, TelemetryConfig } from '../provider';
|
|
3
|
+
/**
|
|
4
|
+
* Console Telemetry Provider
|
|
5
|
+
*
|
|
6
|
+
* Logs all telemetry data to the console for local development and debugging.
|
|
7
|
+
* This provider is useful for:
|
|
8
|
+
* 1. Local development without external telemetry infrastructure
|
|
9
|
+
* 2. Debugging telemetry integration
|
|
10
|
+
* 3. Testing span creation and attributes
|
|
11
|
+
*
|
|
12
|
+
* Auto-selected when NODE_ENV=development and no OTEL endpoint is configured.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Auto-detected in development
|
|
16
|
+
* NODE_ENV=development
|
|
17
|
+
*
|
|
18
|
+
* // Or explicitly configured
|
|
19
|
+
* const provider = new ConsoleProvider();
|
|
20
|
+
* await provider.initialize({ serviceName: 'my-service' });
|
|
21
|
+
*/
|
|
22
|
+
export declare class ConsoleProvider implements TelemetryProvider {
|
|
23
|
+
readonly name = "console";
|
|
24
|
+
private enabled;
|
|
25
|
+
/**
|
|
26
|
+
* Console provider is always valid (useful for local testing)
|
|
27
|
+
*/
|
|
28
|
+
validate(): Promise<ValidationResult>;
|
|
29
|
+
/**
|
|
30
|
+
* Initialize console provider
|
|
31
|
+
*/
|
|
32
|
+
initialize(config: TelemetryConfig): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Create a console span that logs to stdout
|
|
35
|
+
*/
|
|
36
|
+
createSpan(context: Context<unknown, unknown>): GenericSpan | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Log metric to console
|
|
39
|
+
*/
|
|
40
|
+
recordMetric(name: string, value: number, attributes?: Record<string, unknown>): void;
|
|
41
|
+
/**
|
|
42
|
+
* Log message to console with level
|
|
43
|
+
*/
|
|
44
|
+
log(level: string, message: string, attributes?: Record<string, unknown>): void;
|
|
45
|
+
/**
|
|
46
|
+
* Console provider is always ready if enabled
|
|
47
|
+
*/
|
|
48
|
+
isReady(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Shutdown console provider
|
|
51
|
+
*/
|
|
52
|
+
shutdown(): Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=console-provider.d.ts.map
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConsoleProvider = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Console Telemetry Provider
|
|
6
|
+
*
|
|
7
|
+
* Logs all telemetry data to the console for local development and debugging.
|
|
8
|
+
* This provider is useful for:
|
|
9
|
+
* 1. Local development without external telemetry infrastructure
|
|
10
|
+
* 2. Debugging telemetry integration
|
|
11
|
+
* 3. Testing span creation and attributes
|
|
12
|
+
*
|
|
13
|
+
* Auto-selected when NODE_ENV=development and no OTEL endpoint is configured.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // Auto-detected in development
|
|
17
|
+
* NODE_ENV=development
|
|
18
|
+
*
|
|
19
|
+
* // Or explicitly configured
|
|
20
|
+
* const provider = new ConsoleProvider();
|
|
21
|
+
* await provider.initialize({ serviceName: 'my-service' });
|
|
22
|
+
*/
|
|
23
|
+
class ConsoleProvider {
|
|
24
|
+
name = 'console';
|
|
25
|
+
enabled = false;
|
|
26
|
+
/**
|
|
27
|
+
* Console provider is always valid (useful for local testing)
|
|
28
|
+
*/
|
|
29
|
+
async validate() {
|
|
30
|
+
return { valid: true };
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Initialize console provider
|
|
34
|
+
*/
|
|
35
|
+
async initialize(config) {
|
|
36
|
+
this.enabled = config.enabled !== false;
|
|
37
|
+
if (this.enabled) {
|
|
38
|
+
console.log('[Telemetry] Console provider initialized');
|
|
39
|
+
console.log('[Telemetry] Service:', config.serviceName);
|
|
40
|
+
console.log('[Telemetry] Version:', config.serviceVersion || 'unknown');
|
|
41
|
+
console.log('[Telemetry] Environment:', config.environment || 'development');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Create a console span that logs to stdout
|
|
46
|
+
*/
|
|
47
|
+
createSpan(context) {
|
|
48
|
+
if (!this.enabled)
|
|
49
|
+
return undefined;
|
|
50
|
+
const spanData = {
|
|
51
|
+
startTime: Date.now(),
|
|
52
|
+
method: context.req.method,
|
|
53
|
+
path: context.req.path || context.req.url,
|
|
54
|
+
requestId: context.requestId,
|
|
55
|
+
};
|
|
56
|
+
console.log('[Telemetry] 🟢 Span started:', spanData);
|
|
57
|
+
return {
|
|
58
|
+
setAttributes: (attrs) => {
|
|
59
|
+
console.log('[Telemetry] 📊 Span attributes:', attrs);
|
|
60
|
+
},
|
|
61
|
+
recordException: (error) => {
|
|
62
|
+
console.error('[Telemetry] ❌ Exception:', {
|
|
63
|
+
message: error.message,
|
|
64
|
+
name: error.name,
|
|
65
|
+
stack: error.stack,
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
setStatus: (status) => {
|
|
69
|
+
const statusIcon = status.code === 0 ? '✅' : '⚠️';
|
|
70
|
+
console.log(`[Telemetry] ${statusIcon} Span status:`, status);
|
|
71
|
+
},
|
|
72
|
+
end: () => {
|
|
73
|
+
const duration = Date.now() - spanData.startTime;
|
|
74
|
+
console.log('[Telemetry] 🔴 Span ended:', {
|
|
75
|
+
...spanData,
|
|
76
|
+
duration: `${duration}ms`,
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Log metric to console
|
|
83
|
+
*/
|
|
84
|
+
recordMetric(name, value, attributes) {
|
|
85
|
+
if (!this.enabled)
|
|
86
|
+
return;
|
|
87
|
+
console.log('[Telemetry] 📈 Metric:', {
|
|
88
|
+
name,
|
|
89
|
+
value,
|
|
90
|
+
attributes,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Log message to console with level
|
|
95
|
+
*/
|
|
96
|
+
log(level, message, attributes) {
|
|
97
|
+
if (!this.enabled)
|
|
98
|
+
return;
|
|
99
|
+
const levelIcon = {
|
|
100
|
+
info: 'ℹ️',
|
|
101
|
+
error: '❌',
|
|
102
|
+
warn: '⚠️',
|
|
103
|
+
debug: '🔍',
|
|
104
|
+
}[level] || '📝';
|
|
105
|
+
console.log(`[Telemetry] ${levelIcon} Log [${level}]:`, message, attributes);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Console provider is always ready if enabled
|
|
109
|
+
*/
|
|
110
|
+
isReady() {
|
|
111
|
+
return this.enabled;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Shutdown console provider
|
|
115
|
+
*/
|
|
116
|
+
async shutdown() {
|
|
117
|
+
if (this.enabled) {
|
|
118
|
+
console.log('[Telemetry] Console provider shutdown');
|
|
119
|
+
}
|
|
120
|
+
this.enabled = false;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.ConsoleProvider = ConsoleProvider;
|
|
124
|
+
//# sourceMappingURL=console-provider.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telemetry Providers
|
|
3
|
+
*
|
|
4
|
+
* This module exports all available telemetry providers.
|
|
5
|
+
* Providers can be used directly or auto-detected by OpenTelemetryMiddleware.
|
|
6
|
+
*/
|
|
7
|
+
export { NoopProvider } from './noop-provider';
|
|
8
|
+
export { ConsoleProvider } from './console-provider';
|
|
9
|
+
export { OpenTelemetryProvider } from './opentelemetry-provider';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Telemetry Providers
|
|
4
|
+
*
|
|
5
|
+
* This module exports all available telemetry providers.
|
|
6
|
+
* Providers can be used directly or auto-detected by OpenTelemetryMiddleware.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.OpenTelemetryProvider = exports.ConsoleProvider = exports.NoopProvider = void 0;
|
|
10
|
+
var noop_provider_1 = require("./noop-provider");
|
|
11
|
+
Object.defineProperty(exports, "NoopProvider", { enumerable: true, get: function () { return noop_provider_1.NoopProvider; } });
|
|
12
|
+
var console_provider_1 = require("./console-provider");
|
|
13
|
+
Object.defineProperty(exports, "ConsoleProvider", { enumerable: true, get: function () { return console_provider_1.ConsoleProvider; } });
|
|
14
|
+
var opentelemetry_provider_1 = require("./opentelemetry-provider");
|
|
15
|
+
Object.defineProperty(exports, "OpenTelemetryProvider", { enumerable: true, get: function () { return opentelemetry_provider_1.OpenTelemetryProvider; } });
|
|
16
|
+
// Note: New Relic and Datadog providers are optional and can be added when needed
|
|
17
|
+
// export { NewRelicProvider } from './newrelic-provider';
|
|
18
|
+
// export { DatadogProvider } from './datadog-provider';
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Context } from '../../core';
|
|
2
|
+
import { TelemetryProvider, ValidationResult, GenericSpan, TelemetryConfig } from '../provider';
|
|
3
|
+
/**
|
|
4
|
+
* Noop (No-operation) Telemetry Provider
|
|
5
|
+
*
|
|
6
|
+
* This provider does nothing and is used as:
|
|
7
|
+
* 1. Fallback when other providers fail validation
|
|
8
|
+
* 2. Default when telemetry is disabled (NODE_ENV=test)
|
|
9
|
+
* 3. Placeholder when no configuration is provided
|
|
10
|
+
*
|
|
11
|
+
* It implements all TelemetryProvider methods as no-ops to ensure
|
|
12
|
+
* the application continues to work even when telemetry fails.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Automatically used as fallback
|
|
16
|
+
* const provider = new NoopProvider();
|
|
17
|
+
* await provider.initialize({ serviceName: 'test' });
|
|
18
|
+
* const span = provider.createSpan(context); // Returns undefined
|
|
19
|
+
*/
|
|
20
|
+
export declare class NoopProvider implements TelemetryProvider {
|
|
21
|
+
readonly name = "noop";
|
|
22
|
+
/**
|
|
23
|
+
* Noop provider is always valid
|
|
24
|
+
*/
|
|
25
|
+
validate(): Promise<ValidationResult>;
|
|
26
|
+
/**
|
|
27
|
+
* No-op initialization
|
|
28
|
+
*/
|
|
29
|
+
initialize(_config: TelemetryConfig): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Always returns undefined (no span created)
|
|
32
|
+
*/
|
|
33
|
+
createSpan(_context: Context<unknown, unknown>): GenericSpan | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* No-op metric recording
|
|
36
|
+
*/
|
|
37
|
+
recordMetric(_name: string, _value: number, _attributes?: Record<string, unknown>): void;
|
|
38
|
+
/**
|
|
39
|
+
* No-op logging
|
|
40
|
+
*/
|
|
41
|
+
log(_level: string, _message: string, _attributes?: Record<string, unknown>): void;
|
|
42
|
+
/**
|
|
43
|
+
* Always ready (does nothing, so always ready)
|
|
44
|
+
*/
|
|
45
|
+
isReady(): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* No-op shutdown
|
|
48
|
+
*/
|
|
49
|
+
shutdown(): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=noop-provider.d.ts.map
|