Skip to content

Commit fc6e3b6

Browse files
author
bcode
committed
feat(bcode-laminar): wire LMNR_PARENT_SPAN_CONTEXT env into startTurnSpan
When LMNR_PARENT_SPAN_CONTEXT is set in the process env, every 'turn' span the plugin opens is parented under the given Laminar span context (via the parentSpanContext arg startTurnSpan already accepts). Used by external evaluation harnesses that spawn bcode as a subprocess and want the agent's traces to nest under their own evaluation span — one trace per task, judge + agent siblings — instead of producing a separate root trace per bcode process. Format is the JSON serialization of a LaminarSpanContext (the lmnr Python SDK exposes Laminar.serialize_span_context() which returns exactly this shape; the JS-side parseLaminarSpanContext in span.ts already accepts snake_case and camelCase keys). Default behavior (env unset) is unchanged: bcode opens a fresh root turn span per chat.message event as before. Read once at plugin init via closure; one process is one parent for our intended use case (eval harness spawns bcode per task).
1 parent dc2c603 commit fc6e3b6

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

packages/bcode-laminar/src/plugin.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ export const LaminarPlugin: Plugin = ({ client }) => {
3434
process.env.LMNR_GRPC_PORT,
3535
baseUrl === "https://api.lmnr.ai" ? DEFAULT_GRPC_PORT_LMNR : DEFAULT_GRPC_PORT_GENERIC,
3636
)
37+
// When set, every "turn" span this plugin starts is parented under the
38+
// given Laminar span context. Used by external evaluation harnesses that
39+
// spawn bcode as a subprocess and want the agent's traces to nest under
40+
// their own evaluation span (one trace per task, judge + agent siblings).
41+
// Format: JSON serialization of LaminarSpanContext (snake_case or camelCase
42+
// keys both accepted by parseLaminarSpanContext in span.ts).
43+
const parentSpanContext = process.env.LMNR_PARENT_SPAN_CONTEXT
3744

3845
const log = (level: "debug" | "info" | "warn" | "error", message: string) => {
3946
client.app
@@ -118,6 +125,7 @@ export const LaminarPlugin: Plugin = ({ client }) => {
118125
const span = startTurnSpan({
119126
name: "turn",
120127
sessionId: sessionID,
128+
parentSpanContext,
121129
input: {
122130
sessionID,
123131
agent,

0 commit comments

Comments
 (0)