@ramarivera/coding-agent-langfuse 0.1.25 → 0.1.26
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/backfill.js +28 -2
- package/package.json +1 -1
package/dist/backfill.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { execFileSync } from "node:child_process";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
import { existsSync, mkdirSync, renameSync, readdirSync, readFileSync, statSync, writeFileSync, } from "node:fs";
|
|
5
|
-
import { homedir } from "node:os";
|
|
5
|
+
import { hostname, homedir } from "node:os";
|
|
6
6
|
import { dirname, join } from "node:path";
|
|
7
7
|
const allAgents = ["claude", "codex", "grok", "opencode", "pi"];
|
|
8
8
|
const importIdentityVersion = "v8-cached-input-token-split";
|
|
@@ -16,6 +16,7 @@ const importIdentityVersions = {
|
|
|
16
16
|
const defaultEndpoint = "https://langfuse.ai.roxasroot.net/otel/v1/traces";
|
|
17
17
|
const deadRemoteEndpoint = "http://langfuse.ai.roxasroot.net:14318/v1/traces";
|
|
18
18
|
const defaultStatePath = join(homedir(), ".local/state/coding-agent-langfuse/backfill-v6.json");
|
|
19
|
+
const currentHost = hostname();
|
|
19
20
|
function usage() {
|
|
20
21
|
return `Usage: coding-agent-langfuse-backfill [options]
|
|
21
22
|
|
|
@@ -568,6 +569,7 @@ function claudeEvents(homeDir) {
|
|
|
568
569
|
return genericJsonlEvents("claude", files, "claude session");
|
|
569
570
|
}
|
|
570
571
|
function piEvents(homeDir) {
|
|
572
|
+
const seenMessageIds = new Set();
|
|
571
573
|
const files = [
|
|
572
574
|
...listFiles(join(homeDir, ".pi/agent/sessions"), (path) => path.endsWith(".jsonl")),
|
|
573
575
|
...listFiles(join(homeDir, ".pi/agent"), (path) => path.endsWith("run-history.jsonl")),
|
|
@@ -596,7 +598,14 @@ function piEvents(homeDir) {
|
|
|
596
598
|
const message = asRecord(row.message);
|
|
597
599
|
const usage = normalizeUsage(message.usage);
|
|
598
600
|
const role = asString(message.role);
|
|
599
|
-
const
|
|
601
|
+
const explicitMessageId = asString(row.id);
|
|
602
|
+
const messageId = explicitMessageId ?? `message-${stableId(path)}-${index}`;
|
|
603
|
+
const dedupeKey = explicitMessageId === undefined
|
|
604
|
+
? `${path}:${messageId}`
|
|
605
|
+
: explicitMessageId;
|
|
606
|
+
if (seenMessageIds.has(dedupeKey))
|
|
607
|
+
continue;
|
|
608
|
+
seenMessageIds.add(dedupeKey);
|
|
600
609
|
const toolCallId = asString(message.toolCallId);
|
|
601
610
|
events.push({
|
|
602
611
|
agent: "pi",
|
|
@@ -1142,16 +1151,24 @@ function toOtlp(events) {
|
|
|
1142
1151
|
attr("session.id", first.sessionId),
|
|
1143
1152
|
attr("langfuse.observation.type", "span"),
|
|
1144
1153
|
attr("agent.name", first.agent),
|
|
1154
|
+
attr("host.name", currentHost),
|
|
1145
1155
|
attr("agent.session_id", first.sessionId),
|
|
1146
1156
|
attr("agent.record_id", "session-root"),
|
|
1147
1157
|
attr("agent.event_count", sortedEvents.length),
|
|
1148
1158
|
attr("langfuse.trace.metadata.agent", first.agent),
|
|
1159
|
+
attr("langfuse.trace.metadata.host", currentHost),
|
|
1160
|
+
attr("langfuse.trace.metadata.machine", currentHost),
|
|
1149
1161
|
attr("langfuse.trace.metadata.source_path", first.sourcePath),
|
|
1150
1162
|
attr("langfuse.trace.metadata.cwd", first.cwd),
|
|
1151
1163
|
attr("langfuse.trace.input", firstInputEvent?.input),
|
|
1152
1164
|
attr("langfuse.trace.output", lastOutputEvent?.output),
|
|
1153
1165
|
attr("langfuse.observation.metadata.agent", first.agent),
|
|
1166
|
+
attr("langfuse.observation.metadata.host", currentHost),
|
|
1167
|
+
attr("langfuse.observation.metadata.machine", currentHost),
|
|
1168
|
+
attr("langfuse.observation.metadata.session_id", first.sessionId),
|
|
1154
1169
|
attr("langfuse.observation.metadata.record_id", "session-root"),
|
|
1170
|
+
attr("langfuse.observation.metadata.source_path", first.sourcePath),
|
|
1171
|
+
attr("langfuse.observation.metadata.cwd", first.cwd),
|
|
1155
1172
|
attr("source.path", first.sourcePath),
|
|
1156
1173
|
attr("cwd", first.cwd),
|
|
1157
1174
|
].filter((item) => Boolean(item));
|
|
@@ -1198,16 +1215,25 @@ function toOtlp(events) {
|
|
|
1198
1215
|
attr("gen_ai.usage.total_tokens", usage?.total),
|
|
1199
1216
|
attr("gen_ai.usage.cost", cost?.total),
|
|
1200
1217
|
attr("agent.name", event.agent),
|
|
1218
|
+
attr("host.name", currentHost),
|
|
1201
1219
|
attr("agent.session_id", event.sessionId),
|
|
1202
1220
|
attr("agent.record_id", event.recordId),
|
|
1203
1221
|
attr("agent.original_start_time", new Date(event.startMs).toISOString()),
|
|
1204
1222
|
attr("agent.original_end_time", event.endMs === undefined ? undefined : new Date(event.endMs).toISOString()),
|
|
1205
1223
|
attr("langfuse.trace.metadata.agent", event.agent),
|
|
1224
|
+
attr("langfuse.trace.metadata.host", currentHost),
|
|
1225
|
+
attr("langfuse.trace.metadata.machine", currentHost),
|
|
1206
1226
|
attr("langfuse.trace.metadata.source_path", event.sourcePath),
|
|
1227
|
+
attr("langfuse.trace.metadata.cwd", event.cwd),
|
|
1207
1228
|
attr("langfuse.trace.metadata.model", event.model),
|
|
1208
1229
|
attr("langfuse.trace.metadata.provider", event.provider),
|
|
1209
1230
|
attr("langfuse.observation.metadata.agent", event.agent),
|
|
1231
|
+
attr("langfuse.observation.metadata.host", currentHost),
|
|
1232
|
+
attr("langfuse.observation.metadata.machine", currentHost),
|
|
1233
|
+
attr("langfuse.observation.metadata.session_id", event.sessionId),
|
|
1210
1234
|
attr("langfuse.observation.metadata.record_id", event.recordId),
|
|
1235
|
+
attr("langfuse.observation.metadata.source_path", event.sourcePath),
|
|
1236
|
+
attr("langfuse.observation.metadata.cwd", event.cwd),
|
|
1211
1237
|
attr("langfuse.observation.metadata.model", modelName ?? event.model),
|
|
1212
1238
|
attr("langfuse.observation.metadata.provider", event.provider),
|
|
1213
1239
|
attr("langfuse.observation.metadata.cost_source", cost?.source),
|