@lssm/lib.observability 0.0.0-canary-20251120192244 → 0.0.0-canary-20251206160926
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 +76 -1
- package/README.md +21 -0
- package/dist/anomaly/alert-manager.d.mts +20 -0
- package/dist/anomaly/alert-manager.mjs +1 -0
- package/dist/anomaly/anomaly-detector.d.mts +25 -0
- package/dist/anomaly/anomaly-detector.mjs +1 -0
- package/dist/anomaly/baseline-calculator.d.mts +25 -0
- package/dist/anomaly/baseline-calculator.mjs +1 -0
- package/dist/anomaly/root-cause-analyzer.d.mts +22 -0
- package/dist/anomaly/root-cause-analyzer.mjs +1 -0
- package/dist/index.d.mts +10 -2
- package/dist/index.mjs +1 -1
- package/dist/intent/aggregator.d.mts +59 -0
- package/dist/intent/aggregator.mjs +1 -0
- package/dist/intent/detector.d.mts +31 -0
- package/dist/intent/detector.mjs +1 -0
- package/dist/lifecycle/dist/index.mjs +1 -0
- package/dist/lifecycle/dist/types/axes.mjs +1 -0
- package/dist/lifecycle/dist/types/milestones.mjs +1 -0
- package/dist/lifecycle/dist/types/signals.mjs +1 -0
- package/dist/lifecycle/dist/types/stages.mjs +1 -0
- package/dist/lifecycle/dist/utils/formatters.mjs +1 -0
- package/dist/logging/index.d.mts +1 -2
- package/dist/logging/index.mjs +1 -2
- package/dist/metrics/index.d.mts +1 -2
- package/dist/metrics/index.mjs +1 -2
- package/dist/pipeline/evolution-pipeline.d.mts +39 -0
- package/dist/pipeline/evolution-pipeline.mjs +1 -0
- package/dist/pipeline/lifecycle-pipeline.d.mts +43 -0
- package/dist/pipeline/lifecycle-pipeline.mjs +1 -0
- package/dist/tracing/index.d.mts +1 -2
- package/dist/tracing/index.mjs +1 -2
- package/dist/tracing/middleware.d.mts +16 -3
- package/dist/tracing/middleware.mjs +1 -2
- package/package.json +19 -5
- package/.turbo/turbo-build.log +0 -29
- package/dist/logging/index.d.mts.map +0 -1
- package/dist/logging/index.mjs.map +0 -1
- package/dist/metrics/index.d.mts.map +0 -1
- package/dist/metrics/index.mjs.map +0 -1
- package/dist/tracing/index.d.mts.map +0 -1
- package/dist/tracing/index.mjs.map +0 -1
- package/dist/tracing/middleware.d.mts.map +0 -1
- package/dist/tracing/middleware.mjs.map +0 -1
- package/src/index.ts +0 -13
- package/src/logging/index.ts +0 -57
- package/src/metrics/index.ts +0 -54
- package/src/tracing/index.ts +0 -62
- package/src/tracing/middleware.ts +0 -36
- package/tsconfig.json +0 -10
- package/tsconfig.tsbuildinfo +0 -1
- package/tsdown.config.js +0 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,81 @@
|
|
|
1
1
|
# @lssm/lib.observability
|
|
2
2
|
|
|
3
|
-
## 0.0.0-canary-
|
|
3
|
+
## 0.0.0-canary-20251206160926
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [3086383]
|
|
8
|
+
- @lssm/lib.lifecycle@0.0.0-canary-20251206160926
|
|
9
|
+
|
|
10
|
+
## 0.5.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- Refactor to be compatible with ai-sdk v6
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
- @lssm/lib.lifecycle@0.4.0
|
|
20
|
+
|
|
21
|
+
## 0.4.1
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Fix dependencies
|
|
26
|
+
- Updated dependencies
|
|
27
|
+
- @lssm/lib.lifecycle@0.3.1
|
|
28
|
+
|
|
29
|
+
## 0.4.0
|
|
30
|
+
|
|
31
|
+
### Minor Changes
|
|
32
|
+
|
|
33
|
+
- b7621d3: Fix version
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- Updated dependencies [b7621d3]
|
|
38
|
+
- @lssm/lib.lifecycle@0.3.0
|
|
39
|
+
|
|
40
|
+
## 0.3.0
|
|
41
|
+
|
|
42
|
+
### Minor Changes
|
|
43
|
+
|
|
44
|
+
- fix
|
|
45
|
+
|
|
46
|
+
### Patch Changes
|
|
47
|
+
|
|
48
|
+
- Updated dependencies
|
|
49
|
+
- @lssm/lib.lifecycle@0.2.0
|
|
50
|
+
|
|
51
|
+
## 0.2.2
|
|
52
|
+
|
|
53
|
+
### Patch Changes
|
|
54
|
+
|
|
55
|
+
- fix dependencies
|
|
56
|
+
- Updated dependencies
|
|
57
|
+
- @lssm/lib.lifecycle@0.1.2
|
|
58
|
+
|
|
59
|
+
## 0.2.1
|
|
60
|
+
|
|
61
|
+
### Patch Changes
|
|
62
|
+
|
|
63
|
+
- fix
|
|
64
|
+
- Updated dependencies
|
|
65
|
+
- @lssm/lib.lifecycle@0.1.1
|
|
66
|
+
|
|
67
|
+
## 0.2.0
|
|
68
|
+
|
|
69
|
+
### Minor Changes
|
|
70
|
+
|
|
71
|
+
- b1d0876: Managed platform
|
|
72
|
+
|
|
73
|
+
### Patch Changes
|
|
74
|
+
|
|
75
|
+
- Updated dependencies [b1d0876]
|
|
76
|
+
- @lssm/lib.lifecycle@0.1.0
|
|
77
|
+
|
|
78
|
+
## 0.1.0
|
|
4
79
|
|
|
5
80
|
### Minor Changes
|
|
6
81
|
|
package/README.md
CHANGED
|
@@ -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 @@
|
|
|
1
|
+
var e=class{cooldownMs;lastAlert=new Map;constructor(e){this.options=e,this.cooldownMs=e.cooldownMs??6e4}async notify(e,t){let n=`${e.type}:${t.culprit?.id??`none`}`,r=Date.now();r-(this.lastAlert.get(n)??0)<this.cooldownMs||(await this.options.transport({signal:e,analysis:t}),this.lastAlert.set(n,r))}};export{e as AlertManager};
|
|
@@ -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 @@
|
|
|
1
|
+
import{BaselineCalculator as e}from"./baseline-calculator.mjs";var t=class{baseline;thresholds={errorRateDelta:.5,latencyDelta:.35,throughputDrop:.4,minSamples:10};constructor(t={}){this.baseline=new e,this.thresholds={...this.thresholds,...t}}evaluate(e){let t=this.baseline.update(e);if(t.sampleCount<this.thresholds.minSamples)return[];let n=[],r=this.relativeDelta(e.errorRate,t.errorRate);r>this.thresholds.errorRateDelta&&n.push({type:`error_rate_spike`,delta:r,point:e,baseline:t});let i=this.relativeDelta(e.latencyP99,t.latencyP99);i>this.thresholds.latencyDelta&&n.push({type:`latency_regression`,delta:i,point:e,baseline:t});let a=this.relativeDrop(e.throughput,t.throughput);return a>this.thresholds.throughputDrop&&n.push({type:`throughput_drop`,delta:a,point:e,baseline:t}),n}relativeDelta(e,t){return t===0?0:(e-t)/t}relativeDrop(e,t){return t===0?0:(t-e)/t}};export{t as AnomalyDetector};
|
|
@@ -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 @@
|
|
|
1
|
+
var e=class{snapshot={latencyP99:0,latencyP95:0,errorRate:0,throughput:0,sampleCount:0};constructor(e=.2){this.alpha=e}update(e){let{sampleCount:t}=this.snapshot,n=t+1,r=t===0?1:this.alpha;return this.snapshot={latencyP99:this.mix(this.snapshot.latencyP99,e.latencyP99,r),latencyP95:this.mix(this.snapshot.latencyP95,e.latencyP95,r),errorRate:this.mix(this.snapshot.errorRate,e.errorRate,r),throughput:this.mix(this.snapshot.throughput,e.throughput,r),sampleCount:n},this.snapshot}getSnapshot(){return this.snapshot}mix(e,t,n){return this.snapshot.sampleCount===0?t:e*(1-n)+t*n}};export{e as BaselineCalculator};
|
|
@@ -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 @@
|
|
|
1
|
+
var e=class{constructor(e=900*1e3){this.lookbackMs=e}analyze(e,t){let n=new Date(e.point.timestamp.getTime()-this.lookbackMs),r=t.filter(e=>e.deployedAt>=n).sort((e,t)=>t.deployedAt.getTime()-e.deployedAt.getTime()),i=[],a;return r.length>0?(a=r[0],i.push(`Closest deployment ${a.id} (${a.operation}) at ${a.deployedAt.toISOString()}`)):i.push(`No deployments found within lookback window.`),e.type===`latency_regression`&&i.push(`Verify recent schema changes and external dependency latency.`),e.type===`error_rate_spike`&&i.push(`Check SLO monitor for correlated incidents.`),{signal:e,culprit:a,notes:i}}};export{e as RootCauseAnalyzer};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +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";
|
|
1
5
|
import { getTracer, traceAsync, traceSync } from "./tracing/index.mjs";
|
|
2
6
|
import { createCounter, createHistogram, createUpDownCounter, getMeter, standardMetrics } from "./metrics/index.mjs";
|
|
3
7
|
import { LogEntry, LogLevel, Logger, logger } from "./logging/index.mjs";
|
|
4
|
-
import {
|
|
5
|
-
|
|
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 };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getTracer as e,traceAsync as t,traceSync as n}from"./tracing/index.mjs";import{createCounter as r,createHistogram as i,createUpDownCounter as a,getMeter as o,standardMetrics as s}from"./metrics/index.mjs";import{Logger as c,logger as l}from"./logging/index.mjs";import{createTracingMiddleware as u}from"./tracing/middleware.mjs";export{c as Logger,r as createCounter,i as createHistogram,u as createTracingMiddleware,a as createUpDownCounter,o as getMeter,e as getTracer,l as logger,s as standardMetrics,t as traceAsync,n as traceSync};
|
|
1
|
+
import{getTracer as e,traceAsync as t,traceSync as n}from"./tracing/index.mjs";import{createCounter as r,createHistogram as i,createUpDownCounter as a,getMeter as o,standardMetrics as s}from"./metrics/index.mjs";import{Logger as c,logger as l}from"./logging/index.mjs";import{createTracingMiddleware as u}from"./tracing/middleware.mjs";import{IntentAggregator as d}from"./intent/aggregator.mjs";import{IntentDetector as f}from"./intent/detector.mjs";import{EvolutionPipeline as p}from"./pipeline/evolution-pipeline.mjs";import{LifecycleKpiPipeline as m}from"./pipeline/lifecycle-pipeline.mjs";import{BaselineCalculator as h}from"./anomaly/baseline-calculator.mjs";import{AnomalyDetector as g}from"./anomaly/anomaly-detector.mjs";import{RootCauseAnalyzer as _}from"./anomaly/root-cause-analyzer.mjs";import{AlertManager as v}from"./anomaly/alert-manager.mjs";export{v as AlertManager,g as AnomalyDetector,h as BaselineCalculator,p as EvolutionPipeline,d as IntentAggregator,f as IntentDetector,m as LifecycleKpiPipeline,c as Logger,_ as RootCauseAnalyzer,r as createCounter,i as createHistogram,u as createTracingMiddleware,a as createUpDownCounter,o as getMeter,e as getTracer,l as logger,s as standardMetrics,t as traceAsync,n as 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 @@
|
|
|
1
|
+
var e=class{windowMs;sequenceSampleSize;samples=[];constructor(e={}){this.windowMs=e.windowMs??9e5,this.sequenceSampleSize=e.sequenceSampleSize??1e3}add(e){this.samples.push(e)}flush(e=new Date){let t=e.getTime()-this.windowMs,n=this.samples.filter(e=>e.timestamp.getTime()>=t);this.samples.length=0;let r=this.aggregateMetrics(n),i=this.buildSequences(n),a=n.map(e=>e.timestamp.getTime());return{metrics:r,sequences:i,sampleCount:n.length,windowStart:a.length?new Date(Math.min(...a)):void 0,windowEnd:a.length?new Date(Math.max(...a)):void 0}}aggregateMetrics(e){if(!e.length)return[];let n=new Map;for(let t of e){let e=`${t.operation.name}.v${t.operation.version}`,r=n.get(e)??[];r.push(t),n.set(e,r)}return[...n.values()].map(e=>{let n=e.map(e=>e.durationMs).sort((e,t)=>e-t),r=e.filter(e=>!e.success),i=e.length,a=r.reduce((e,t)=>(t.errorCode&&(e[t.errorCode]=(e[t.errorCode]??0)+1),e),{}),o=e.map(e=>e.timestamp.getTime());return{operation:e[0].operation,totalCalls:i,successRate:(i-r.length)/i,errorRate:r.length/i,averageLatencyMs:n.reduce((e,t)=>e+t,0)/i,p95LatencyMs:t(n,.95),p99LatencyMs:t(n,.99),maxLatencyMs:Math.max(...n),windowStart:new Date(Math.min(...o)),windowEnd:new Date(Math.max(...o)),topErrors:a}})}buildSequences(e){let t=new Map;for(let n of e.slice(-this.sequenceSampleSize)){if(!n.traceId)continue;let e=t.get(n.traceId)??[];e.push(n),t.set(n.traceId,e)}let n={};for(let[e,r]of t.entries()){let e=r.sort((e,t)=>e.timestamp.getTime()-t.timestamp.getTime()),t=e.map(e=>e.operation.name);if(t.length<2)continue;let i=`${t.join(`>`)}@${e[0]?.tenantId??`global`}`,a=n[i];a?a.count+=1:n[i]={steps:t,tenantId:e[0]?.tenantId,count:1}}return Object.values(n).sort((e,t)=>t.count-e.count)}};function t(e,t){return e.length?e.length===1?e[0]:e[Math.min(e.length-1,Math.floor(t*e.length))]:0}export{e as IntentAggregator};
|
|
@@ -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 @@
|
|
|
1
|
+
import{randomUUID as e}from"node:crypto";const t={errorRateThreshold:.05,latencyP99ThresholdMs:750,throughputDropThreshold:.3,minSequenceLength:3};var n=class{options;constructor(e={}){this.options={errorRateThreshold:e.errorRateThreshold??t.errorRateThreshold,latencyP99ThresholdMs:e.latencyP99ThresholdMs??t.latencyP99ThresholdMs,throughputDropThreshold:e.throughputDropThreshold??t.throughputDropThreshold,minSequenceLength:e.minSequenceLength??t.minSequenceLength}}detectFromMetrics(t,n){let r=[],i=new Map((n??[]).map(e=>[`${e.operation.name}.v${e.operation.version}`,e]));for(let n of t){if(n.errorRate>=this.options.errorRateThreshold){r.push({id:e(),type:`error-spike`,operation:n.operation,confidence:Math.min(1,n.errorRate/this.options.errorRateThreshold),description:`Error rate ${n.errorRate.toFixed(2)} exceeded threshold`,metadata:{errorRate:n.errorRate,topErrors:n.topErrors},evidence:[{type:`metric`,description:`error-rate`,data:{errorRate:n.errorRate,threshold:this.options.errorRateThreshold}}]});continue}if(n.p99LatencyMs>=this.options.latencyP99ThresholdMs){r.push({id:e(),type:`latency-regression`,operation:n.operation,confidence:Math.min(1,n.p99LatencyMs/this.options.latencyP99ThresholdMs),description:`P99 latency ${n.p99LatencyMs}ms exceeded threshold`,metadata:{p99LatencyMs:n.p99LatencyMs},evidence:[{type:`metric`,description:`p99-latency`,data:{p99LatencyMs:n.p99LatencyMs,threshold:this.options.latencyP99ThresholdMs}}]});continue}let t=i.get(`${n.operation.name}.v${n.operation.version}`);if(t){let i=(t.totalCalls-n.totalCalls)/Math.max(t.totalCalls,1);i>=this.options.throughputDropThreshold&&r.push({id:e(),type:`throughput-drop`,operation:n.operation,confidence:Math.min(1,i/this.options.throughputDropThreshold),description:`Throughput dropped ${(i*100).toFixed(1)}% vs baseline`,metadata:{baselineCalls:t.totalCalls,currentCalls:n.totalCalls},evidence:[{type:`metric`,description:`throughput-drop`,data:{baselineCalls:t.totalCalls,currentCalls:n.totalCalls}}]})}}return r}detectSequentialIntents(t){let n=[];for(let r of t){if(r.steps.length<this.options.minSequenceLength)continue;let t=r.steps.join(` → `);n.push({id:e(),type:`missing-workflow-step`,confidence:.6,description:`Repeated workflow detected: ${t}`,metadata:{steps:r.steps,tenantId:r.tenantId,occurrences:r.count},evidence:[{type:`sequence`,description:`sequential-calls`,data:{steps:r.steps,count:r.count}}]})}return n}};export{n as IntentDetector};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{e,n as t,t as n}from"./types/stages.mjs";import"./types/axes.mjs";import"./types/signals.mjs";import"./types/milestones.mjs";import{o as r,r as i}from"./utils/formatters.mjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(e){return e.Sketch=`Sketch`,e.Prototype=`Prototype`,e.Mvp=`MVP`,e.V1=`V1`,e.Ecosystem=`Ecosystem`,e})({}),function(e){return e.Solo=`Solo`,e.TinyTeam=`TinyTeam`,e.FunctionalOrg=`FunctionalOrg`,e.MultiTeam=`MultiTeam`,e.Bureaucratic=`Bureaucratic`,e}({}),function(e){return e.Bootstrapped=`Bootstrapped`,e.PreSeed=`PreSeed`,e.Seed=`Seed`,e.SeriesAorB=`SeriesAorB`,e.LateStage=`LateStage`,e}({});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./stages.mjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./stages.mjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let e=function(e){return e[e.Exploration=0]=`Exploration`,e[e.ProblemSolutionFit=1]=`ProblemSolutionFit`,e[e.MvpEarlyTraction=2]=`MvpEarlyTraction`,e[e.ProductMarketFit=3]=`ProductMarketFit`,e[e.GrowthScaleUp=4]=`GrowthScaleUp`,e[e.ExpansionPlatform=5]=`ExpansionPlatform`,e[e.MaturityRenewal=6]=`MaturityRenewal`,e}({});const t=[e.Exploration,e.ProblemSolutionFit,e.MvpEarlyTraction,e.ProductMarketFit,e.GrowthScaleUp,e.ExpansionPlatform,e.MaturityRenewal],n={[e.Exploration]:{id:e.Exploration,order:0,slug:`exploration`,name:`Exploration / Ideation`,question:`Is there a problem worth my time?`,signals:[`20+ discovery interviews`,`Clear problem statement`,`Named ICP`],traps:[`Branding before discovery`,`Premature tooling decisions`],focusAreas:[`Customer discovery`,`Problem definition`,`Segment clarity`]},[e.ProblemSolutionFit]:{id:e.ProblemSolutionFit,order:1,slug:`problem-solution-fit`,name:`Problem–Solution Fit`,question:`Do people care enough about this solution?`,signals:[`Prototype reuse`,`Referral energy`,`Pre-pay interest`],traps:[`“Market is huge” without users`,`Skipping qualitative loops`],focusAreas:[`Solution hypothesis`,`Value messaging`,`Feedback capture`]},[e.MvpEarlyTraction]:{id:e.MvpEarlyTraction,order:2,slug:`mvp-early-traction`,name:`MVP & Early Traction`,question:`Can we get real usage and learn fast?`,signals:[`20–50 named active users`,`Weekly releases`,`Noisy feedback`],traps:[`Overbuilt infra for 10 users`,`Undefined retention metric`],focusAreas:[`Activation`,`Cohort tracking`,`Feedback rituals`]},[e.ProductMarketFit]:{id:e.ProductMarketFit,order:3,slug:`product-market-fit`,name:`Product–Market Fit`,question:`Is this pulling us forward?`,signals:[`Retention without heroics`,`Organic word-of-mouth`,`Value stories`],traps:[`Hero growth that does not scale`,`Ignoring churn signals`],focusAreas:[`Retention`,`Reliability`,`ICP clarity`]},[e.GrowthScaleUp]:{id:e.GrowthScaleUp,order:4,slug:`growth-scale-up`,name:`Growth / Scale-up`,question:`Can we grow this repeatably?`,signals:[`Predictable channels`,`Specialized hires`,`Unit economics on track`],traps:[`Paid spend masking retention gaps`,`Infra debt blocking launches`],focusAreas:[`Ops systems`,`Growth loops`,`Reliability engineering`]},[e.ExpansionPlatform]:{id:e.ExpansionPlatform,order:5,slug:`expansion-platform`,name:`Expansion / Platform`,question:`What is the next growth curve?`,signals:[`Stable core metrics`,`Partner/API demand`,`Ecosystem pull`],traps:[`Platform theater before wedge is solid`],focusAreas:[`Partnerships`,`APIs`,`New market validation`]},[e.MaturityRenewal]:{id:e.MaturityRenewal,order:6,slug:`maturity-renewal`,name:`Maturity / Renewal`,question:`Optimize, reinvent, or sunset?`,signals:[`Margin focus`,`Portfolio bets`,`Narrative refresh`],traps:[`Assuming past success is enough`],focusAreas:[`Cost optimization`,`Reinvention bets`,`Sunset planning`]}};export{e,n,t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,t}from"../types/stages.mjs";const n=e=>[`Product: ${e.product}`,`Company: ${e.company}`,`Capital: ${e.capital}`],r=t=>e[t].name;export{r as o,n as r};
|
package/dist/logging/index.d.mts
CHANGED
package/dist/logging/index.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import{context as e,trace as t}from"@opentelemetry/api";var n=class{constructor(e){this.serviceName=e}log(n,r,i={}){let a=t.getSpan(e.active()),o=a?.spanContext().traceId,s=a?.spanContext().spanId,c={timestamp:new Date().toISOString(),service:this.serviceName,level:n,message:r,traceId:o,spanId:s,...i};console.log(JSON.stringify(c))}debug(e,t){this.log(`debug`,e,t)}info(e,t){this.log(`info`,e,t)}warn(e,t){this.log(`warn`,e,t)}error(e,t){this.log(`error`,e,t)}};const r=new n(process.env.OTEL_SERVICE_NAME||`unknown-service`);export{n as Logger,r as logger};
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
import{context as e,trace as t}from"@opentelemetry/api";var n=class{constructor(e){this.serviceName=e}log(n,r,i={}){let a=t.getSpan(e.active()),o=a?.spanContext().traceId,s=a?.spanContext().spanId,c={timestamp:new Date().toISOString(),service:this.serviceName,level:n,message:r,traceId:o,spanId:s,...i};console.log(JSON.stringify(c))}debug(e,t){this.log(`debug`,e,t)}info(e,t){this.log(`info`,e,t)}warn(e,t){this.log(`warn`,e,t)}error(e,t){this.log(`error`,e,t)}};const r=new n(process.env.OTEL_SERVICE_NAME||`unknown-service`);export{n as Logger,r as logger};
|
package/dist/metrics/index.d.mts
CHANGED
|
@@ -13,5 +13,4 @@ declare const standardMetrics: {
|
|
|
13
13
|
workflowDuration: Histogram<_opentelemetry_api0.Attributes>;
|
|
14
14
|
};
|
|
15
15
|
//#endregion
|
|
16
|
-
export { createCounter, createHistogram, createUpDownCounter, getMeter, standardMetrics };
|
|
17
|
-
//# sourceMappingURL=index.d.mts.map
|
|
16
|
+
export { createCounter, createHistogram, createUpDownCounter, getMeter, standardMetrics };
|
package/dist/metrics/index.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import{metrics as e}from"@opentelemetry/api";function t(t=`@lssm/lib.observability`){return e.getMeter(t)}function n(e,n,r){return t(r).createCounter(e,{description:n})}function r(e,n,r){return t(r).createUpDownCounter(e,{description:n})}function i(e,n,r){return t(r).createHistogram(e,{description:n})}const a={httpRequests:n(`http_requests_total`,`Total HTTP requests`),httpDuration:i(`http_request_duration_seconds`,`HTTP request duration`),operationErrors:n(`operation_errors_total`,`Total operation errors`),workflowDuration:i(`workflow_duration_seconds`,`Workflow execution duration`)};export{n as createCounter,i as createHistogram,r as createUpDownCounter,t as getMeter,a as standardMetrics};
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
import{metrics as e}from"@opentelemetry/api";function t(t=`@lssm/lib.observability`){return e.getMeter(t)}function n(e,n,r){return t(r).createCounter(e,{description:n})}function r(e,n,r){return t(r).createUpDownCounter(e,{description:n})}function i(e,n,r){return t(r).createHistogram(e,{description:n})}const a={httpRequests:n(`http_requests_total`,`Total HTTP requests`),httpDuration:i(`http_request_duration_seconds`,`HTTP request duration`),operationErrors:n(`operation_errors_total`,`Total operation errors`),workflowDuration:i(`workflow_duration_seconds`,`Workflow execution duration`)};export{n as createCounter,i as createHistogram,r as createUpDownCounter,t as getMeter,a as 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 @@
|
|
|
1
|
+
import{IntentAggregator as e}from"../intent/aggregator.mjs";import{IntentDetector as t}from"../intent/detector.mjs";import{EventEmitter as n}from"node:events";var r=class{detector;aggregator;emitter;onIntent;onSnapshot;timer;previousMetrics;constructor(r={}){this.detector=r.detector??new t,this.aggregator=r.aggregator??new e,this.emitter=r.emitter??new n,this.onIntent=r.onIntent,this.onSnapshot=r.onSnapshot}ingest(e){this.aggregator.add(e)}on(e){this.emitter.on(`event`,e)}start(e=300*1e3){this.stop(),this.timer=setInterval(()=>{this.run()},e)}stop(){this.timer&&=(clearInterval(this.timer),void 0)}async run(){let e=this.aggregator.flush();if(this.emit({type:`telemetry.window`,payload:{sampleCount:e.sampleCount}}),this.onSnapshot&&await this.onSnapshot(e),!e.sampleCount)return;let t=this.detector.detectFromMetrics(e.metrics,this.previousMetrics),n=this.detector.detectSequentialIntents(e.sequences);this.previousMetrics=e.metrics;let r=[...t,...n];for(let e of r)this.onIntent&&await this.onIntent(e),this.emit({type:`intent.detected`,payload:e})}emit(e){this.emitter.emit(`event`,e)}};export{r as EvolutionPipeline};
|
|
@@ -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 @@
|
|
|
1
|
+
import{createCounter as e,createHistogram as t,createUpDownCounter as n}from"../metrics/index.mjs";import{o as r}from"../lifecycle/dist/utils/formatters.mjs";import"../lifecycle/dist/index.mjs";import{EventEmitter as i}from"node:events";var a=class{assessmentCounter;confidenceHistogram;stageUpDownCounter;emitter;lowConfidenceThreshold;currentStageByTenant=new Map;constructor(r={}){let a=r.meterName??`@lssm/lib.lifecycle-kpi`;this.assessmentCounter=e(`lifecycle_assessments_total`,`Total lifecycle assessments`,a),this.confidenceHistogram=t(`lifecycle_assessment_confidence`,`Lifecycle assessment confidence distribution`,a),this.stageUpDownCounter=n(`lifecycle_stage_tenants`,`Current tenants per lifecycle stage`,a),this.emitter=r.emitter??new i,this.lowConfidenceThreshold=r.lowConfidenceThreshold??.4}recordAssessment(e,t){let n={stage:r(e.stage),tenantId:t};this.assessmentCounter.add(1,n),this.confidenceHistogram.record(e.confidence,n),this.ensureStageCounters(e.stage,t),this.emitter.emit(`event`,{type:`assessment.recorded`,payload:{tenantId:t,stage:e.stage}}),e.confidence<this.lowConfidenceThreshold&&this.emitter.emit(`event`,{type:`confidence.low`,payload:{tenantId:t,confidence:e.confidence}})}on(e){this.emitter.on(`event`,e)}ensureStageCounters(e,t){if(!t)return;let n=this.currentStageByTenant.get(t);n!==e&&(n!==void 0&&this.stageUpDownCounter.add(-1,{stage:r(n),tenantId:t}),this.stageUpDownCounter.add(1,{stage:r(e),tenantId:t}),this.currentStageByTenant.set(t,e),this.emitter.emit(`event`,{type:`stage.changed`,payload:{tenantId:t,previousStage:n,nextStage:e}}))}};export{a as LifecycleKpiPipeline};
|
package/dist/tracing/index.d.mts
CHANGED
|
@@ -5,5 +5,4 @@ declare function getTracer(name?: string): Tracer;
|
|
|
5
5
|
declare function traceAsync<T>(name: string, fn: (span: Span) => Promise<T>, tracerName?: string): Promise<T>;
|
|
6
6
|
declare function traceSync<T>(name: string, fn: (span: Span) => T, tracerName?: string): T;
|
|
7
7
|
//#endregion
|
|
8
|
-
export { getTracer, traceAsync, traceSync };
|
|
9
|
-
//# sourceMappingURL=index.d.mts.map
|
|
8
|
+
export { getTracer, traceAsync, traceSync };
|
package/dist/tracing/index.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import{SpanStatusCode as e,context as t,trace as n}from"@opentelemetry/api";function r(e=`@lssm/lib.observability`){return n.getTracer(e)}async function i(t,n,i){return r(i).startActiveSpan(t,async t=>{try{let r=await n(t);return t.setStatus({code:e.OK}),r}catch(n){throw t.recordException(n),t.setStatus({code:e.ERROR,message:n instanceof Error?n.message:String(n)}),n}finally{t.end()}})}function a(t,n,i){return r(i).startActiveSpan(t,t=>{try{let r=n(t);return t.setStatus({code:e.OK}),r}catch(n){throw t.recordException(n),t.setStatus({code:e.ERROR,message:n instanceof Error?n.message:String(n)}),n}finally{t.end()}})}export{r as getTracer,i as traceAsync,a as traceSync};
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
import{SpanStatusCode as e,context as t,trace as n}from"@opentelemetry/api";function r(e=`@lssm/lib.observability`){return n.getTracer(e)}async function i(t,n,i){return r(i).startActiveSpan(t,async t=>{try{let r=await n(t);return t.setStatus({code:e.OK}),r}catch(n){throw t.recordException(n),t.setStatus({code:e.ERROR,message:n instanceof Error?n.message:String(n)}),n}finally{t.end()}})}function a(t,n,i){return r(i).startActiveSpan(t,t=>{try{let r=n(t);return t.setStatus({code:e.OK}),r}catch(n){throw t.recordException(n),t.setStatus({code:e.ERROR,message:n instanceof Error?n.message:String(n)}),n}finally{t.end()}})}export{r as getTracer,i as traceAsync,a as traceSync};
|
|
@@ -1,5 +1,18 @@
|
|
|
1
|
+
import { TelemetrySample } from "../intent/aggregator.mjs";
|
|
2
|
+
|
|
1
3
|
//#region src/tracing/middleware.d.ts
|
|
2
|
-
|
|
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>;
|
|
3
17
|
//#endregion
|
|
4
|
-
export { createTracingMiddleware };
|
|
5
|
-
//# sourceMappingURL=middleware.d.mts.map
|
|
18
|
+
export { TracingMiddlewareOptions, createTracingMiddleware };
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import{traceAsync as e}from"./index.mjs";import{standardMetrics as t}from"../metrics/index.mjs";function n(){return async(
|
|
2
|
-
//# sourceMappingURL=middleware.mjs.map
|
|
1
|
+
import{traceAsync as e}from"./index.mjs";import{standardMetrics as t}from"../metrics/index.mjs";function n(n={}){return async(i,a)=>{let o=i.method,s=new URL(i.url).pathname;t.httpRequests.add(1,{method:o,path:s});let c=performance.now();return e(`HTTP ${o} ${s}`,async e=>{e.setAttribute(`http.method`,o),e.setAttribute(`http.url`,i.url);try{let l=await a();e.setAttribute(`http.status_code`,l.status);let u=(performance.now()-c)/1e3;return t.httpDuration.record(u,{method:o,path:s,status:l.status.toString()}),r({req:i,res:l,span:e,success:!0,durationMs:u*1e3,options:n}),l}catch(a){throw t.operationErrors.add(1,{method:o,path:s}),r({req:i,span:e,success:!1,durationMs:performance.now()-c,error:a,options:n}),a}})}}function r({req:e,res:t,span:n,success:r,durationMs:i,error:a,options:o}){if(!o.onSample||!o.resolveOperation)return;let s=o.resolveOperation({req:e,res:t});if(!s)return;let c={operation:s,durationMs:i,success:r,timestamp:new Date,errorCode:!r&&a instanceof Error?a.name:r?void 0:`unknown`,tenantId:o.tenantResolver?.(e),actorId:o.actorResolver?.(e),traceId:n.spanContext().traceId,metadata:{method:e.method,path:new URL(e.url).pathname,status:t?.status}};o.onSample(c)}export{n as createTracingMiddleware};
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lssm/lib.observability",
|
|
3
|
-
"version": "0.0.0-canary-
|
|
3
|
+
"version": "0.0.0-canary-20251206160926",
|
|
4
4
|
"main": "./dist/index.mjs",
|
|
5
5
|
"types": "./dist/index.d.mts",
|
|
6
6
|
"scripts": {
|
|
7
|
+
"publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
|
|
7
8
|
"build": "bun build:bundle && bun build:types",
|
|
8
9
|
"build:bundle": "tsdown",
|
|
9
10
|
"build:types": "tsc --noEmit",
|
|
@@ -12,22 +13,35 @@
|
|
|
12
13
|
"lint": "bun lint:fix",
|
|
13
14
|
"lint:fix": "eslint src --fix",
|
|
14
15
|
"lint:check": "eslint src",
|
|
15
|
-
"test": "
|
|
16
|
+
"test": "bun run"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@lssm/lib.lifecycle": "workspace:*"
|
|
16
20
|
},
|
|
17
21
|
"peerDependencies": {
|
|
18
22
|
"@opentelemetry/api": "*"
|
|
19
23
|
},
|
|
20
24
|
"devDependencies": {
|
|
21
|
-
"typescript": "^5.0.0"
|
|
22
|
-
"vitest": "^1.0.0"
|
|
25
|
+
"typescript": "^5.0.0"
|
|
23
26
|
},
|
|
24
27
|
"exports": {
|
|
25
28
|
".": "./dist/index.mjs",
|
|
29
|
+
"./anomaly/alert-manager": "./dist/anomaly/alert-manager.mjs",
|
|
30
|
+
"./anomaly/anomaly-detector": "./dist/anomaly/anomaly-detector.mjs",
|
|
31
|
+
"./anomaly/baseline-calculator": "./dist/anomaly/baseline-calculator.mjs",
|
|
32
|
+
"./anomaly/root-cause-analyzer": "./dist/anomaly/root-cause-analyzer.mjs",
|
|
33
|
+
"./intent/aggregator": "./dist/intent/aggregator.mjs",
|
|
34
|
+
"./intent/detector": "./dist/intent/detector.mjs",
|
|
26
35
|
"./logging": "./dist/logging/index.mjs",
|
|
27
36
|
"./metrics": "./dist/metrics/index.mjs",
|
|
37
|
+
"./pipeline/evolution-pipeline": "./dist/pipeline/evolution-pipeline.mjs",
|
|
38
|
+
"./pipeline/lifecycle-pipeline": "./dist/pipeline/lifecycle-pipeline.mjs",
|
|
28
39
|
"./tracing": "./dist/tracing/index.mjs",
|
|
29
40
|
"./tracing/middleware": "./dist/tracing/middleware.mjs",
|
|
30
41
|
"./*": "./*"
|
|
31
42
|
},
|
|
32
|
-
"module": "./dist/index.mjs"
|
|
43
|
+
"module": "./dist/index.mjs",
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
46
|
+
}
|
|
33
47
|
}
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
$ bun build:bundle && bun build:types
|
|
2
|
-
$ tsdown
|
|
3
|
-
[34mℹ[39m tsdown [2mv0.15.12[22m powered by rolldown [2mv1.0.0-beta.45[22m
|
|
4
|
-
[34mℹ[39m Using tsdown config: [4m/home/runner/work/contractspec/contractspec/packages/libs/observability/tsdown.config.js[24m
|
|
5
|
-
[34mℹ[39m entry: [34msrc/index.ts, src/logging/index.ts, src/metrics/index.ts, src/tracing/index.ts, src/tracing/middleware.ts[39m
|
|
6
|
-
[34mℹ[39m target: [34mesnext[39m
|
|
7
|
-
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
8
|
-
[34mℹ[39m Build start
|
|
9
|
-
[34mℹ[39m [2mdist/[22m[1mmetrics/index.mjs[22m [2m0.73 kB[22m [2m│ gzip: 0.36 kB[22m
|
|
10
|
-
[34mℹ[39m [2mdist/[22m[1mtracing/index.mjs[22m [2m0.71 kB[22m [2m│ gzip: 0.34 kB[22m
|
|
11
|
-
[34mℹ[39m [2mdist/[22m[1mtracing/middleware.mjs[22m [2m0.65 kB[22m [2m│ gzip: 0.39 kB[22m
|
|
12
|
-
[34mℹ[39m [2mdist/[22m[1mlogging/index.mjs[22m [2m0.59 kB[22m [2m│ gzip: 0.38 kB[22m
|
|
13
|
-
[34mℹ[39m [2mdist/[22m[1mindex.mjs[22m [2m0.54 kB[22m [2m│ gzip: 0.24 kB[22m
|
|
14
|
-
[34mℹ[39m [2mdist/[22mtracing/index.mjs.map [2m2.34 kB[22m [2m│ gzip: 0.77 kB[22m
|
|
15
|
-
[34mℹ[39m [2mdist/[22mlogging/index.mjs.map [2m2.10 kB[22m [2m│ gzip: 0.85 kB[22m
|
|
16
|
-
[34mℹ[39m [2mdist/[22mmetrics/index.mjs.map [2m1.87 kB[22m [2m│ gzip: 0.68 kB[22m
|
|
17
|
-
[34mℹ[39m [2mdist/[22mtracing/middleware.mjs.map [2m1.75 kB[22m [2m│ gzip: 0.80 kB[22m
|
|
18
|
-
[34mℹ[39m [2mdist/[22mmetrics/index.d.mts.map [2m0.42 kB[22m [2m│ gzip: 0.26 kB[22m
|
|
19
|
-
[34mℹ[39m [2mdist/[22mlogging/index.d.mts.map [2m0.36 kB[22m [2m│ gzip: 0.24 kB[22m
|
|
20
|
-
[34mℹ[39m [2mdist/[22mtracing/index.d.mts.map [2m0.33 kB[22m [2m│ gzip: 0.23 kB[22m
|
|
21
|
-
[34mℹ[39m [2mdist/[22mtracing/middleware.d.mts.map [2m0.17 kB[22m [2m│ gzip: 0.15 kB[22m
|
|
22
|
-
[34mℹ[39m [2mdist/[22m[32m[1mmetrics/index.d.mts[22m[39m [2m0.94 kB[22m [2m│ gzip: 0.34 kB[22m
|
|
23
|
-
[34mℹ[39m [2mdist/[22m[32m[1mlogging/index.d.mts[22m[39m [2m0.66 kB[22m [2m│ gzip: 0.31 kB[22m
|
|
24
|
-
[34mℹ[39m [2mdist/[22m[32m[1mindex.d.mts[22m[39m [2m0.53 kB[22m [2m│ gzip: 0.22 kB[22m
|
|
25
|
-
[34mℹ[39m [2mdist/[22m[32m[1mtracing/index.d.mts[22m[39m [2m0.43 kB[22m [2m│ gzip: 0.23 kB[22m
|
|
26
|
-
[34mℹ[39m [2mdist/[22m[32m[1mtracing/middleware.d.mts[22m[39m [2m0.24 kB[22m [2m│ gzip: 0.17 kB[22m
|
|
27
|
-
[34mℹ[39m 18 files, total: 15.38 kB
|
|
28
|
-
[32m✔[39m Build complete in [32m35694ms[39m
|
|
29
|
-
$ tsc --noEmit
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/logging/index.ts"],"sourcesContent":[],"mappings":";KAEY,QAAA;AAAA,UAEK,QAAA,CAFG;EAEH,KAAA,EACR,QADgB;EAMZ,OAAA,EAAM,MAAA;EA0Ba,CAAA,GAAA,EAAA,MAAA,CAAA,EAAA,OAAA;;AAQD,cAlClB,MAAA,CAkCkB;EAIC,iBAAA,WAAA;EAAM,WAAA,CAAA,WAAA,EAAA,MAAA;EAKzB,QAAA,GAEZ;gCAnB+B;+BAID;+BAIA;gCAIC;;cAKnB,QAAM"}
|