@obsunified/collector 2.0.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.
- package/LICENSE +21 -0
- package/README.md +60 -0
- package/dist/auth.d.ts +2 -0
- package/dist/auth.js +9 -0
- package/dist/auth.js.map +1 -0
- package/dist/chunk-UGWDOGGH.js +319 -0
- package/dist/chunk-UGWDOGGH.js.map +1 -0
- package/dist/chunk-XKQTVIRE.js +671 -0
- package/dist/chunk-XKQTVIRE.js.map +1 -0
- package/dist/index.d.ts +1197 -0
- package/dist/index.js +17707 -0
- package/dist/index.js.map +1 -0
- package/dist/ingest-auth-HFVO1zIp.d.ts +165 -0
- package/dist/openai-FJYOQ7WO.js +384 -0
- package/dist/openai-FJYOQ7WO.js.map +1 -0
- package/package.json +73 -0
- package/src/ai-parity/ai-parity.acceptance.test.ts +449 -0
- package/src/analyses/derive.ts +642 -0
- package/src/analyses/index.ts +50 -0
- package/src/analyses/investigations.ts +277 -0
- package/src/analyses/tier0.ts +568 -0
- package/src/auth/dashboard-auth.ts +269 -0
- package/src/auth/ingest-auth.ts +147 -0
- package/src/durable-objects/tail-hub.test.ts +32 -0
- package/src/durable-objects/tail-hub.ts +158 -0
- package/src/framework/collector.ts +467 -0
- package/src/framework/env.ts +90 -0
- package/src/framework/logger.ts +81 -0
- package/src/index.ts +211 -0
- package/src/lib/action-aggregates.ts +1031 -0
- package/src/lib/action-identity.ts +106 -0
- package/src/lib/actions-store.ts +397 -0
- package/src/lib/ai-pricing.ts +80 -0
- package/src/lib/ai-store/calls.ts +148 -0
- package/src/lib/ai-store/evaluations.test.ts +47 -0
- package/src/lib/ai-store/evaluations.ts +125 -0
- package/src/lib/ai-store/helpers.ts +37 -0
- package/src/lib/ai-store/retention.ts +17 -0
- package/src/lib/ai-store/sessions.ts +277 -0
- package/src/lib/ai-store/spans.ts +109 -0
- package/src/lib/ai-store/types.ts +112 -0
- package/src/lib/ai-store.ts +76 -0
- package/src/lib/alerts-store.ts +458 -0
- package/src/lib/analyses-runner.ts +439 -0
- package/src/lib/analyses-store.test.ts +243 -0
- package/src/lib/analyses-store.ts +454 -0
- package/src/lib/ask.test.ts +302 -0
- package/src/lib/ask.ts +390 -0
- package/src/lib/blob-store-s3.ts +213 -0
- package/src/lib/blob-store.ts +366 -0
- package/src/lib/eval-cases-store.test.ts +171 -0
- package/src/lib/eval-cases-store.ts +1033 -0
- package/src/lib/evidence-references.test.ts +10 -0
- package/src/lib/evidence-references.ts +684 -0
- package/src/lib/hash.ts +26 -0
- package/src/lib/identity-index/action-lookups.ts +805 -0
- package/src/lib/identity-index/constants.ts +1 -0
- package/src/lib/identity-index/key-lookups.ts +199 -0
- package/src/lib/identity-index/mappers.ts +349 -0
- package/src/lib/identity-index/types.ts +196 -0
- package/src/lib/identity-index/user-lookup.ts +137 -0
- package/src/lib/identity-index.test.ts +624 -0
- package/src/lib/identity-index.ts +85 -0
- package/src/lib/json.ts +39 -0
- package/src/lib/llm.ts +263 -0
- package/src/lib/logs-store.ts +188 -0
- package/src/lib/metrics-store.test.ts +189 -0
- package/src/lib/metrics-store.ts +312 -0
- package/src/lib/narrate-gate.test.ts +260 -0
- package/src/lib/narrate-gate.ts +253 -0
- package/src/lib/openai.test.ts +300 -0
- package/src/lib/openai.ts +512 -0
- package/src/lib/otlp.ts +212 -0
- package/src/lib/parse-pprof.test.ts +64 -0
- package/src/lib/parse-pprof.ts +184 -0
- package/src/lib/payload-capture.ts +22 -0
- package/src/lib/projects-store.ts +207 -0
- package/src/lib/propagation-metric.test.ts +196 -0
- package/src/lib/propagation-metric.ts +175 -0
- package/src/lib/sql-db-dialect.test.ts +22 -0
- package/src/lib/sql-db-postgres.ts +229 -0
- package/src/lib/sql-db.ts +166 -0
- package/src/lib/stage6.test.ts +216 -0
- package/src/lib/store/export.ts +65 -0
- package/src/lib/store/helpers.ts +367 -0
- package/src/lib/store/ingest.ts +68 -0
- package/src/lib/store/issues.ts +158 -0
- package/src/lib/store/overview.ts +127 -0
- package/src/lib/store/retention.ts +10 -0
- package/src/lib/store/service-map.ts +384 -0
- package/src/lib/store/trace-detail.bench.ts +76 -0
- package/src/lib/store/trace-detail.test.ts +410 -0
- package/src/lib/store/trace-detail.ts +427 -0
- package/src/lib/store/trace-queries.test.ts +29 -0
- package/src/lib/store/trace-queries.ts +89 -0
- package/src/lib/store-overview.test.ts +77 -0
- package/src/lib/store.ts +96 -0
- package/src/lib/tail-publisher.ts +64 -0
- package/src/lib/test-utils/mem-sql-db.test.ts +93 -0
- package/src/lib/test-utils/mem-sql-db.ts +86 -0
- package/src/lib/ua-parser.ts +61 -0
- package/src/lib/usage-store.ts +567 -0
- package/src/migrations/001_telemetry_spans.sql +28 -0
- package/src/migrations/002_usage_events.sql +24 -0
- package/src/migrations/003_usage_analytics_columns.sql +13 -0
- package/src/migrations/004_logs.sql +19 -0
- package/src/migrations/005_ai_calls.sql +25 -0
- package/src/migrations/006_user_profiles.sql +11 -0
- package/src/migrations/007_session_replay_metadata.sql +10 -0
- package/src/migrations/008_session_replay_storage_bytes.sql +1 -0
- package/src/migrations/009_projects_and_keys.sql +22 -0
- package/src/migrations/010_signal_project_id.sql +15 -0
- package/src/migrations/011_default_project_seed.sql +3 -0
- package/src/migrations/012_alert_rules.sql +17 -0
- package/src/migrations/013_alert_evaluations.sql +13 -0
- package/src/migrations/014_alert_state.sql +9 -0
- package/src/migrations/015_metrics.sql +58 -0
- package/src/migrations/016_metrics_exp_histogram_summary.sql +5 -0
- package/src/migrations/017_span_dropped_counts.sql +11 -0
- package/src/migrations/018_log_flags.sql +8 -0
- package/src/migrations/019_ai_span_payloads.sql +30 -0
- package/src/migrations/020_ai_span_evaluations.sql +33 -0
- package/src/migrations/021_ai_span_session.sql +13 -0
- package/src/migrations/022_span_log_session_id.sql +13 -0
- package/src/migrations/023_service_map_indexes.sql +32 -0
- package/src/migrations/024_analysis_results.sql +49 -0
- package/src/migrations/025_stage6_autopinning_alerts.sql +38 -0
- package/src/migrations/026_obs_dashboard_project_seed.sql +18 -0
- package/src/migrations/027_identity_propagation.sql +50 -0
- package/src/migrations/028_profile_blobs.sql +57 -0
- package/src/migrations/029_telemetry_sdk_name.sql +20 -0
- package/src/migrations/030_analysis_claim.sql +18 -0
- package/src/migrations/031_agent_action_graph.sql +154 -0
- package/src/migrations/032_payload_capture_flags.sql +8 -0
- package/src/migrations/033_eval_cases.sql +52 -0
- package/src/migrations/034_eval_case_results.sql +23 -0
- package/src/migrations/035_metric_exemplars.sql +33 -0
- package/src/migrations/036_trace_instrumentation_gaps.sql +19 -0
- package/src/migrations/037_eval_runs.sql +37 -0
- package/src/migrations/038_tool_call_evidence.sql +11 -0
- package/src/migrations/039_drop_trace_instrumentation_gaps.sql +11 -0
- package/src/migrations/040_evidence_retrieval_refs.sql +50 -0
- package/src/migrations-postgres/001_telemetry_spans.sql +33 -0
- package/src/migrations-postgres/002_usage_events.sql +24 -0
- package/src/migrations-postgres/003_usage_analytics_columns.sql +13 -0
- package/src/migrations-postgres/004_logs.sql +19 -0
- package/src/migrations-postgres/005_ai_calls.sql +25 -0
- package/src/migrations-postgres/006_user_profiles.sql +11 -0
- package/src/migrations-postgres/007_session_replay_metadata.sql +10 -0
- package/src/migrations-postgres/008_session_replay_storage_bytes.sql +2 -0
- package/src/migrations-postgres/009_projects_and_keys.sql +25 -0
- package/src/migrations-postgres/010_signal_project_id.sql +18 -0
- package/src/migrations-postgres/011_default_project_seed.sql +5 -0
- package/src/migrations-postgres/012_alert_rules.sql +17 -0
- package/src/migrations-postgres/013_alert_evaluations.sql +13 -0
- package/src/migrations-postgres/014_alert_state.sql +9 -0
- package/src/migrations-postgres/015_metrics.sql +47 -0
- package/src/migrations-postgres/016_metrics_exp_histogram_summary.sql +1 -0
- package/src/migrations-postgres/017_span_dropped_counts.sql +4 -0
- package/src/migrations-postgres/018_log_flags.sql +2 -0
- package/src/migrations-postgres/019_ai_span_payloads.sql +18 -0
- package/src/migrations-postgres/020_ai_span_evaluations.sql +21 -0
- package/src/migrations-postgres/021_ai_span_session.sql +7 -0
- package/src/migrations-postgres/022_span_log_session_id.sql +7 -0
- package/src/migrations-postgres/023_service_map_indexes.sql +9 -0
- package/src/migrations-postgres/024_analysis_results.sql +41 -0
- package/src/migrations-postgres/025_stage6_autopinning_alerts.sql +17 -0
- package/src/migrations-postgres/026_obs_dashboard_project_seed.sql +14 -0
- package/src/migrations-postgres/027_identity_propagation.sql +27 -0
- package/src/migrations-postgres/028_profile_blobs.sql +48 -0
- package/src/migrations-postgres/029_telemetry_sdk_name.sql +5 -0
- package/src/migrations-postgres/030_analysis_claim.sql +5 -0
- package/src/migrations-postgres/031_agent_action_graph.sql +190 -0
- package/src/migrations-postgres/032_payload_capture_flags.sql +8 -0
- package/src/migrations-postgres/033_eval_cases.sql +55 -0
- package/src/migrations-postgres/034_eval_case_results.sql +26 -0
- package/src/migrations-postgres/035_metric_exemplars.sql +31 -0
- package/src/migrations-postgres/036_trace_instrumentation_gaps.sql +19 -0
- package/src/migrations-postgres/037_eval_runs.sql +40 -0
- package/src/migrations-postgres/038_tool_call_evidence.sql +11 -0
- package/src/migrations-postgres/039_drop_trace_instrumentation_gaps.sql +11 -0
- package/src/migrations-postgres/040_evidence_retrieval_refs.sql +47 -0
- package/src/migrations-postgres/README.md +40 -0
- package/src/otlp/acceptance.test.ts +373 -0
- package/src/otlp/decode/body.ts +127 -0
- package/src/otlp/decode/logs.ts +96 -0
- package/src/otlp/decode/metrics.ts +402 -0
- package/src/otlp/decode/traces.ts +92 -0
- package/src/otlp/decode/values.ts +150 -0
- package/src/otlp/decode.test.ts +800 -0
- package/src/otlp/decode.ts +11 -0
- package/src/otlp/gen/opentelemetry/proto/collector/logs/v1/logs_service_pb.ts +132 -0
- package/src/otlp/gen/opentelemetry/proto/collector/metrics/v1/metrics_service_pb.ts +158 -0
- package/src/otlp/gen/opentelemetry/proto/collector/trace/v1/trace_service_pb.ts +158 -0
- package/src/otlp/gen/opentelemetry/proto/common/v1/common_pb.ts +289 -0
- package/src/otlp/gen/opentelemetry/proto/logs/v1/logs_pb.ts +397 -0
- package/src/otlp/gen/opentelemetry/proto/metrics/v1/metrics_pb.ts +1329 -0
- package/src/otlp/gen/opentelemetry/proto/resource/v1/resource_pb.ts +86 -0
- package/src/otlp/gen/opentelemetry/proto/trace/v1/trace_pb.ts +710 -0
- package/src/otlp/response.test.ts +158 -0
- package/src/otlp/response.ts +129 -0
- package/src/plugins/_context.ts +15 -0
- package/src/plugins/action-graph-processor/enrichers.ts +45 -0
- package/src/plugins/action-graph-processor/redaction.ts +84 -0
- package/src/plugins/action-graph-processor.test.ts +1023 -0
- package/src/plugins/action-graph-processor.ts +1172 -0
- package/src/plugins/action-routes.test.ts +716 -0
- package/src/plugins/action-routes.ts +343 -0
- package/src/plugins/ai-receiver.ts +254 -0
- package/src/plugins/ai-span-payloads-processor.test.ts +90 -0
- package/src/plugins/ai-span-payloads-processor.ts +180 -0
- package/src/plugins/alerts-evaluator.test.ts +91 -0
- package/src/plugins/alerts-evaluator.ts +328 -0
- package/src/plugins/alerts-routes.ts +101 -0
- package/src/plugins/analyses-routes.ts +138 -0
- package/src/plugins/ask-routes.ts +182 -0
- package/src/plugins/bot-filter.ts +19 -0
- package/src/plugins/connected-routes/manifest.ts +531 -0
- package/src/plugins/connected-routes.test.ts +1791 -0
- package/src/plugins/connected-routes.ts +1103 -0
- package/src/plugins/dashboard-routes.ts +41 -0
- package/src/plugins/default-span-enrichment.ts +92 -0
- package/src/plugins/eval-cases-routes.test.ts +391 -0
- package/src/plugins/eval-cases-routes.ts +529 -0
- package/src/plugins/evidence-retrieval-routes.benchmark.test.ts +245 -0
- package/src/plugins/evidence-retrieval-routes.test.ts +932 -0
- package/src/plugins/evidence-retrieval-routes.ts +2179 -0
- package/src/plugins/gen-ai-normalizer.test.ts +680 -0
- package/src/plugins/gen-ai-normalizer.ts +302 -0
- package/src/plugins/identity-receiver.ts +96 -0
- package/src/plugins/issue-enrichment.ts +132 -0
- package/src/plugins/issue-insights.ts +81 -0
- package/src/plugins/logs-receiver.ts +160 -0
- package/src/plugins/metrics-receiver.ts +91 -0
- package/src/plugins/onboarding-routes.ts +54 -0
- package/src/plugins/otlp-receiver.ts +124 -0
- package/src/plugins/platform-routes.ts +165 -0
- package/src/plugins/profile-routes.ts +468 -0
- package/src/plugins/projects-routes.ts +92 -0
- package/src/plugins/query-routes.ts +220 -0
- package/src/plugins/redaction-processor.ts +132 -0
- package/src/plugins/replay-query-routes.test.ts +38 -0
- package/src/plugins/replay-query-routes.ts +199 -0
- package/src/plugins/replay-receiver.ts +81 -0
- package/src/plugins/tail-routes.test.ts +47 -0
- package/src/plugins/tail-routes.ts +42 -0
- package/src/plugins/timeline-routes.ts +244 -0
- package/src/plugins/ua-enrichment.ts +27 -0
- package/src/plugins/usage-normalization.ts +46 -0
- package/src/plugins/usage-privacy.ts +55 -0
- package/src/plugins/usage-query-routes.ts +102 -0
- package/src/plugins/usage-receiver.ts +129 -0
- package/src/plugins/users-query-routes.ts +78 -0
- package/src/plugins/utm-enrichment.ts +36 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AISpanRecord,
|
|
3
|
+
AISpansOverviewOptions,
|
|
4
|
+
AISpansOverviewResponse,
|
|
5
|
+
JsonValue,
|
|
6
|
+
} from "@obsunified/types";
|
|
7
|
+
import { parseJsonRecord } from "../json";
|
|
8
|
+
import { dialectFor, type SqlDb } from "../sql-db";
|
|
9
|
+
import { enrichCost } from "./helpers";
|
|
10
|
+
import type { AISpanRow } from "./types";
|
|
11
|
+
import { clampInt } from "./types";
|
|
12
|
+
|
|
13
|
+
export async function getAISpansOverview(
|
|
14
|
+
db: SqlDb,
|
|
15
|
+
options: AISpansOverviewOptions,
|
|
16
|
+
): Promise<AISpansOverviewResponse> {
|
|
17
|
+
if (!options.projectId)
|
|
18
|
+
throw new Error("AIStore.getAISpans: projectId is required");
|
|
19
|
+
const dialect = dialectFor(db);
|
|
20
|
+
const hours = clampInt(options.hours, 1, 720, 24);
|
|
21
|
+
const limit = clampInt(options.limit, 1, 1000, 100);
|
|
22
|
+
|
|
23
|
+
let sql = `
|
|
24
|
+
SELECT
|
|
25
|
+
s.trace_id AS trace_id,
|
|
26
|
+
s.span_id AS span_id,
|
|
27
|
+
s.parent_span_id AS parent_span_id,
|
|
28
|
+
s.service_name AS service_name,
|
|
29
|
+
s.span_name AS span_name,
|
|
30
|
+
s.status_code AS status_code,
|
|
31
|
+
s.status_message AS status_message,
|
|
32
|
+
s.start_time AS start_time,
|
|
33
|
+
s.end_time AS end_time,
|
|
34
|
+
s.duration_ms AS duration_ms,
|
|
35
|
+
s.attributes_json AS attributes_json,
|
|
36
|
+
p.span_kind AS span_kind,
|
|
37
|
+
p.input_json AS input_json,
|
|
38
|
+
p.output_json AS output_json
|
|
39
|
+
FROM ai_span_payloads p
|
|
40
|
+
INNER JOIN telemetry_spans s
|
|
41
|
+
ON s.trace_id = p.trace_id AND s.span_id = p.span_id
|
|
42
|
+
WHERE p.project_id = ?
|
|
43
|
+
AND p.received_at >= ${dialect.sinceHours("?")}
|
|
44
|
+
`;
|
|
45
|
+
const params: unknown[] = [options.projectId, hours];
|
|
46
|
+
|
|
47
|
+
if (options.kind) {
|
|
48
|
+
sql += ` AND p.span_kind = ?`;
|
|
49
|
+
params.push(options.kind);
|
|
50
|
+
}
|
|
51
|
+
if (options.service) {
|
|
52
|
+
sql += ` AND s.service_name = ?`;
|
|
53
|
+
params.push(options.service);
|
|
54
|
+
}
|
|
55
|
+
if (options.traceId) {
|
|
56
|
+
sql += ` AND s.trace_id = ?`;
|
|
57
|
+
params.push(options.traceId);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
sql += ` ORDER BY s.start_time DESC LIMIT ?`;
|
|
61
|
+
params.push(limit);
|
|
62
|
+
|
|
63
|
+
const results = await db
|
|
64
|
+
.prepare(sql)
|
|
65
|
+
.bind(...params)
|
|
66
|
+
.all<AISpanRow>();
|
|
67
|
+
|
|
68
|
+
const spans: AISpanRecord[] = (results.results || []).map((row) => {
|
|
69
|
+
const attrs = parseJsonRecord(row.attributes_json) as Record<
|
|
70
|
+
string,
|
|
71
|
+
JsonValue
|
|
72
|
+
>;
|
|
73
|
+
enrichCost(attrs);
|
|
74
|
+
return {
|
|
75
|
+
traceId: row.trace_id,
|
|
76
|
+
spanId: row.span_id,
|
|
77
|
+
parentSpanId: row.parent_span_id,
|
|
78
|
+
serviceName: row.service_name,
|
|
79
|
+
spanName: row.span_name,
|
|
80
|
+
spanKind: row.span_kind,
|
|
81
|
+
statusCode: row.status_code ?? 0,
|
|
82
|
+
statusMessage: row.status_message,
|
|
83
|
+
startTime: row.start_time,
|
|
84
|
+
endTime: row.end_time ?? row.start_time,
|
|
85
|
+
durationMs: row.duration_ms ?? 0,
|
|
86
|
+
attributes: attrs,
|
|
87
|
+
inputJson: row.input_json,
|
|
88
|
+
outputJson: row.output_json,
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const byKind: Record<string, number> = {};
|
|
93
|
+
let errorSpans = 0;
|
|
94
|
+
for (const span of spans) {
|
|
95
|
+
byKind[span.spanKind] = (byKind[span.spanKind] ?? 0) + 1;
|
|
96
|
+
if (span.statusCode === 2) errorSpans++;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
spans,
|
|
101
|
+
summary: {
|
|
102
|
+
totalSpans: spans.length,
|
|
103
|
+
byKind,
|
|
104
|
+
errorSpans,
|
|
105
|
+
},
|
|
106
|
+
windowHours: hours,
|
|
107
|
+
timestamp: new Date().toISOString(),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { AICallRecord, AIEvaluationSource } from "@obsunified/types";
|
|
2
|
+
|
|
3
|
+
export interface IngestEvaluation {
|
|
4
|
+
projectId: string;
|
|
5
|
+
evaluationId: string;
|
|
6
|
+
traceId: string;
|
|
7
|
+
spanId: string;
|
|
8
|
+
name: string;
|
|
9
|
+
score: number | null;
|
|
10
|
+
label: string | null;
|
|
11
|
+
explanation: string | null;
|
|
12
|
+
source: AIEvaluationSource;
|
|
13
|
+
metadataJson: string | null;
|
|
14
|
+
createdAt: string;
|
|
15
|
+
expiresAt: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Clamp an integer to a safe range */
|
|
19
|
+
export const clampInt = (
|
|
20
|
+
value: unknown,
|
|
21
|
+
min: number,
|
|
22
|
+
max: number,
|
|
23
|
+
fallback: number,
|
|
24
|
+
): number => {
|
|
25
|
+
const n = typeof value === "number" ? value : parseInt(String(value), 10);
|
|
26
|
+
if (!Number.isFinite(n)) return fallback;
|
|
27
|
+
return Math.max(min, Math.min(max, n));
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export interface AICallRow {
|
|
31
|
+
project_id?: string;
|
|
32
|
+
call_id: string;
|
|
33
|
+
trace_id: string | null;
|
|
34
|
+
span_id: string | null;
|
|
35
|
+
service_name: string | null;
|
|
36
|
+
model_name: string;
|
|
37
|
+
provider: string;
|
|
38
|
+
call_type: AICallRecord["callType"];
|
|
39
|
+
request_json: string | null;
|
|
40
|
+
response_json: string | null;
|
|
41
|
+
prompt_tokens: number | null;
|
|
42
|
+
completion_tokens: number | null;
|
|
43
|
+
total_cost_usd: number | null;
|
|
44
|
+
latency_ms: number | null;
|
|
45
|
+
is_error: number;
|
|
46
|
+
error_message: string | null;
|
|
47
|
+
occurred_at: string;
|
|
48
|
+
received_at: string;
|
|
49
|
+
expires_at: string;
|
|
50
|
+
session_id: string | null;
|
|
51
|
+
interaction_id: string | null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface AICallSummaryRow {
|
|
55
|
+
totalCalls?: number;
|
|
56
|
+
totalCostUsd?: number;
|
|
57
|
+
totalPromptTokens?: number;
|
|
58
|
+
totalCompletionTokens?: number;
|
|
59
|
+
errorCalls?: number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface AISpanRow {
|
|
63
|
+
trace_id: string;
|
|
64
|
+
span_id: string;
|
|
65
|
+
parent_span_id: string | null;
|
|
66
|
+
service_name: string | null;
|
|
67
|
+
span_name: string;
|
|
68
|
+
span_kind: string;
|
|
69
|
+
status_code: number | null;
|
|
70
|
+
status_message: string | null;
|
|
71
|
+
start_time: string;
|
|
72
|
+
end_time: string | null;
|
|
73
|
+
duration_ms: number | null;
|
|
74
|
+
attributes_json: string | null;
|
|
75
|
+
input_json: string | null;
|
|
76
|
+
output_json: string | null;
|
|
77
|
+
user_id?: string | null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface AISessionRow {
|
|
81
|
+
session_id: string;
|
|
82
|
+
user_id: string | null;
|
|
83
|
+
span_count: number | null;
|
|
84
|
+
llm_span_count: number | null;
|
|
85
|
+
error_count: number | null;
|
|
86
|
+
prompt_tokens: number | null;
|
|
87
|
+
completion_tokens: number | null;
|
|
88
|
+
cost_usd: number | null;
|
|
89
|
+
first_span_at: string;
|
|
90
|
+
last_span_at: string;
|
|
91
|
+
trace_count: number | null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface AISessionPreviewRow {
|
|
95
|
+
session_id: string;
|
|
96
|
+
input_json: string | null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface AIEvaluationRow {
|
|
100
|
+
evaluation_id: string;
|
|
101
|
+
project_id: string;
|
|
102
|
+
trace_id: string;
|
|
103
|
+
span_id: string;
|
|
104
|
+
name: string;
|
|
105
|
+
score: number | null;
|
|
106
|
+
label: string | null;
|
|
107
|
+
explanation: string | null;
|
|
108
|
+
source: AIEvaluationSource;
|
|
109
|
+
metadata_json: string | null;
|
|
110
|
+
created_at: string;
|
|
111
|
+
expires_at: string;
|
|
112
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AICallRecord,
|
|
3
|
+
AICallsOverviewOptions,
|
|
4
|
+
AICallsOverviewResponse,
|
|
5
|
+
AIEvaluationsListOptions,
|
|
6
|
+
AIEvaluationsListResponse,
|
|
7
|
+
AISessionDetailResponse,
|
|
8
|
+
AISessionsListOptions,
|
|
9
|
+
AISessionsListResponse,
|
|
10
|
+
AISpansOverviewOptions,
|
|
11
|
+
AISpansOverviewResponse,
|
|
12
|
+
} from "@obsunified/types";
|
|
13
|
+
import { getAICallsOverview, ingestAICallBatch } from "./ai-store/calls";
|
|
14
|
+
import {
|
|
15
|
+
getAIEvaluation,
|
|
16
|
+
ingestAIEvaluations,
|
|
17
|
+
listAIEvaluations,
|
|
18
|
+
} from "./ai-store/evaluations";
|
|
19
|
+
import { purgeExpiredAIData } from "./ai-store/retention";
|
|
20
|
+
import { getAISessionDetail, listAISessions } from "./ai-store/sessions";
|
|
21
|
+
import { getAISpansOverview } from "./ai-store/spans";
|
|
22
|
+
import type { IngestEvaluation } from "./ai-store/types";
|
|
23
|
+
import type { SqlDb } from "./sql-db";
|
|
24
|
+
|
|
25
|
+
export type { IngestEvaluation } from "./ai-store/types";
|
|
26
|
+
|
|
27
|
+
export class AIStore {
|
|
28
|
+
constructor(private readonly db: SqlDb) {}
|
|
29
|
+
|
|
30
|
+
async ingestBatch(calls: AICallRecord[]): Promise<void> {
|
|
31
|
+
return ingestAICallBatch(this.db, calls);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async getAICalls(
|
|
35
|
+
options: AICallsOverviewOptions,
|
|
36
|
+
): Promise<AICallsOverviewResponse> {
|
|
37
|
+
return getAICallsOverview(this.db, options);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async purgeExpired(): Promise<number> {
|
|
41
|
+
return purgeExpiredAIData(this.db);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async getAISpans(
|
|
45
|
+
options: AISpansOverviewOptions,
|
|
46
|
+
): Promise<AISpansOverviewResponse> {
|
|
47
|
+
return getAISpansOverview(this.db, options);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async listSessions(
|
|
51
|
+
options: AISessionsListOptions,
|
|
52
|
+
): Promise<AISessionsListResponse> {
|
|
53
|
+
return listAISessions(this.db, options);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async getSession(
|
|
57
|
+
projectId: string,
|
|
58
|
+
sessionId: string,
|
|
59
|
+
): Promise<AISessionDetailResponse> {
|
|
60
|
+
return getAISessionDetail(this.db, projectId, sessionId);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async ingestEvaluations(evaluations: IngestEvaluation[]): Promise<void> {
|
|
64
|
+
return ingestAIEvaluations(this.db, evaluations);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async listEvaluations(
|
|
68
|
+
options: AIEvaluationsListOptions,
|
|
69
|
+
): Promise<AIEvaluationsListResponse> {
|
|
70
|
+
return listAIEvaluations(this.db, options);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async getEvaluation(projectId: string, evaluationId: string) {
|
|
74
|
+
return getAIEvaluation(this.db, projectId, evaluationId);
|
|
75
|
+
}
|
|
76
|
+
}
|