@lssm/lib.observability 0.0.0-canary-20251217052941 → 0.0.0-canary-20251217060433

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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @lssm/lib.observability
2
2
 
3
- ## 0.0.0-canary-20251217052941
3
+ ## 0.0.0-canary-20251217060433
4
4
 
5
5
  ### Minor Changes
6
6
 
@@ -9,7 +9,7 @@
9
9
  ### Patch Changes
10
10
 
11
11
  - Updated dependencies [66a5dfd]
12
- - @lssm/lib.lifecycle@0.0.0-canary-20251217052941
12
+ - @lssm/lib.lifecycle@0.0.0-canary-20251217060433
13
13
 
14
14
  ## 0.5.0
15
15
 
@@ -0,0 +1,20 @@
1
+ import { AnomalySignal } from "./anomaly-detector.mjs";
2
+ import { RootCauseAnalysis } from "./root-cause-analyzer.mjs";
3
+
4
+ //#region src/anomaly/alert-manager.d.ts
5
+ interface AlertManagerOptions {
6
+ cooldownMs?: number;
7
+ transport: (payload: {
8
+ signal: AnomalySignal;
9
+ analysis: RootCauseAnalysis;
10
+ }) => Promise<void> | void;
11
+ }
12
+ declare class AlertManager {
13
+ private readonly options;
14
+ private readonly cooldownMs;
15
+ private readonly lastAlert;
16
+ constructor(options: AlertManagerOptions);
17
+ notify(signal: AnomalySignal, analysis: RootCauseAnalysis): Promise<void>;
18
+ }
19
+ //#endregion
20
+ export { AlertManager, AlertManagerOptions };
@@ -0,0 +1,25 @@
1
+ import { BaselineCalculator, MetricPoint } from "./baseline-calculator.mjs";
2
+
3
+ //#region src/anomaly/anomaly-detector.d.ts
4
+ interface AnomalyThresholds {
5
+ errorRateDelta?: number;
6
+ latencyDelta?: number;
7
+ throughputDrop?: number;
8
+ minSamples?: number;
9
+ }
10
+ interface AnomalySignal {
11
+ type: 'error_rate_spike' | 'latency_regression' | 'throughput_drop';
12
+ delta: number;
13
+ point: MetricPoint;
14
+ baseline: ReturnType<BaselineCalculator['getSnapshot']>;
15
+ }
16
+ declare class AnomalyDetector {
17
+ private readonly baseline;
18
+ private readonly thresholds;
19
+ constructor(options?: AnomalyThresholds);
20
+ evaluate(point: MetricPoint): AnomalySignal[];
21
+ private relativeDelta;
22
+ private relativeDrop;
23
+ }
24
+ //#endregion
25
+ export { AnomalyDetector, AnomalySignal, AnomalyThresholds };
@@ -0,0 +1,25 @@
1
+ //#region src/anomaly/baseline-calculator.d.ts
2
+ interface MetricPoint {
3
+ latencyP99: number;
4
+ latencyP95: number;
5
+ errorRate: number;
6
+ throughput: number;
7
+ timestamp: Date;
8
+ }
9
+ interface BaselineSnapshot {
10
+ latencyP99: number;
11
+ latencyP95: number;
12
+ errorRate: number;
13
+ throughput: number;
14
+ sampleCount: number;
15
+ }
16
+ declare class BaselineCalculator {
17
+ private readonly alpha;
18
+ private snapshot;
19
+ constructor(alpha?: number);
20
+ update(point: MetricPoint): BaselineSnapshot;
21
+ getSnapshot(): BaselineSnapshot;
22
+ private mix;
23
+ }
24
+ //#endregion
25
+ export { BaselineCalculator, BaselineSnapshot, MetricPoint };
@@ -0,0 +1,22 @@
1
+ import { AnomalySignal } from "./anomaly-detector.mjs";
2
+
3
+ //#region src/anomaly/root-cause-analyzer.d.ts
4
+ interface DeploymentEvent {
5
+ id: string;
6
+ operation: string;
7
+ deployedAt: Date;
8
+ stage?: string;
9
+ status: 'in_progress' | 'completed' | 'rolled_back';
10
+ }
11
+ interface RootCauseAnalysis {
12
+ signal: AnomalySignal;
13
+ culprit?: DeploymentEvent;
14
+ notes: string[];
15
+ }
16
+ declare class RootCauseAnalyzer {
17
+ private readonly lookbackMs;
18
+ constructor(lookbackMs?: number);
19
+ analyze(signal: AnomalySignal, deployments: DeploymentEvent[]): RootCauseAnalysis;
20
+ }
21
+ //#endregion
22
+ export { DeploymentEvent, RootCauseAnalysis, RootCauseAnalyzer };
@@ -0,0 +1,13 @@
1
+ import { BaselineCalculator } from "./anomaly/baseline-calculator.mjs";
2
+ import { AnomalyDetector, AnomalySignal, AnomalyThresholds } from "./anomaly/anomaly-detector.mjs";
3
+ import { RootCauseAnalysis, RootCauseAnalyzer } from "./anomaly/root-cause-analyzer.mjs";
4
+ import { AlertManager } from "./anomaly/alert-manager.mjs";
5
+ import { getTracer, traceAsync, traceSync } from "./tracing/index.mjs";
6
+ import { createCounter, createHistogram, createUpDownCounter, getMeter, standardMetrics } from "./metrics/index.mjs";
7
+ import { LogEntry, LogLevel, Logger, logger } from "./logging/index.mjs";
8
+ import { IntentAggregator, IntentAggregatorSnapshot, TelemetrySample } from "./intent/aggregator.mjs";
9
+ import { TracingMiddlewareOptions, createTracingMiddleware } from "./tracing/middleware.mjs";
10
+ import { IntentDetector, IntentSignal, IntentSignalType } from "./intent/detector.mjs";
11
+ import { EvolutionPipeline, EvolutionPipelineEvent, EvolutionPipelineOptions } from "./pipeline/evolution-pipeline.mjs";
12
+ import { LifecycleKpiPipeline, LifecycleKpiPipelineOptions, LifecyclePipelineEvent } from "./pipeline/lifecycle-pipeline.mjs";
13
+ export { AlertManager, AnomalyDetector, type AnomalySignal, type AnomalyThresholds, BaselineCalculator, EvolutionPipeline, type EvolutionPipelineEvent, type EvolutionPipelineOptions, IntentAggregator, type IntentAggregatorSnapshot, IntentDetector, type IntentSignal, type IntentSignalType, LifecycleKpiPipeline, type LifecycleKpiPipelineOptions, type LifecyclePipelineEvent, type LogEntry, type LogLevel, Logger, type RootCauseAnalysis, RootCauseAnalyzer, type TelemetrySample, type TracingMiddlewareOptions, createCounter, createHistogram, createTracingMiddleware, createUpDownCounter, getMeter, getTracer, logger, standardMetrics, traceAsync, traceSync };
@@ -0,0 +1,59 @@
1
+ //#region src/intent/aggregator.d.ts
2
+ interface TelemetrySample {
3
+ operation: {
4
+ name: string;
5
+ version: number;
6
+ };
7
+ durationMs: number;
8
+ success: boolean;
9
+ timestamp: Date;
10
+ errorCode?: string;
11
+ tenantId?: string;
12
+ traceId?: string;
13
+ actorId?: string;
14
+ metadata?: Record<string, unknown>;
15
+ }
16
+ interface AggregatedOperationMetrics {
17
+ operation: {
18
+ name: string;
19
+ version: number;
20
+ };
21
+ totalCalls: number;
22
+ successRate: number;
23
+ errorRate: number;
24
+ averageLatencyMs: number;
25
+ p95LatencyMs: number;
26
+ p99LatencyMs: number;
27
+ maxLatencyMs: number;
28
+ windowStart: Date;
29
+ windowEnd: Date;
30
+ topErrors: Record<string, number>;
31
+ }
32
+ interface OperationSequence {
33
+ steps: string[];
34
+ tenantId?: string;
35
+ count: number;
36
+ }
37
+ interface IntentAggregatorSnapshot {
38
+ metrics: AggregatedOperationMetrics[];
39
+ sequences: OperationSequence[];
40
+ sampleCount: number;
41
+ windowStart?: Date;
42
+ windowEnd?: Date;
43
+ }
44
+ interface IntentAggregatorOptions {
45
+ windowMs?: number;
46
+ sequenceSampleSize?: number;
47
+ }
48
+ declare class IntentAggregator {
49
+ private readonly windowMs;
50
+ private readonly sequenceSampleSize;
51
+ private readonly samples;
52
+ constructor(options?: IntentAggregatorOptions);
53
+ add(sample: TelemetrySample): void;
54
+ flush(now?: Date): IntentAggregatorSnapshot;
55
+ private aggregateMetrics;
56
+ private buildSequences;
57
+ }
58
+ //#endregion
59
+ export { AggregatedOperationMetrics, IntentAggregator, IntentAggregatorOptions, IntentAggregatorSnapshot, OperationSequence, TelemetrySample };
@@ -0,0 +1,31 @@
1
+ import { AggregatedOperationMetrics, OperationSequence } from "./aggregator.mjs";
2
+
3
+ //#region src/intent/detector.d.ts
4
+ type IntentSignalType = 'latency-regression' | 'error-spike' | 'throughput-drop' | 'missing-workflow-step';
5
+ interface IntentSignal {
6
+ id: string;
7
+ type: IntentSignalType;
8
+ operation?: AggregatedOperationMetrics['operation'];
9
+ confidence: number;
10
+ description: string;
11
+ metadata?: Record<string, unknown>;
12
+ evidence: {
13
+ type: 'metric' | 'sequence' | 'anomaly';
14
+ description: string;
15
+ data?: Record<string, unknown>;
16
+ }[];
17
+ }
18
+ interface IntentDetectorOptions {
19
+ errorRateThreshold?: number;
20
+ latencyP99ThresholdMs?: number;
21
+ throughputDropThreshold?: number;
22
+ minSequenceLength?: number;
23
+ }
24
+ declare class IntentDetector {
25
+ private readonly options;
26
+ constructor(options?: IntentDetectorOptions);
27
+ detectFromMetrics(current: AggregatedOperationMetrics[], previous?: AggregatedOperationMetrics[]): IntentSignal[];
28
+ detectSequentialIntents(sequences: OperationSequence[]): IntentSignal[];
29
+ }
30
+ //#endregion
31
+ export { IntentDetector, IntentDetectorOptions, IntentSignal, IntentSignalType };
@@ -0,0 +1,19 @@
1
+ //#region src/logging/index.d.ts
2
+ type LogLevel = 'debug' | 'info' | 'warn' | 'error';
3
+ interface LogEntry {
4
+ level: LogLevel;
5
+ message: string;
6
+ [key: string]: unknown;
7
+ }
8
+ declare class Logger {
9
+ private readonly serviceName;
10
+ constructor(serviceName: string);
11
+ private log;
12
+ debug(message: string, meta?: Record<string, unknown>): void;
13
+ info(message: string, meta?: Record<string, unknown>): void;
14
+ warn(message: string, meta?: Record<string, unknown>): void;
15
+ error(message: string, meta?: Record<string, unknown>): void;
16
+ }
17
+ declare const logger: Logger;
18
+ //#endregion
19
+ export { LogEntry, LogLevel, Logger, logger };
@@ -0,0 +1,16 @@
1
+ import * as _opentelemetry_api0 from "@opentelemetry/api";
2
+ import { Counter, Histogram, Meter, UpDownCounter } from "@opentelemetry/api";
3
+
4
+ //#region src/metrics/index.d.ts
5
+ declare function getMeter(name?: string): Meter;
6
+ declare function createCounter(name: string, description?: string, meterName?: string): Counter;
7
+ declare function createUpDownCounter(name: string, description?: string, meterName?: string): UpDownCounter;
8
+ declare function createHistogram(name: string, description?: string, meterName?: string): Histogram;
9
+ declare const standardMetrics: {
10
+ httpRequests: Counter<_opentelemetry_api0.Attributes>;
11
+ httpDuration: Histogram<_opentelemetry_api0.Attributes>;
12
+ operationErrors: Counter<_opentelemetry_api0.Attributes>;
13
+ workflowDuration: Histogram<_opentelemetry_api0.Attributes>;
14
+ };
15
+ //#endregion
16
+ export { createCounter, createHistogram, createUpDownCounter, getMeter, standardMetrics };
@@ -0,0 +1,39 @@
1
+ import { IntentAggregator, IntentAggregatorSnapshot, TelemetrySample } from "../intent/aggregator.mjs";
2
+ import { IntentDetector, IntentSignal } from "../intent/detector.mjs";
3
+ import { EventEmitter } from "node:events";
4
+
5
+ //#region src/pipeline/evolution-pipeline.d.ts
6
+ type EvolutionPipelineEvent = {
7
+ type: 'intent.detected';
8
+ payload: IntentSignal;
9
+ } | {
10
+ type: 'telemetry.window';
11
+ payload: {
12
+ sampleCount: number;
13
+ };
14
+ };
15
+ interface EvolutionPipelineOptions {
16
+ detector?: IntentDetector;
17
+ aggregator?: IntentAggregator;
18
+ emitter?: EventEmitter;
19
+ onIntent?: (intent: IntentSignal) => Promise<void> | void;
20
+ onSnapshot?: (snapshot: IntentAggregatorSnapshot) => Promise<void> | void;
21
+ }
22
+ declare class EvolutionPipeline {
23
+ private readonly detector;
24
+ private readonly aggregator;
25
+ private readonly emitter;
26
+ private readonly onIntent?;
27
+ private readonly onSnapshot?;
28
+ private timer?;
29
+ private previousMetrics?;
30
+ constructor(options?: EvolutionPipelineOptions);
31
+ ingest(sample: TelemetrySample): void;
32
+ on(listener: (event: EvolutionPipelineEvent) => void): void;
33
+ start(intervalMs?: number): void;
34
+ stop(): void;
35
+ run(): Promise<void>;
36
+ private emit;
37
+ }
38
+ //#endregion
39
+ export { EvolutionPipeline, EvolutionPipelineEvent, EvolutionPipelineOptions };
@@ -0,0 +1,43 @@
1
+ import { EventEmitter } from "node:events";
2
+ import { LifecycleAssessment, LifecycleStage } from "@lssm/lib.lifecycle";
3
+
4
+ //#region src/pipeline/lifecycle-pipeline.d.ts
5
+ type LifecyclePipelineEvent = {
6
+ type: 'assessment.recorded';
7
+ payload: {
8
+ tenantId?: string;
9
+ stage: LifecycleStage;
10
+ };
11
+ } | {
12
+ type: 'stage.changed';
13
+ payload: {
14
+ tenantId?: string;
15
+ previousStage?: LifecycleStage;
16
+ nextStage: LifecycleStage;
17
+ };
18
+ } | {
19
+ type: 'confidence.low';
20
+ payload: {
21
+ tenantId?: string;
22
+ confidence: number;
23
+ };
24
+ };
25
+ interface LifecycleKpiPipelineOptions {
26
+ meterName?: string;
27
+ emitter?: EventEmitter;
28
+ lowConfidenceThreshold?: number;
29
+ }
30
+ declare class LifecycleKpiPipeline {
31
+ private readonly assessmentCounter;
32
+ private readonly confidenceHistogram;
33
+ private readonly stageUpDownCounter;
34
+ private readonly emitter;
35
+ private readonly lowConfidenceThreshold;
36
+ private readonly currentStageByTenant;
37
+ constructor(options?: LifecycleKpiPipelineOptions);
38
+ recordAssessment(assessment: LifecycleAssessment, tenantId?: string): void;
39
+ on(listener: (event: LifecyclePipelineEvent) => void): void;
40
+ private ensureStageCounters;
41
+ }
42
+ //#endregion
43
+ export { LifecycleKpiPipeline, LifecycleKpiPipelineOptions, LifecyclePipelineEvent };
@@ -0,0 +1,8 @@
1
+ import { Span, Tracer } from "@opentelemetry/api";
2
+
3
+ //#region src/tracing/index.d.ts
4
+ declare function getTracer(name?: string): Tracer;
5
+ declare function traceAsync<T>(name: string, fn: (span: Span) => Promise<T>, tracerName?: string): Promise<T>;
6
+ declare function traceSync<T>(name: string, fn: (span: Span) => T, tracerName?: string): T;
7
+ //#endregion
8
+ export { getTracer, traceAsync, traceSync };
@@ -0,0 +1,18 @@
1
+ import { TelemetrySample } from "../intent/aggregator.mjs";
2
+
3
+ //#region src/tracing/middleware.d.ts
4
+ interface TracingMiddlewareOptions {
5
+ resolveOperation?: (input: {
6
+ req: Request;
7
+ res?: Response;
8
+ }) => {
9
+ name: string;
10
+ version: number;
11
+ } | undefined;
12
+ onSample?: (sample: TelemetrySample) => void;
13
+ tenantResolver?: (req: Request) => string | undefined;
14
+ actorResolver?: (req: Request) => string | undefined;
15
+ }
16
+ declare function createTracingMiddleware(options?: TracingMiddlewareOptions): (req: Request, next: () => Promise<Response>) => Promise<Response>;
17
+ //#endregion
18
+ export { TracingMiddlewareOptions, createTracingMiddleware };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lssm/lib.observability",
3
- "version": "0.0.0-canary-20251217052941",
3
+ "version": "0.0.0-canary-20251217060433",
4
4
  "main": "./dist/index.mjs",
