Skip to content

Commit 1b18379

Browse files
authored
Merge pull request #79 from browser-use/alex/v4-bcode-laminar-trace-spans
diag(TEMP): stderr trace span IDs through chat.message + session.idle
2 parents 5d9f2cb + 1b58d8b commit 1b18379

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

‎packages/bcode-laminar/src/plugin.ts‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,23 @@ export const LaminarPlugin: Plugin = ({ client }) => {
127127
const sessionId = event.properties.sessionID
128128
const span = sessionCurrentTurnSpan[sessionId]
129129
if (span) {
130+
const sid = span.spanContext().spanId
131+
process.stderr.write(`[bcode-laminar] session.idle: ending turn span ${sid} session=${sessionId}\n`)
130132
span.end()
131133
delete sessionCurrentTurnSpan[sessionId]
134+
const start = Date.now()
135+
try {
136+
await processor.forceFlush()
137+
process.stderr.write(`[bcode-laminar] session.idle: forceFlush done in ${Date.now() - start}ms\n`)
138+
} catch (err) {
139+
process.stderr.write(
140+
`[bcode-laminar] session.idle: forceFlush threw after ${Date.now() - start}ms: ${(err as Error).message}\n`,
141+
)
142+
}
143+
} else {
144+
process.stderr.write(`[bcode-laminar] session.idle: no turn span for session=${sessionId}\n`)
145+
await processor.forceFlush()
132146
}
133-
await processor.forceFlush()
134147
break
135148
}
136149
case "server.instance.disposed": {
@@ -143,7 +156,9 @@ export const LaminarPlugin: Plugin = ({ client }) => {
143156
// which the sync `shutdown` hook's `processor.forceFlush()` is a
144157
// no-op and turn spans are silently dropped. The sync hook is now
145158
// the single drain point; this handler just ends spans.
146-
for (const [sessionId, span] of Object.entries(sessionCurrentTurnSpan)) {
159+
const entries = Object.entries(sessionCurrentTurnSpan)
160+
process.stderr.write(`[bcode-laminar] server.instance.disposed: ending ${entries.length} open turn span(s)\n`)
161+
for (const [sessionId, span] of entries) {
147162
span.end()
148163
delete sessionCurrentTurnSpan[sessionId]
149164
}
@@ -178,7 +193,12 @@ export const LaminarPlugin: Plugin = ({ client }) => {
178193
const isSubagent = Object.values(subagentSessionIds).some((children) =>
179194
children.has(sessionID),
180195
)
181-
if (isSubagent || sessionCurrentTurnSpan[sessionID]) return
196+
if (isSubagent || sessionCurrentTurnSpan[sessionID]) {
197+
process.stderr.write(
198+
`[bcode-laminar] chat.message: skip (isSubagent=${isSubagent}, hasOpen=${!!sessionCurrentTurnSpan[sessionID]}) session=${sessionID}\n`,
199+
)
200+
return
201+
}
182202

183203
const span = startTurnSpan({
184204
name: "turn",
@@ -195,6 +215,9 @@ export const LaminarPlugin: Plugin = ({ client }) => {
195215
},
196216
})
197217
sessionCurrentTurnSpan[sessionID] = span
218+
process.stderr.write(
219+
`[bcode-laminar] chat.message: created turn span ${span.spanContext().spanId} session=${sessionID}\n`,
220+
)
198221
},
199222
})
200223
}

0 commit comments

Comments
 (0)