@plyaz/types 1.23.0 → 1.23.1

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.
@@ -126,7 +126,7 @@ export type CoreValidatorClass<T extends CoreBaseValidatorInstance = CoreBaseVal
126
126
  * interface BasicInjectedServices extends CoreInjectedServices {}
127
127
  * ```
128
128
  */
129
- export interface CoreInjectedServices<TCache = unknown, TDb = unknown, TApi = unknown, TStores = unknown> {
129
+ export interface CoreInjectedServices<TCache = unknown, TDb = unknown, TApi = unknown, TStores = unknown, TObservability = unknown> {
130
130
  /** Cache manager instance */
131
131
  cache?: TCache;
132
132
  /** Database service instance */
@@ -139,6 +139,11 @@ export interface CoreInjectedServices<TCache = unknown, TDb = unknown, TApi = un
139
139
  * @example { example: ExampleStoreSlice, errors: ErrorStoreSlice }
140
140
  */
141
141
  stores?: TStores extends Record<string, unknown> ? Partial<TStores> : Record<string, TStores>;
142
+ /**
143
+ * Observability service instance for metrics, tracing, and logging.
144
+ * Supports adapter-based providers (Datadog, Grafana, OpenTelemetry, etc.)
145
+ */
146
+ observability?: TObservability;
142
147
  }
143
148
  /**
144
149
  * 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';
@@ -213,6 +213,38 @@ export interface CoreServiceInitConfig {
213
213
  /** Default TTL in seconds for cached operations */
214
214
  defaultTtl?: number;
215
215
  };
216
+ /**
217
+ * Create a dedicated observability instance for this service.
218
+ *
219
+ * By default, services share the global observability adapter. Use this when
220
+ * a service needs its own isolated observability (e.g., different provider,
221
+ * custom tags, separate sampling).
222
+ *
223
+ * - `false` or `undefined`: Use global shared observability (default)
224
+ * - `true`: Create dedicated instance using global config
225
+ * - `ObservabilityAdapterConfig`: Create dedicated instance with custom config
226
+ *
227
+ * @example
228
+ * ```typescript
229
+ * // Use global shared observability (default)
230
+ * { service: UserService, config: { enabled: true } }
231
+ *
232
+ * // Create dedicated observability with global config
233
+ * { service: PaymentService, config: { dedicatedObservability: true } }
234
+ *
235
+ * // Create dedicated observability with custom config
236
+ * {
237
+ * service: CriticalService,
238
+ * config: {
239
+ * dedicatedObservability: {
240
+ * serviceName: 'critical-service',
241
+ * samplingRate: 1.0, // 100% sampling for critical operations
242
+ * },
243
+ * },
244
+ * }
245
+ * ```
246
+ */
247
+ dedicatedObservability?: boolean | CoreObservabilityConfig;
216
248
  }
217
249
  /**
218
250
  * Options passed to the service factory method
@@ -304,6 +336,27 @@ export interface CoreServiceCreateOptions<TConfig = unknown, TMapper = unknown,
304
336
  */
305
337
  instance?: unknown;
306
338
  };
339
+ /**
340
+ * Observability configuration and mode.
341
+ */
342
+ observability?: {
343
+ /**
344
+ * Whether to use a dedicated (isolated) observability instance.
345
+ * - `false`: Use global shared instance (default)
346
+ * - `true`: Create dedicated instance
347
+ */
348
+ dedicated: boolean;
349
+ /**
350
+ * Observability config (merged global + per-service config).
351
+ * Used to create dedicated instance or configure global.
352
+ */
353
+ config?: CoreObservabilityConfig;
354
+ /**
355
+ * Actual ObservabilityAdapter instance to use.
356
+ * Injected by ServiceRegistry, not created by service.
357
+ */
358
+ instance?: unknown;
359
+ };
307
360
  /** Logger prefix */
308
361
  loggerPrefix?: string;
309
362
  /** Whether this is a singleton instance */
@@ -387,6 +440,8 @@ export interface CoreServiceRegistryConfig {
387
440
  db?: Partial<CoreDbServiceConfig>;
388
441
  /** Global cache config (shared by all services unless overridden) */
389
442
  cache?: CoreCacheConfig;
443
+ /** Global observability config (shared by all services unless overridden) */
444
+ observability?: CoreObservabilityConfig;
390
445
  /**
391
446
  * Store registry interface for injecting stores into services.
392
447
  * Provides type-safe store access via store keys.
@@ -519,6 +574,70 @@ export interface CoreCacheConfig {
519
574
  keyPrefix?: string;
520
575
  };
521
576
  }
577
+ /**
578
+ * Observability initialization configuration
579
+ */
580
+ export interface CoreObservabilityConfig {
581
+ /** Enable/disable observability (default: true) */
582
+ enabled?: boolean;
583
+ /** Service name for tagging */
584
+ serviceName?: string;
585
+ /** Environment (production, staging, development) */
586
+ environment?: string;
587
+ /** Default tags to add to all metrics/spans */
588
+ defaultTags?: Record<string, string>;
589
+ /** Sampling rate for traces (0.0 to 1.0) */
590
+ samplingRate?: number;
591
+ /** Flush interval in milliseconds */
592
+ flushInterval?: number;
593
+ /** Buffer size before auto-flush */
594
+ bufferSize?: number;
595
+ /**
596
+ * Provider type
597
+ * Currently supported: 'datadog', 'console', 'noop'
598
+ * Planned: 'grafana', 'opentelemetry', 'prometheus', 'newrelic', 'custom'
599
+ */
600
+ provider?: 'datadog' | 'console' | 'noop';
601
+ /** Mode for multi-provider: 'parallel' sends to all, 'priority' falls back on error */
602
+ mode?: 'single' | 'parallel' | 'priority';
603
+ /** Datadog-specific configuration */
604
+ datadog?: {
605
+ /** Datadog API key */
606
+ apiKey?: string;
607
+ /** Datadog site (e.g., 'datadoghq.com', 'datadoghq.eu') */
608
+ site?: string;
609
+ /** Enable APM tracing */
610
+ apmEnabled?: boolean;
611
+ /** Enable RUM */
612
+ rumEnabled?: boolean;
613
+ /** RUM application ID */
614
+ rumApplicationId?: string;
615
+ /** RUM client token */
616
+ rumClientToken?: string;
617
+ };
618
+ /** Grafana-specific configuration */
619
+ grafana?: {
620
+ /** Push gateway URL (for Prometheus) */
621
+ pushGatewayUrl?: string;
622
+ /** Grafana Cloud user */
623
+ grafanaCloudUser?: string;
624
+ /** Grafana Cloud API key */
625
+ grafanaCloudApiKey?: string;
626
+ /** Loki endpoint for logs */
627
+ lokiEndpoint?: string;
628
+ /** Tempo endpoint for traces */
629
+ tempoEndpoint?: string;
630
+ };
631
+ /** OpenTelemetry-specific configuration */
632
+ opentelemetry?: {
633
+ /** OTLP endpoint URL */
634
+ endpoint?: string;
635
+ /** Headers for OTLP exporter */
636
+ headers?: Record<string, string>;
637
+ /** Export interval in milliseconds */
638
+ exportInterval?: number;
639
+ };
640
+ }
522
641
  /**
523
642
  * Base core initialization options
524
643
  * Extended by @plyaz/core's CoreInitOptions with specific types
@@ -538,12 +657,16 @@ export interface CoreInitOptionsBase<TDb = unknown, TApi = unknown> {
538
657
  api?: TApi;
539
658
  /** Cache configuration */
540
659
  cache?: CoreCacheConfig;
660
+ /** Observability configuration */
661
+ observability?: CoreObservabilityConfig;
541
662
  /** Skip database initialization */
542
663
  skipDb?: boolean;
543
664
  /** Skip API client initialization */
544
665
  skipApi?: boolean;
545
666
  /** Skip cache initialization */
546
667
  skipCache?: boolean;
668
+ /** Skip observability initialization */
669
+ skipObservability?: boolean;
547
670
  /** Enable verbose logging */
548
671
  verbose?: boolean;
549
672
  /** Error handler configuration */
@@ -556,13 +679,15 @@ export interface CoreInitOptionsBase<TDb = unknown, TApi = unknown> {
556
679
  /**
557
680
  * Core services result from initialization
558
681
  */
559
- export interface CoreServicesResultBase<TDb = unknown, TApi = unknown, TCache = unknown> {
682
+ export interface CoreServicesResultBase<TDb = unknown, TApi = unknown, TCache = unknown, TObservability = unknown> {
560
683
  /** Database service instance (null if skipped or on frontend) */
561
684
  db: TDb | null;
562
685
  /** API client service class */
563
686
  api: TApi | null;
564
687
  /** Cache service instance (null if skipped or on frontend) */
565
688
  cache: TCache | null;
689
+ /** Observability adapter instance (null if skipped) */
690
+ observability: TObservability | null;
566
691
  /** Loaded environment variables */
567
692
  env: Record<string, string | undefined>;
568
693
  /** 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;