5
5
  "types": "./dist/index.d.mts",
6
6
  "scripts": {
@@ -17,7 +17,7 @@
17
17
  "test": "bun run"
18
18
  },
19
19
  "dependencies": {
20
- "@lssm/lib.lifecycle": "0.0.0-canary-20251217052941"
20
+ "@lssm/lib.lifecycle": "0.0.0-canary-20251217060433"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "@opentelemetry/api": "*"
@@ -26,19 +26,19 @@
26
26
  "typescript": "^5.0.0"
27
27
  },
28
28
  "exports": {
29
- ".": "./src/index.ts",
30
- "./anomaly/alert-manager": "./src/anomaly/alert-manager.ts",
31
- "./anomaly/anomaly-detector": "./src/anomaly/anomaly-detector.ts",
32
- "./anomaly/baseline-calculator": "./src/anomaly/baseline-calculator.ts",
33
- "./anomaly/root-cause-analyzer": "./src/anomaly/root-cause-analyzer.ts",
34
- "./intent/aggregator": "./src/intent/aggregator.ts",
35
- "./intent/detector": "./src/intent/detector.ts",
36
- "./logging": "./src/logging/index.ts",
37
- "./metrics": "./src/metrics/index.ts",
38
- "./pipeline/evolution-pipeline": "./src/pipeline/evolution-pipeline.ts",
39
- "./pipeline/lifecycle-pipeline": "./src/pipeline/lifecycle-pipeline.ts",
40
- "./tracing": "./src/tracing/index.ts",
41
- "./tracing/middleware": "./src/tracing/middleware.ts",
29
+ ".": "./dist/index.mjs",
30
+ "./anomaly/alert-manager": "./dist/anomaly/alert-manager.mjs",
31
+ "./anomaly/anomaly-detector": "./dist/anomaly/anomaly-detector.mjs",
32
+ "./anomaly/baseline-calculator": "./dist/anomaly/baseline-calculator.mjs",
33
+ "./anomaly/root-cause-analyzer": "./dist/anomaly/root-cause-analyzer.mjs",
34
+ "./intent/aggregator": "./dist/intent/aggregator.mjs",
35
+ "./intent/detector": "./dist/intent/detector.mjs",
36
+ "./logging": "./dist/logging/index.mjs",
37
+ "./metrics": "./dist/metrics/index.mjs",
38
+ "./pipeline/evolution-pipeline": "./dist/pipeline/evolution-pipeline.mjs",
39
+ "./pipeline/lifecycle-pipeline": "./dist/pipeline/lifecycle-pipeline.mjs",
40
+ "./tracing": "./dist/tracing/index.mjs",
41
+ "./tracing/middleware": "./dist/tracing/middleware.mjs",
42
42
  "./*": "./*"
43
43
  },
44
44
  "module": "./dist/index.mjs",