Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): emit one managed agent trace tree (#2813)

Chad Hietala7a415bf00cd0
diff --git a/.changeset/single-agent-trace-tree.md b/.changeset/single-agent-trace-tree.md
new file mode 100644
index 000000000..4a242ed3d
--- /dev/null
+++ b/.changeset/single-agent-trace-tree.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Emit one framework-owned agent trace tree from managed OpenTelemetry runtimes. Legacy instrumentation keeps its existing span hierarchy, and authored AI SDK telemetry integrations continue to compose with eve's structural spans.
diff --git a/packages/eve/src/instrumentation/ai-sdk-telemetry.test.ts b/packages/eve/src/instrumentation/ai-sdk-telemetry.test.ts
index e99ea1698..2450a7fb0 100644
--- a/packages/eve/src/instrumentation/ai-sdk-telemetry.test.ts
+++ b/packages/eve/src/instrumentation/ai-sdk-telemetry.test.ts
@@ -56,9 +56,13 @@ describe("getRegisteredTelemetryIntegrations", () => {
const registered = getRegisteredTelemetryIntegrations();
const errorSafe = getRegisteredTelemetryIntegrations({ sanitizeEveOtelErrors: true });
+ const authoredOnly = getRegisteredTelemetryIntegrations({
+ excludeEveOtelIntegration: true,
+ });
expect(errorSafe).toHaveLength(2);
expect(errorSafe[0]).not.toBe(registered[0]);
expect(errorSafe[1]).toBe(authored);
+ expect(authoredOnly).toEqual([authored]);
});
});
diff --git a/packages/eve/src/instrumentation/ai-sdk-telemetry.ts b/packages/eve/src/instrumentation/ai-sdk-telemetry.ts
index 0e8b17cb4..43d1907a7 100644
--- a/packages/eve/src/instrumentation/ai-sdk-telemetry.ts
+++ b/packages/eve/src/instrumentation/ai-sdk-telemetry.ts
@@ -35,9 +35,14 @@ export function ensureOtelIntegration(): void {
* these forward or they stop receiving events.
*/
export function getRegisteredTelemetryIntegrations(options?: {
+ readonly excludeEveOtelIntegration?: boolean;
readonly sanitizeEveOtelErrors?: boolean;
}): readonly Telemetry[] {
- const integrations = globalThis.AI_SDK_TELEMETRY_INTEGRATIONS ?? [];
+ const registered = globalThis.AI_SDK_TELEMETRY_INTEGRATIONS ?? [];
+ const integrations =
+ options?.excludeEveOtelIntegration === true
+ ? registered.filter((integration) => integration !== eveOtelIntegration)
+ : registered;
if (options?.sanitizeEveOtelErrors !== true) return integrations;
let matched = false;
const sanitized = integrations.map((integration) => {
@@ -47,7 +52,7 @@ export function getRegisteredTelemetryIntegrations(options?: {
matched = true;
return errorSafeEveOtelIntegration;
});
- if (!matched && !warnedMissingEveOtelIntegration) {
+ if (!matched && options.excludeEveOtelIntegration !== true && !warnedMissingEveOtelIntegration) {
warnedMissingEveOtelIntegration = true;
log.warn("could not sanitize eve's AI SDK OpenTelemetry integration", {
reason:
diff --git a/packages/eve/src/instrumentation/runtime.test.ts b/packages/eve/src/instrumentation/runtime.test.ts
index 3d7e163e9..bd3bc40aa 100644
--- a/packages/eve/src/instrumentation/runtime.test.ts
+++ b/packages/eve/src/instrumentation/runtime.test.ts
@@ -151,6 +151,45 @@ describe("bindInstrumentationRuntime", () => {
expect(telemetry).toMatchObject({ recordInputs: false, recordOutputs: false });
});
+ it("uses one framework-owned span tree when the runtime owns agent spans", async () => {
+ const originalIntegrations = globalThis.AI_SDK_TELEMETRY_INTEGRATIONS;
+ const authoredIntegration = { onStart: vi.fn() };
+ globalThis.AI_SDK_TELEMETRY_INTEGRATIONS = [authoredIntegration];
+ const runtime = {
+ ...createRuntime({ capturesContent: true, publish: vi.fn() }),
+ ownsAgentSpans: true,
+ };
+ const instrumentation = bindInstrumentationRuntime(runtime, createContext(), boundSession);
+
+ try {
+ const result = await instrumentation?.prepareExecution().runStep(
+ {
+ environment: "test",
+ eveVersion: "0.0.0",
+ hasInput: true,
+ session: { sessionId: "session-1", state: {} as Record<string, unknown> },
+ },
+ async (scope) => ({
+ integrations: scope.prepareAttempt({
+ attemptIndex: 0,
+ stepIndex: 0,
+ turnId: "turn-1",
+ }).telemetry?.integrations,
+ session: scope.session,
+ }),
+ );
+
+ expect(result?.session.state?.["eve.harness.turnTrace"]).toBeUndefined();
+ expect(result?.integrations).toEqual([
+ expect.objectContaining({ onStart: expect.any(Function) }),
+ authoredIntegration,
+ ]);
+ expect(globalThis.AI_SDK_TELEMETRY_INTEGRATIONS).toEqual([authoredIntegration]);
+ } finally {
+ globalThis.AI_SDK_TELEMETRY_INTEGRATIONS = originalIntegrations;
+ }
+ });
+
it("isolates concurrent step decisions and audiences", async () => {
const ctx = createContext("private");
const runtime = createRuntime({ capturesContent: true, publish: vi.fn() });
diff --git a/packages/eve/src/instrumentation/runtime.ts b/packages/eve/src/instrumentation/runtime.ts
index d83e076c5..387411173 100644
--- a/packages/eve/src/instrumentation/runtime.ts
+++ b/packages/eve/src/instrumentation/runtime.ts
@@ -147,6 +147,7 @@ export interface InstrumentationRuntime {
readonly hooks: InstrumentationHooks;
readonly idGenerator?: AgentSpanIdGenerator;
readonly instrumentationProviders?: boolean;
+ readonly ownsAgentSpans?: boolean;
readonly prepareSessionTrace?: (
event: InstrumentationSessionStartedEvent,
) => Promise<InstrumentationTraceSeed>;
@@ -218,8 +219,10 @@ export function bindInstrumentationRuntime(
};
const captureExecutionRuntime = () => {
const otelSettings = runtime.otelSettings;
- if (otelSettings !== undefined) ensureOtelIntegration();
+ const ownsAgentSpans = runtime.ownsAgentSpans === true;
+ if (otelSettings !== undefined && !ownsAgentSpans) ensureOtelIntegration();
return {
+ ownsAgentSpans,
otelSettings,
runtimeContextResolvers: runtime.runtimeContextResolvers,
stepStartedRuntimeContextResolver: runtime.stepStartedRuntimeContextResolver,
@@ -268,7 +271,10 @@ export function bindInstrumentationRuntime(
const functionId = settings?.functionId ?? boundSession.agentName;
if (functionId) attributes["ai.telemetry.functionId"] = functionId;
let turnSpan =
- tracer !== undefined && decision?.action !== "drop" && input.hasInput
+ tracer !== undefined &&
+ !executionRuntime.ownsAgentSpans &&
+ decision?.action !== "drop" &&
+ input.hasInput
? tracer.startSpan("ai.eve.turn", { attributes })
: undefined;
const spanContext = turnSpan?.spanContext();
@@ -337,7 +343,13 @@ export function bindInstrumentationRuntime(
}
const sanitizeEveOtelErrors =
settings !== undefined && !(content.recordInputs && content.recordOutputs);
- const integrations = () => getRegisteredTelemetryIntegrations({ sanitizeEveOtelErrors });
+ const integrations = () =>
+ getRegisteredTelemetryIntegrations({
+ ...(executionRuntime.ownsAgentSpans
+ ? { excludeEveOtelIntegration: true }
+ : undefined),
+ sanitizeEveOtelErrors,
+ });
return {
functionId: settings?.functionId ?? boundSession.agentName,
includeRuntimeContext,
diff --git a/packages/eve/src/tracing/install-instrumentation-runtime.test.ts b/packages/eve/src/tracing/install-instrumentation-runtime.test.ts
index 477fb2cd4..4baeb61ae 100644
--- a/packages/eve/src/tracing/install-instrumentation-runtime.test.ts
+++ b/packages/eve/src/tracing/install-instrumentation-runtime.test.ts
@@ -71,6 +71,7 @@ describe("installInstrumentationRuntime", () => {
expect(forceFlush).toHaveBeenCalledOnce();
expect(providerFlush).toHaveBeenCalledOnce();
expect(runtime.instrumentationProviders).toBe(true);
+ expect(runtime.ownsAgentSpans).toBe(true);
expect(runtime.otelSettings).toEqual({
functionId: undefined,
recordInputs: true,
diff --git a/packages/eve/src/tracing/install-instrumentation-runtime.ts b/packages/eve/src/tracing/install-instrumentation-runtime.ts
index da23d7a2b..5c8351bcb 100644
--- a/packages/eve/src/tracing/install-instrumentation-runtime.ts
+++ b/packages/eve/src/tracing/install-instrumentation-runtime.ts
@@ -86,6 +86,7 @@ export function installInstrumentationRuntime(input: {
idGenerator: otelRuntime?.idGenerator ?? new AgentSpanIdGenerator(),
instrumentationProviders: input.instrumentationProviders,
otelSettings: input.collected.declared ? input.collected.settings : undefined,
+ ownsAgentSpans: otelRuntime !== undefined,
prepareSessionTrace,
prepareTurnTrace,
runtimeContextResolvers: input.runtimeContextResolvers,