@ramarivera/coding-agent-langfuse 0.1.38 → 0.1.39

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.
Files changed (2) hide show
  1. package/dist/backfill.js +28 -0
  2. package/package.json +1 -1
package/dist/backfill.js CHANGED
@@ -19,6 +19,17 @@ const defaultMaxRequestBytes = 12 * 1024 * 1024;
19
19
  const defaultMaxFieldBytes = 512 * 1024;
20
20
  const defaultStatePath = join(homedir(), ".local/state/coding-agent-langfuse/backfill-v6.json");
21
21
  const currentHost = hostname();
22
+ function projectMetadata(cwd) {
23
+ if (!cwd)
24
+ return {};
25
+ const normalized = cwd.replace(/[\\/]+$/, "");
26
+ const projectName = normalized.split(/[\\/]+/).filter(Boolean).at(-1);
27
+ return {
28
+ projectPath: cwd,
29
+ projectName,
30
+ projectFolder: projectName,
31
+ };
32
+ }
22
33
  function usage() {
23
34
  return `Usage: coding-agent-langfuse-backfill [options]
24
35
 
@@ -1204,6 +1215,7 @@ function toOtlp(events, options = {}) {
1204
1215
  const traceStartMs = sortedEvents[0]?.startMs ?? Date.now();
1205
1216
  const traceEndMs = Math.max(...sortedEvents.map((event) => event.endMs ?? event.startMs + 1), traceStartMs + 1);
1206
1217
  const shouldEmitRootSpan = sortedEvents.some((event) => event.recordId === "session");
1218
+ const firstProject = projectMetadata(first.cwd);
1207
1219
  const rootAttributes = [
1208
1220
  attr("service.name", `agent.${first.agent}`),
1209
1221
  attr("deployment.environment", "local"),
@@ -1223,6 +1235,9 @@ function toOtlp(events, options = {}) {
1223
1235
  attr("langfuse.trace.metadata.machine", currentHost),
1224
1236
  attr("langfuse.trace.metadata.source_path", first.sourcePath),
1225
1237
  attr("langfuse.trace.metadata.cwd", first.cwd),
1238
+ attr("langfuse.trace.metadata.project_path", firstProject.projectPath),
1239
+ attr("langfuse.trace.metadata.project_name", firstProject.projectName),
1240
+ attr("langfuse.trace.metadata.project_folder", firstProject.projectFolder),
1226
1241
  attr("langfuse.observation.metadata.agent", first.agent),
1227
1242
  attr("langfuse.observation.metadata.host", currentHost),
1228
1243
  attr("langfuse.observation.metadata.machine", currentHost),
@@ -1230,8 +1245,14 @@ function toOtlp(events, options = {}) {
1230
1245
  attr("langfuse.observation.metadata.record_id", "session-root"),
1231
1246
  attr("langfuse.observation.metadata.source_path", first.sourcePath),
1232
1247
  attr("langfuse.observation.metadata.cwd", first.cwd),
1248
+ attr("langfuse.observation.metadata.project_path", firstProject.projectPath),
1249
+ attr("langfuse.observation.metadata.project_name", firstProject.projectName),
1250
+ attr("langfuse.observation.metadata.project_folder", firstProject.projectFolder),
1233
1251
  attr("source.path", first.sourcePath),
1234
1252
  attr("cwd", first.cwd),
1253
+ attr("project.path", firstProject.projectPath),
1254
+ attr("project.name", firstProject.projectName),
1255
+ attr("project.folder", firstProject.projectFolder),
1235
1256
  ].filter((item) => Boolean(item));
1236
1257
  const rootSpan = {
1237
1258
  traceId: traceId(first),
@@ -1251,6 +1272,7 @@ function toOtlp(events, options = {}) {
1251
1272
  const generation = isGenerationEvent(event);
1252
1273
  const usage = usageDetails(event.usage);
1253
1274
  const cost = costDetails(event.usage, modelName);
1275
+ const eventProject = projectMetadata(event.cwd);
1254
1276
  const costForLangfuse = cost === undefined
1255
1277
  ? undefined
1256
1278
  : {
@@ -1288,6 +1310,9 @@ function toOtlp(events, options = {}) {
1288
1310
  attr("langfuse.observation.metadata.record_id", event.recordId),
1289
1311
  attr("langfuse.observation.metadata.source_path", event.sourcePath),
1290
1312
  attr("langfuse.observation.metadata.cwd", event.cwd),
1313
+ attr("langfuse.observation.metadata.project_path", eventProject.projectPath),
1314
+ attr("langfuse.observation.metadata.project_name", eventProject.projectName),
1315
+ attr("langfuse.observation.metadata.project_folder", eventProject.projectFolder),
1291
1316
  attr("langfuse.observation.metadata.model", modelName ?? event.model),
1292
1317
  attr("langfuse.observation.metadata.provider", event.provider),
1293
1318
  attr("langfuse.observation.metadata.cost_source", cost?.source),
@@ -1295,6 +1320,9 @@ function toOtlp(events, options = {}) {
1295
1320
  attr("langfuse.observation.output", event.output),
1296
1321
  attr("source.path", event.sourcePath),
1297
1322
  attr("cwd", event.cwd),
1323
+ attr("project.path", eventProject.projectPath),
1324
+ attr("project.name", eventProject.projectName),
1325
+ attr("project.folder", eventProject.projectFolder),
1298
1326
  attr("role", event.role),
1299
1327
  attr("agent.model", event.model),
1300
1328
  attr("agent.provider", event.provider),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramarivera/coding-agent-langfuse",
3
- "version": "0.1.38",
3
+ "version": "0.1.39",
4
4
  "description": "Universal coding-agent Langfuse backfiller and live OTLP helpers",
5
5
  "type": "module",
6
6
  "license": "MIT",