@nahisaho/katashiro-observability 2.0.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.
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Observability Types
3
+ *
4
+ * @requirement REQ-OBS-001, REQ-OBS-002
5
+ * @design DES-KATASHIRO-003-OBS §3.1
6
+ */
7
+ /**
8
+ * スパンステータス
9
+ */
10
+ export type SpanStatus = {
11
+ code: 'OK';
12
+ } | {
13
+ code: 'ERROR';
14
+ message: string;
15
+ };
16
+ /**
17
+ * 属性値型
18
+ */
19
+ export type AttributeValue = string | number | boolean | string[] | number[];
20
+ /**
21
+ * スパンイベント
22
+ */
23
+ export interface SpanEvent {
24
+ name: string;
25
+ timestamp: string;
26
+ attributes?: Record<string, AttributeValue>;
27
+ }
28
+ /**
29
+ * スパンリンク
30
+ */
31
+ export interface SpanLink {
32
+ traceId: string;
33
+ spanId: string;
34
+ attributes?: Record<string, AttributeValue>;
35
+ }
36
+ /**
37
+ * トレースレコード
38
+ */
39
+ export interface TraceRecord {
40
+ /** トレースID(UUID) */
41
+ traceId: string;
42
+ /** スパンID(UUID) */
43
+ spanId: string;
44
+ /** 親スパンID */
45
+ parentSpanId?: string;
46
+ /** 操作名 */
47
+ name: string;
48
+ /** 開始時刻(ISO8601) */
49
+ startTime: string;
50
+ /** 終了時刻(ISO8601) */
51
+ endTime?: string;
52
+ /** 期間(ミリ秒) */
53
+ durationMs?: number;
54
+ /** ステータス */
55
+ status: SpanStatus;
56
+ /** 属性 */
57
+ attributes: Record<string, AttributeValue>;
58
+ /** イベント */
59
+ events: SpanEvent[];
60
+ /** リンク */
61
+ links: SpanLink[];
62
+ }
63
+ /**
64
+ * トレースコンテキスト
65
+ */
66
+ export interface TraceContext {
67
+ traceId: string;
68
+ currentSpan: Span;
69
+ }
70
+ /**
71
+ * スパンインターフェース
72
+ */
73
+ export interface Span {
74
+ readonly traceId: string;
75
+ readonly spanId: string;
76
+ setAttribute(key: string, value: AttributeValue): this;
77
+ setAttributes(attributes: Record<string, AttributeValue>): this;
78
+ setStatus(status: SpanStatus): this;
79
+ addEvent(name: string, attributes?: Record<string, AttributeValue>): this;
80
+ recordException(error: Error): this;
81
+ end(): void;
82
+ toRecord(): TraceRecord;
83
+ }
84
+ /**
85
+ * スパン作成オプション
86
+ */
87
+ export interface SpanOptions {
88
+ attributes?: Record<string, AttributeValue>;
89
+ links?: SpanLink[];
90
+ recordInput?: boolean;
91
+ recordOutput?: boolean;
92
+ }
93
+ /**
94
+ * トレーサー設定
95
+ */
96
+ export interface TracerConfig {
97
+ serviceName: string;
98
+ serviceVersion: string;
99
+ environment?: string;
100
+ /** サンプリングレート (0.0-1.0) */
101
+ sampling?: number;
102
+ exporters?: TraceExporter[];
103
+ }
104
+ /**
105
+ * トレースエクスポーターインターフェース
106
+ */
107
+ export interface TraceExporter {
108
+ name: string;
109
+ export(record: TraceRecord): Promise<void>;
110
+ shutdown?(): Promise<void>;
111
+ }
112
+ /**
113
+ * メトリクスエクスポーターインターフェース
114
+ */
115
+ export interface MetricsExporter {
116
+ name: string;
117
+ export(snapshot: MetricsSnapshot): Promise<void>;
118
+ shutdown?(): Promise<void>;
119
+ }
120
+ /**
121
+ * ヒストグラムデータ
122
+ */
123
+ export interface HistogramData {
124
+ count: number;
125
+ sum: number;
126
+ min: number;
127
+ max: number;
128
+ avg: number;
129
+ p50: number;
130
+ p90: number;
131
+ p99: number;
132
+ buckets: Record<string, number>;
133
+ }
134
+ /**
135
+ * メトリクススナップショット
136
+ */
137
+ export interface MetricsSnapshot {
138
+ timestamp: string;
139
+ counters: Record<string, number>;
140
+ gauges: Record<string, number>;
141
+ histograms: Record<string, HistogramData>;
142
+ }
143
+ /**
144
+ * ヘルスチェック結果
145
+ */
146
+ export interface HealthCheckResult {
147
+ status: 'healthy' | 'degraded' | 'unhealthy';
148
+ checks: Record<string, {
149
+ status: 'pass' | 'warn' | 'fail';
150
+ message?: string;
151
+ latencyMs?: number;
152
+ }>;
153
+ timestamp: string;
154
+ }
155
+ /**
156
+ * ヘルスチェック対象
157
+ */
158
+ export interface HealthCheck {
159
+ name: string;
160
+ check(): Promise<{
161
+ status: 'pass' | 'warn' | 'fail';
162
+ message?: string;
163
+ }>;
164
+ timeout?: number;
165
+ }
166
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7E;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC;AAE7E;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;CAC7C;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;CAC7C;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,mBAAmB;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,kBAAkB;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,aAAa;IACb,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU;IACV,IAAI,EAAE,MAAM,CAAC;IACb,oBAAoB;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,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AU,GAAG,WAAW,CAAC;IAC7C,MAAM,EAAE,MAAM,CACZ,MAAM,EACN;QACE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;QACjC,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CACF,CAAC;IACF,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,IAAI,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACzE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
package/dist/types.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Observability Types
3
+ *
4
+ * @requirement REQ-OBS-001, REQ-OBS-002
5
+ * @design DES-KATASHIRO-003-OBS §3.1
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@nahisaho/katashiro-observability",
3
+ "version": "2.0.0",
4
+ "description": "KATASHIRO Observability - トレーシング・メトリクス・ロギング",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "keywords": [
19
+ "katashiro",
20
+ "observability",
21
+ "tracing",
22
+ "metrics",
23
+ "logging"
24
+ ],
25
+ "author": "nahisaho",
26
+ "license": "MIT",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/nahisaho/katashiro.git",
30
+ "directory": "packages/observability"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "dependencies": {
36
+ "@nahisaho/katashiro-core": "2.0.0"
37
+ },
38
+ "devDependencies": {
39
+ "typescript": "^5.3.0"
40
+ },
41
+ "peerDependencies": {
42
+ "@opentelemetry/api": "^1.7.0",
43
+ "langfuse": "^3.0.0"
44
+ },
45
+ "peerDependenciesMeta": {
46
+ "@opentelemetry/api": {
47
+ "optional": true
48
+ },
49
+ "langfuse": {
50
+ "optional": true
51
+ }
52
+ },
53
+ "scripts": {
54
+ "build": "tsc",
55
+ "clean": "rm -rf dist",
56
+ "test": "vitest run",
57
+ "test:watch": "vitest"
58
+ }
59
+ }