Skip to content

Commit 729bf45

Browse files
fix(server): export activity publication spans through relay tracing
1 parent 88084b9 commit 729bf45

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

‎apps/server/src/relay/AgentAwarenessRelay.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
TurnItemId,
1616
} from "@t3tools/contracts";
1717
import { RelayAgentActivityState } from "@t3tools/contracts/relay";
18+
import { RelayClientTracer } from "@t3tools/shared/relayTracing";
1819
import * as DateTime from "effect/DateTime";
1920
import * as Deferred from "effect/Deferred";
2021
import * as Effect from "effect/Effect";
@@ -24,6 +25,7 @@ import * as Queue from "effect/Queue";
2425
import * as Ref from "effect/Ref";
2526
import * as Schema from "effect/Schema";
2627
import * as Stream from "effect/Stream";
28+
import * as Tracer from "effect/Tracer";
2729
import * as TestClock from "effect/testing/TestClock";
2830
import * as FetchHttpClient from "effect/http/FetchHttpClient";
2931

@@ -373,6 +375,29 @@ describe("AgentAwarenessRelay", () => {
373375
}),
374376
);
375377

378+
it.effect("exports the publication span through the relay tracer", () => {
379+
const relaySpans: string[] = [];
380+
const localSpans: string[] = [];
381+
const collectingTracer = (spans: string[]) =>
382+
Tracer.make({
383+
span: (options) => {
384+
spans.push(options.name);
385+
return new Tracer.NativeSpan(options);
386+
},
387+
});
388+
389+
return Effect.gen(function* () {
390+
const { relay, publications } = yield* makeTestRelay();
391+
yield* relay.publishThread(THREAD_ID);
392+
assert.equal(publications.length, 1);
393+
assert.include(relaySpans, "relay.agent_activity.publish");
394+
assert.notInclude(localSpans, "relay.agent_activity.publish");
395+
}).pipe(
396+
Effect.provideService(RelayClientTracer, Option.some(collectingTracer(relaySpans))),
397+
Effect.withTracer(collectingTracer(localSpans)),
398+
);
399+
});
400+
376401
it.effect("deduplicates state and republishes title changes", () =>
377402
Effect.gen(function* () {
378403
const { relay, currentShell, publications } = yield* makeTestRelay();

‎apps/server/src/relay/AgentAwarenessRelay.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ export const make = Effect.gen(function* () {
508508
ok: response.ok,
509509
deliveries: deliveryStats(response.deliveries),
510510
});
511-
}, withRelayClientTracing);
511+
});
512512

513513
// Per-thread shell read: this publish runs for every activity-relevant
514514
// domain event, so materializing the full shell here would make the cost
@@ -613,7 +613,7 @@ export const make = Effect.gen(function* () {
613613
projectId: snapshot.projectId,
614614
state: snapshot.state,
615615
reason: snapshot.reason,
616-
});
616+
}).pipe(withRelayClientTracing);
617617
publishConfirmDeadlines.delete(threadId);
618618
yield* Ref.update(publishedStateByThreadRef, (publishedStates) => {
619619
const nextPublishedStates = new Map(publishedStates);

0 commit comments

Comments
 (0)