@plyaz/types 1.23.0 → 1.23.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.
- package/dist/core/domain/types.d.ts +12 -1
- package/dist/core/init/index.d.ts +1 -1
- package/dist/core/init/types.d.ts +133 -1
- package/dist/index.cjs +42 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +41 -1
- package/dist/index.js.map +1 -1
- package/dist/observability/datadog-sdk.d.ts +138 -0
- package/dist/observability/index.cjs +48 -0
- package/dist/observability/index.cjs.map +1 -0
- package/dist/observability/index.d.ts +10 -0
- package/dist/observability/index.js +45 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/types.d.ts +548 -0
- package/package.json +6 -1
|
@@ -94,6 +94,12 @@ export interface CoreBaseDomainServiceConfig {
|
|
|
94
94
|
enabled?: boolean;
|
|
95
95
|
/** Default values for feature flags or other defaults */
|
|
96
96
|
defaults?: Record<string, FeatureFlagValue>;
|
|
97
|
+
/**
|
|
98
|
+
* Custom observability adapter to use instead of the injected global/dedicated one.
|
|
99
|
+
* Useful when a service needs a different provider or custom configuration.
|
|
100
|
+
* Takes precedence over injected observability.
|
|
101
|
+
*/
|
|
102
|
+
observabilityOverride?: unknown;
|
|
97
103
|
}
|
|
98
104
|
/**
|
|
99
105
|
* Type for mapper class constructor
|
|
@@ -126,7 +132,7 @@ export type CoreValidatorClass<T extends CoreBaseValidatorInstance = CoreBaseVal
|
|
|
126
132
|
* interface BasicInjectedServices extends CoreInjectedServices {}
|
|
127
133
|
* ```
|
|
128
134
|
*/
|
|
129
|
-
export interface CoreInjectedServices<TCache = unknown, TDb = unknown, TApi = unknown, TStores = unknown> {
|
|
135
|
+
export interface CoreInjectedServices<TCache = unknown, TDb = unknown, TApi = unknown, TStores = unknown, TObservability = unknown> {
|
|
130
136
|
/** Cache manager instance */
|
|
131
137
|
cache?: TCache;
|
|
132
138
|
/** Database service instance */
|
|
@@ -139,6 +145,11 @@ export interface CoreInjectedServices<TCache = unknown, TDb = unknown, TApi = un
|
|
|
139
145
|
* @example { example: ExampleStoreSlice, errors: ErrorStoreSlice }
|
|
140
146
|
*/
|
|
141
147
|
stores?: TStores extends Record<string, unknown> ? Partial<TStores> : Record<string, TStores>;
|
|
148
|
+
/**
|
|
149
|
+
* Observability service instance for metrics, tracing, and logging.
|
|
150
|
+
* Supports adapter-based providers (Datadog, Grafana, OpenTelemetry, etc.)
|
|
151
|
+
*/
|
|
152
|
+
observability?: TObservability;
|
|
142
153
|
}
|
|
143
154
|
/**
|
|
144
155
|
* Base service configuration passed to constructor
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* Core Init Types
|
|
3
3
|
* Service registry and initialization type definitions
|
|
4
4
|
*/
|
|
5
|
-
export type { CoreDomainServiceInstance, CoreServiceInitConfig, CoreServiceCreateOptions, CoreInitializableDomainService, CoreServiceEntry, CoreServiceRegistryConfig, CoreExtractServiceConfig, CoreExtractServiceInstance, CoreFeatureFlagInitConfig, CoreErrorHandlerInitConfig, CoreCacheConfig, CoreInitOptionsBase, CoreServicesResultBase, } from './types';
|
|
5
|
+
export type { CoreDomainServiceInstance, CoreServiceInitConfig, CoreServiceCreateOptions, CoreInitializableDomainService, CoreServiceEntry, CoreServiceRegistryConfig, CoreExtractServiceConfig, CoreExtractServiceInstance, CoreFeatureFlagInitConfig, CoreErrorHandlerInitConfig, CoreCacheConfig, CoreObservabilityConfig, CoreInitOptionsBase, CoreServicesResultBase, } from './types';
|
|
@@ -12,6 +12,7 @@ import type { RootStoreSlice } from '../../store';
|
|
|
12
12
|
import type { CoreAppEnvironment, CoreAppContext, CoreRuntimeEnvironment, CoreServiceRuntime } from '../modules';
|
|
13
13
|
import type { CoreDbServiceConfig } from '../services';
|
|
14
14
|
import type { CoreInjectedServices } from '../domain';
|
|
15
|
+
import type { MonitoringObservabilityAdapter, MonitoringAdapterWithPriority } from '../../observability';
|
|
15
16
|
/**
|
|
16
17
|
* Base interface that all domain service instances must implement.
|
|
17
18
|
* This allows the registry to manage services generically.
|
|
@@ -213,6 +214,38 @@ export interface CoreServiceInitConfig {
|
|
|
213
214
|
/** Default TTL in seconds for cached operations */
|
|
214
215
|
defaultTtl?: number;
|
|
215
216
|
};
|
|
217
|
+
/**
|
|
218
|
+
* Create a dedicated observability instance for this service.
|
|
219
|
+
*
|
|
220
|
+
* By default, services share the global observability adapter. Use this when
|
|
221
|
+
* a service needs its own isolated observability (e.g., different provider,
|
|
222
|
+
* custom tags, separate sampling).
|
|
223
|
+
*
|
|
224
|
+
* - `false` or `undefined`: Use global shared observability (default)
|
|
225
|
+
* - `true`: Create dedicated instance using global config
|
|
226
|
+
* - `ObservabilityAdapterConfig`: Create dedicated instance with custom config
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```typescript
|
|
230
|
+
* // Use global shared observability (default)
|
|
231
|
+
* { service: UserService, config: { enabled: true } }
|
|
232
|
+
*
|
|
233
|
+
* // Create dedicated observability with global config
|
|
234
|
+
* { service: PaymentService, config: { dedicatedObservability: true } }
|
|
235
|
+
*
|
|
236
|
+
* // Create dedicated observability with custom config
|
|
237
|
+
* {
|
|
238
|
+
* service: CriticalService,
|
|
239
|
+
* config: {
|
|
240
|
+
* dedicatedObservability: {
|
|
241
|
+
* serviceName: 'critical-service',
|
|
242
|
+
* samplingRate: 1.0, // 100% sampling for critical operations
|
|
243
|
+
* },
|
|
244
|
+
* },
|
|
245
|
+
* }
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
dedicatedObservability?: boolean | CoreObservabilityConfig;
|
|
216
249
|
}
|
|
217
250
|
/**
|
|
218
251
|
* Options passed to the service factory method
|
|
@@ -304,6 +337,27 @@ export interface CoreServiceCreateOptions<TConfig = unknown, TMapper = unknown,
|
|
|
304
337
|
*/
|
|
305
338
|
instance?: unknown;
|
|
306
339
|
};
|
|
340
|
+
/**
|
|
341
|
+
* Observability configuration and mode.
|
|
342
|
+
*/
|
|
343
|
+
observability?: {
|
|
344
|
+
/**
|
|
345
|
+
* Whether to use a dedicated (isolated) observability instance.
|
|
346
|
+
* - `false`: Use global shared instance (default)
|
|
347
|
+
* - `true`: Create dedicated instance
|
|
348
|
+
*/
|
|
349
|
+
dedicated: boolean;
|
|
350
|
+
/**
|
|
351
|
+
* Observability config (merged global + per-service config).
|
|
352
|
+
* Used to create dedicated instance or configure global.
|
|
353
|
+
*/
|
|
354
|
+
config?: CoreObservabilityConfig;
|
|
355
|
+
/**
|
|
356
|
+
* Actual ObservabilityAdapter instance to use.
|
|
357
|
+
* Injected by ServiceRegistry, not created by service.
|
|
358
|
+
*/
|
|
359
|
+
instance?: unknown;
|
|
360
|
+
};
|
|
307
361
|
/** Logger prefix */
|
|
308
362
|
loggerPrefix?: string;
|
|
309
363
|
/** Whether this is a singleton instance */
|
|
@@ -387,6 +441,8 @@ export interface CoreServiceRegistryConfig {
|
|
|
387
441
|
db?: Partial<CoreDbServiceConfig>;
|
|
388
442
|
/** Global cache config (shared by all services unless overridden) */
|
|
389
443
|
cache?: CoreCacheConfig;
|
|
444
|
+
/** Global observability config (shared by all services unless overridden) */
|
|
445
|
+
observability?: CoreObservabilityConfig;
|
|
390
446
|
/**
|
|
391
447
|
* Store registry interface for injecting stores into services.
|
|
392
448
|
* Provides type-safe store access via store keys.
|
|
@@ -519,6 +575,76 @@ export interface CoreCacheConfig {
|
|
|
519
575
|
keyPrefix?: string;
|
|
520
576
|
};
|
|
521
577
|
}
|
|
578
|
+
/**
|
|
579
|
+
* Observability initialization configuration
|
|
580
|
+
*/
|
|
581
|
+
export interface CoreObservabilityConfig {
|
|
582
|
+
/** Enable/disable observability (default: true) */
|
|
583
|
+
enabled?: boolean;
|
|
584
|
+
/** Service name for tagging */
|
|
585
|
+
serviceName?: string;
|
|
586
|
+
/** Environment (production, staging, development) */
|
|
587
|
+
environment?: string;
|
|
588
|
+
/** Default tags to add to all metrics/spans */
|
|
589
|
+
defaultTags?: Record<string, string>;
|
|
590
|
+
/** Sampling rate for traces (0.0 to 1.0) */
|
|
591
|
+
samplingRate?: number;
|
|
592
|
+
/** Flush interval in milliseconds */
|
|
593
|
+
flushInterval?: number;
|
|
594
|
+
/** Buffer size before auto-flush */
|
|
595
|
+
bufferSize?: number;
|
|
596
|
+
/**
|
|
597
|
+
* Provider type
|
|
598
|
+
* Currently supported: 'datadog', 'console', 'noop'
|
|
599
|
+
* Planned: 'grafana', 'opentelemetry', 'prometheus', 'newrelic', 'custom'
|
|
600
|
+
*/
|
|
601
|
+
provider?: 'datadog' | 'console' | 'noop';
|
|
602
|
+
/** Mode for multi-provider: 'parallel' sends to all, 'priority' falls back on error */
|
|
603
|
+
mode?: 'single' | 'parallel' | 'priority';
|
|
604
|
+
/** Datadog-specific configuration */
|
|
605
|
+
datadog?: {
|
|
606
|
+
/** Datadog API key */
|
|
607
|
+
apiKey?: string;
|
|
608
|
+
/** Datadog site (e.g., 'datadoghq.com', 'datadoghq.eu') */
|
|
609
|
+
site?: string;
|
|
610
|
+
/** Enable APM tracing */
|
|
611
|
+
apmEnabled?: boolean;
|
|
612
|
+
/** Enable RUM */
|
|
613
|
+
rumEnabled?: boolean;
|
|
614
|
+
/** RUM application ID */
|
|
615
|
+
rumApplicationId?: string;
|
|
616
|
+
/** RUM client token */
|
|
617
|
+
rumClientToken?: string;
|
|
618
|
+
};
|
|
619
|
+
/** Grafana-specific configuration */
|
|
620
|
+
grafana?: {
|
|
621
|
+
/** Push gateway URL (for Prometheus) */
|
|
622
|
+
pushGatewayUrl?: string;
|
|
623
|
+
/** Grafana Cloud user */
|
|
624
|
+
grafanaCloudUser?: string;
|
|
625
|
+
/** Grafana Cloud API key */
|
|
626
|
+
grafanaCloudApiKey?: string;
|
|
627
|
+
/** Loki endpoint for logs */
|
|
628
|
+
lokiEndpoint?: string;
|
|
629
|
+
/** Tempo endpoint for traces */
|
|
630
|
+
tempoEndpoint?: string;
|
|
631
|
+
};
|
|
632
|
+
/** OpenTelemetry-specific configuration */
|
|
633
|
+
opentelemetry?: {
|
|
634
|
+
/** OTLP endpoint URL */
|
|
635
|
+
endpoint?: string;
|
|
636
|
+
/** Headers for OTLP exporter */
|
|
637
|
+
headers?: Record<string, string>;
|
|
638
|
+
/** Export interval in milliseconds */
|
|
639
|
+
exportInterval?: number;
|
|
640
|
+
};
|
|
641
|
+
/**
|
|
642
|
+
* Pre-initialized adapters for observability.
|
|
643
|
+
* Can be plain adapters or adapters with priority/failover config.
|
|
644
|
+
* LoggerAdapter is auto-added as failover if not included.
|
|
645
|
+
*/
|
|
646
|
+
adapters?: (MonitoringObservabilityAdapter | MonitoringAdapterWithPriority)[];
|
|
647
|
+
}
|
|
522
648
|
/**
|
|
523
649
|
* Base core initialization options
|
|
524
650
|
* Extended by @plyaz/core's CoreInitOptions with specific types
|
|
@@ -538,12 +664,16 @@ export interface CoreInitOptionsBase<TDb = unknown, TApi = unknown> {
|
|
|
538
664
|
api?: TApi;
|
|
539
665
|
/** Cache configuration */
|
|
540
666
|
cache?: CoreCacheConfig;
|
|
667
|
+
/** Observability configuration */
|
|
668
|
+
observability?: CoreObservabilityConfig;
|
|
541
669
|
/** Skip database initialization */
|
|
542
670
|
skipDb?: boolean;
|
|
543
671
|
/** Skip API client initialization */
|
|
544
672
|
skipApi?: boolean;
|
|
545
673
|
/** Skip cache initialization */
|
|
546
674
|
skipCache?: boolean;
|
|
675
|
+
/** Skip observability initialization */
|
|
676
|
+
skipObservability?: boolean;
|
|
547
677
|
/** Enable verbose logging */
|
|
548
678
|
verbose?: boolean;
|
|
549
679
|
/** Error handler configuration */
|
|
@@ -556,13 +686,15 @@ export interface CoreInitOptionsBase<TDb = unknown, TApi = unknown> {
|
|
|
556
686
|
/**
|
|
557
687
|
* Core services result from initialization
|
|
558
688
|
*/
|
|
559
|
-
export interface CoreServicesResultBase<TDb = unknown, TApi = unknown, TCache = unknown> {
|
|
689
|
+
export interface CoreServicesResultBase<TDb = unknown, TApi = unknown, TCache = unknown, TObservability = unknown> {
|
|
560
690
|
/** Database service instance (null if skipped or on frontend) */
|
|
561
691
|
db: TDb | null;
|
|
562
692
|
/** API client service class */
|
|
563
693
|
api: TApi | null;
|
|
564
694
|
/** Cache service instance (null if skipped or on frontend) */
|
|
565
695
|
cache: TCache | null;
|
|
696
|
+
/** Observability adapter instance (null if skipped) */
|
|
697
|
+
observability: TObservability | null;
|
|
566
698
|
/** Loaded environment variables */
|
|
567
699
|
env: Record<string, string | undefined>;
|
|
568
700
|
/** Detected runtime environment */
|
package/dist/index.cjs
CHANGED
|
@@ -7306,6 +7306,46 @@ var CORRELATION_TYPE = /* @__PURE__ */ ((CORRELATION_TYPE2) => {
|
|
|
7306
7306
|
return CORRELATION_TYPE2;
|
|
7307
7307
|
})(CORRELATION_TYPE || {});
|
|
7308
7308
|
|
|
7309
|
+
// src/observability/types.ts
|
|
7310
|
+
var OBSERVABILITY_METRICS = {
|
|
7311
|
+
// Service metrics
|
|
7312
|
+
SERVICE_OPERATION_DURATION: "service.operation.duration",
|
|
7313
|
+
SERVICE_OPERATION_COUNT: "service.operation.count",
|
|
7314
|
+
SERVICE_OPERATION_ERROR: "service.operation.error",
|
|
7315
|
+
// Database metrics
|
|
7316
|
+
DB_QUERY_DURATION: "db.query.duration",
|
|
7317
|
+
DB_QUERY_COUNT: "db.query.count",
|
|
7318
|
+
DB_CONNECTION_POOL_SIZE: "db.connection.pool.size",
|
|
7319
|
+
DB_CONNECTION_POOL_USED: "db.connection.pool.used",
|
|
7320
|
+
// Cache metrics
|
|
7321
|
+
CACHE_HIT: "cache.hit",
|
|
7322
|
+
CACHE_MISS: "cache.miss",
|
|
7323
|
+
CACHE_SET: "cache.set",
|
|
7324
|
+
CACHE_DELETE: "cache.delete",
|
|
7325
|
+
// API metrics
|
|
7326
|
+
API_REQUEST_DURATION: "api.request.duration",
|
|
7327
|
+
API_REQUEST_COUNT: "api.request.count",
|
|
7328
|
+
API_REQUEST_ERROR: "api.request.error",
|
|
7329
|
+
// Transaction metrics
|
|
7330
|
+
TRANSACTION_DURATION: "transaction.duration",
|
|
7331
|
+
TRANSACTION_COUNT: "transaction.count",
|
|
7332
|
+
TRANSACTION_ROLLBACK: "transaction.rollback"
|
|
7333
|
+
};
|
|
7334
|
+
var OBSERVABILITY_SPANS = {
|
|
7335
|
+
SERVICE_CREATE: "service.create",
|
|
7336
|
+
SERVICE_UPDATE: "service.update",
|
|
7337
|
+
SERVICE_DELETE: "service.delete",
|
|
7338
|
+
SERVICE_GET: "service.get",
|
|
7339
|
+
SERVICE_LIST: "service.list",
|
|
7340
|
+
SERVICE_BULK_CREATE: "service.bulk_create",
|
|
7341
|
+
SERVICE_BULK_DELETE: "service.bulk_delete",
|
|
7342
|
+
SERVICE_TRANSACTION: "service.transaction",
|
|
7343
|
+
DB_QUERY: "db.query",
|
|
7344
|
+
CACHE_GET: "cache.get",
|
|
7345
|
+
CACHE_SET: "cache.set",
|
|
7346
|
+
API_REQUEST: "api.request"
|
|
7347
|
+
};
|
|
7348
|
+
|
|
7309
7349
|
// src/api/events/enum.ts
|
|
7310
7350
|
var EVENT_NAMESPACES = {
|
|
7311
7351
|
HEADERS: "headers",
|
|
@@ -8656,6 +8696,8 @@ exports.NOTIFICATION_ERROR_CODES = NOTIFICATION_ERROR_CODES;
|
|
|
8656
8696
|
exports.NOTIFICATION_PROVIDERS = NOTIFICATION_PROVIDERS;
|
|
8657
8697
|
exports.NetworkPresetNames = NetworkPresetNames;
|
|
8658
8698
|
exports.NotificationCategorySchema = NotificationCategorySchema;
|
|
8699
|
+
exports.OBSERVABILITY_METRICS = OBSERVABILITY_METRICS;
|
|
8700
|
+
exports.OBSERVABILITY_SPANS = OBSERVABILITY_SPANS;
|
|
8659
8701
|
exports.OPERATIONS = COMMON_OPERATIONS;
|
|
8660
8702
|
exports.ORGANIZATION_TIER = ORGANIZATION_TIER;
|
|
8661
8703
|
exports.OUTPUT_FORMAT = OUTPUT_FORMAT;
|