@hasna/logs 0.3.10 → 0.3.12
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/dist/cli/index.js +4 -4
- package/dist/index-2sbhn1ye.js +1241 -0
- package/dist/index-t97ttm0a.js +543 -0
- package/dist/index-ww5ggfv3.js +90 -0
- package/dist/mcp/index.js +16 -9
- package/dist/query-7jwj05er.js +15 -0
- package/dist/server/index.js +3 -3
- package/package.json +1 -1
- package/src/lib/ingest.ts +5 -1
- package/src/lib/query.ts +23 -3
- package/src/mcp/index.ts +14 -6
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
getLogContext,
|
|
4
|
+
getLogContextFromId,
|
|
5
|
+
searchLogs,
|
|
6
|
+
tailLogs
|
|
7
|
+
} from "./index-ww5ggfv3.js";
|
|
8
|
+
import"./index-997bkzr2.js";
|
|
9
|
+
import"./index-re3ntm60.js";
|
|
10
|
+
export {
|
|
11
|
+
tailLogs,
|
|
12
|
+
searchLogs,
|
|
13
|
+
getLogContextFromId,
|
|
14
|
+
getLogContext
|
|
15
|
+
};
|
package/dist/server/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
setPageAuth,
|
|
7
7
|
setRetentionPolicy,
|
|
8
8
|
startScheduler
|
|
9
|
-
} from "../index-
|
|
9
|
+
} from "../index-2sbhn1ye.js";
|
|
10
10
|
import {
|
|
11
11
|
getHealth
|
|
12
12
|
} from "../index-xjn8gam3.js";
|
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
updateAlertRule,
|
|
32
32
|
updateIssueStatus,
|
|
33
33
|
updateProject
|
|
34
|
-
} from "../index-
|
|
34
|
+
} from "../index-t97ttm0a.js";
|
|
35
35
|
import {
|
|
36
36
|
createJob,
|
|
37
37
|
deleteJob,
|
|
@@ -42,7 +42,7 @@ import {
|
|
|
42
42
|
getLogContext,
|
|
43
43
|
searchLogs,
|
|
44
44
|
tailLogs
|
|
45
|
-
} from "../index-
|
|
45
|
+
} from "../index-ww5ggfv3.js";
|
|
46
46
|
import {
|
|
47
47
|
countLogs
|
|
48
48
|
} from "../index-edn08m6f.js";
|
package/package.json
CHANGED
package/src/lib/ingest.ts
CHANGED
|
@@ -37,7 +37,11 @@ export function ingestLog(db: Database, entry: LogEntry): LogRow {
|
|
|
37
37
|
return row
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
export function ingestBatch(db: Database, entries: LogEntry[]): LogRow[] {
|
|
40
|
+
export function ingestBatch(db: Database, entries: LogEntry[], sharedTraceId?: string | null): LogRow[] {
|
|
41
|
+
// Apply shared trace_id to entries that don't have their own
|
|
42
|
+
if (sharedTraceId) {
|
|
43
|
+
entries = entries.map(e => e.trace_id ? e : { ...e, trace_id: sharedTraceId })
|
|
44
|
+
}
|
|
41
45
|
const insert = db.prepare(`
|
|
42
46
|
INSERT INTO logs (project_id, page_id, level, source, service, message, trace_id, session_id, agent, url, stack_trace, metadata)
|
|
43
47
|
VALUES ($project_id, $page_id, $level, $source, $service, $message, $trace_id, $session_id, $agent, $url, $stack_trace, $metadata)
|
package/src/lib/query.ts
CHANGED
|
@@ -56,9 +56,29 @@ export function getLogContext(db: Database, traceId: string): LogRow[] {
|
|
|
56
56
|
.all({ $t: traceId }) as LogRow[]
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
export function getLogContextFromId(db: Database, logId: string): LogRow[] {
|
|
59
|
+
export function getLogContextFromId(db: Database, logId: string, window = 0): LogRow[] {
|
|
60
60
|
const log = db.prepare("SELECT * FROM logs WHERE id = $id").get({ $id: logId }) as LogRow | null
|
|
61
61
|
if (!log) return []
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
|
|
63
|
+
// Get trace context (or just the log itself if no trace)
|
|
64
|
+
const trace: LogRow[] = log.trace_id ? getLogContext(db, log.trace_id) : [log]
|
|
65
|
+
|
|
66
|
+
if (window <= 0) return trace
|
|
67
|
+
|
|
68
|
+
// Fetch N rows before and after the target log's timestamp
|
|
69
|
+
const before = db.prepare(
|
|
70
|
+
`SELECT * FROM logs WHERE id != $id AND timestamp <= $ts ORDER BY timestamp DESC LIMIT $n`
|
|
71
|
+
).all({ $id: logId, $ts: log.timestamp, $n: window }) as LogRow[]
|
|
72
|
+
|
|
73
|
+
const after = db.prepare(
|
|
74
|
+
`SELECT * FROM logs WHERE id != $id AND timestamp > $ts ORDER BY timestamp ASC LIMIT $n`
|
|
75
|
+
).all({ $id: logId, $ts: log.timestamp, $n: window }) as LogRow[]
|
|
76
|
+
|
|
77
|
+
// Merge: before (oldest first) + trace + after, deduplicate by id
|
|
78
|
+
const seen = new Set<string>()
|
|
79
|
+
const merged: LogRow[] = []
|
|
80
|
+
for (const row of [...before.reverse(), ...trace, ...after]) {
|
|
81
|
+
if (!seen.has(row.id)) { seen.add(row.id); merged.push(row) }
|
|
82
|
+
}
|
|
83
|
+
return merged.sort((a, b) => a.timestamp < b.timestamp ? -1 : a.timestamp > b.timestamp ? 1 : 0)
|
|
64
84
|
}
|
package/src/mcp/index.ts
CHANGED
|
@@ -123,9 +123,15 @@ server.tool("log_push_batch", {
|
|
|
123
123
|
project_id: z.string().optional(), service: z.string().optional(),
|
|
124
124
|
trace_id: z.string().optional(), metadata: z.record(z.unknown()).optional(),
|
|
125
125
|
})),
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
trace_id: z.string().optional().describe("Shared trace_id applied to all entries that don't have their own trace_id"),
|
|
127
|
+
project_id: z.string().optional().describe("Shared project_id applied to all entries (individual entry project_id takes precedence)"),
|
|
128
|
+
}, ({ entries, trace_id, project_id }) => {
|
|
129
|
+
const mapped = entries.map(e => ({
|
|
130
|
+
...e,
|
|
131
|
+
project_id: rp(e.project_id ?? project_id),
|
|
132
|
+
}))
|
|
133
|
+
const rows = ingestBatch(db, mapped, trace_id)
|
|
134
|
+
return { content: [{ type: "text", text: `Logged ${rows.length} entries${trace_id ? ` (trace: ${trace_id})` : ''}` }] }
|
|
129
135
|
})
|
|
130
136
|
|
|
131
137
|
server.tool("log_search", {
|
|
@@ -185,9 +191,11 @@ server.tool("log_context", {
|
|
|
185
191
|
}))
|
|
186
192
|
|
|
187
193
|
server.tool("log_context_from_id", {
|
|
188
|
-
log_id: z.string(),
|
|
189
|
-
|
|
190
|
-
|
|
194
|
+
log_id: z.string(),
|
|
195
|
+
brief: z.boolean().optional(),
|
|
196
|
+
window: z.number().int().min(0).optional().describe("Return N logs before and after the target log's timestamp (in addition to trace context)"),
|
|
197
|
+
}, ({ log_id, brief, window }) => ({
|
|
198
|
+
content: [{ type: "text", text: JSON.stringify(applyBrief(getLogContextFromId(db, log_id, window ?? 0), brief !== false)) }]
|
|
191
199
|
}))
|
|
192
200
|
|
|
193
201
|
server.tool("log_export", {
|