Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

Fix trace sampling for new Vercel projects (#4540)

Chad Hietala30c88ee0095e
diff --git a/.changeset/new-project-trace-sampling.md b/.changeset/new-project-trace-sampling.md
new file mode 100644
index 000000000..08d54ed69
--- /dev/null
+++ b/.changeset/new-project-trace-sampling.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Configure 100% trace sampling when eve creates a Vercel project during `eve link`, `eve deploy`, or integration setup, so traces appear in Agent Runs. Existing projects keep their sampling settings, and `eve deploy --no-trace-sampling` still skips configuration.
diff --git a/packages/eve/src/cli/commands/deploy.integration.test.ts b/packages/eve/src/cli/commands/deploy.integration.test.ts
index 1774039c5..ab5faaa7c 100644
--- a/packages/eve/src/cli/commands/deploy.integration.test.ts
+++ b/packages/eve/src/cli/commands/deploy.integration.test.ts
@@ -305,13 +305,7 @@ describe("runDeployCommand", () => {
if (traceSampling === false) {
expect(linkDeps.resolveProjectByNameOrId).not.toHaveBeenCalled();
}
- if (existing === "unknown") {
- expect(fake.prompter.log.warning).toHaveBeenCalledWith(
- expect.stringContaining("so it was not configured"),
- );
- } else {
- expect(fake.prompter.log.warning).not.toHaveBeenCalled();
- }
+ expect(fake.prompter.log.warning).not.toHaveBeenCalled();
},
);
});
diff --git a/packages/eve/src/cli/commands/deploy.ts b/packages/eve/src/cli/commands/deploy.ts
index 5d957cd3a..75ce8d57a 100644
--- a/packages/eve/src/cli/commands/deploy.ts
+++ b/packages/eve/src/cli/commands/deploy.ts
@@ -1,7 +1,6 @@
import { isEveProject } from "#setup/scaffold/index.js";
import { runDeployFlow, type DeployFlowDeps } from "#setup/flows/deploy.js";
import { createPrompter, type Prompter } from "#setup/prompter.js";
-import { configureTraceSampling } from "#setup/vercel-trace-sampling.js";
import { hasInteractiveTerminal, validateWorkspaceProjectCommand } from "./preconditions.js";
import {
@@ -70,18 +69,8 @@ export async function runDeployCommand(
logger,
appRoot,
options,
+ prompter,
dependencies: dependencies.nonInteractiveLinkDeps,
- onCreatedProject:
- options.traceSampling === false
- ? undefined
- : (link) => configureTraceSampling(link, prompter),
- onProjectCreationUnknown:
- options.traceSampling === false
- ? undefined
- : () =>
- prompter.log.warning(
- "Could not verify the Vercel project for trace sampling, so it was not configured. Check the project settings if you need traces in Agent Runs.",
- ),
}))
)
return;
diff --git a/packages/eve/src/cli/commands/link.integration.test.ts b/packages/eve/src/cli/commands/link.integration.test.ts
index 2508af07a..a473e8125 100644
--- a/packages/eve/src/cli/commands/link.integration.test.ts
+++ b/packages/eve/src/cli/commands/link.integration.test.ts
@@ -10,8 +10,15 @@ import type { LinkProjectDeps } from "#setup/boxes/link-project.js";
import type { ResolveProvisioningDeps } from "#setup/boxes/resolve-provisioning.js";
import type { LinkFlowDeps } from "#setup/flows/link.js";
import { isEveProject } from "#setup/scaffold/index.js";
+import { readVercelCliToken } from "#internal/model-auth/vercel-cli.js";
import { runLinkCommand, type LinkCliLogger } from "./link.js";
+import type { NonInteractiveLinkDependencies } from "./vercel-non-interactive.js";
+
+vi.mock("#internal/model-auth/vercel-cli.js", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("#internal/model-auth/vercel-cli.js")>()),
+ readVercelCliToken: vi.fn(),
+}));
class TestLogger implements LinkCliLogger {
readonly errors: string[] = [];
@@ -115,10 +122,70 @@ function createFlowDeps(): Partial<LinkFlowDeps> {
}
afterEach(() => {
+ vi.clearAllMocks();
+ vi.unstubAllGlobals();
process.exitCode = undefined;
});
describe("runLinkCommand", () => {
+ test.each([
+ { existing: false, expectedRequests: 1 },
+ { existing: true, expectedRequests: 0 },
+ { existing: "unknown", expectedRequests: 0 },
+ ])(
+ "non-interactive link configures sampling only for a new project: $existing",
+ async ({ existing, expectedRequests }) => {
+ const projectRoot = await createAgentProject();
+ const logger = new TestLogger();
+ const fake = createFakePrompter();
+ const lookup = vi.fn<NonInteractiveLinkDependencies["resolveProjectByNameOrId"]>();
+ if (existing === "unknown") lookup.mockRejectedValue(new Error("Access denied"));
+ else
+ lookup.mockResolvedValue(
+ existing ? { projectId: "prj_existing", projectName: "my-agent" } : null,
+ );
+ const linkDeps: NonInteractiveLinkDependencies = {
+ isEveProject,
+ runVercel: vi.fn(async () => true),
+ runVercelEnvPull: vi.fn(async () => true),
+ resolveTeam: vi.fn(async () => "acme"),
+ resolveProjectByNameOrId: lookup,
+ readProjectLink: vi.fn(async () => ({
+ orgId: "team_123",
+ projectId: "prj_new",
+ projectName: "my-agent",
+ })),
+ };
+ vi.mocked(readVercelCliToken).mockResolvedValue("vercel-token");
+ const fetch = vi.fn(async () => new Response(null, { status: 200 }));
+ vi.stubGlobal("fetch", fetch);
+
+ await runLinkCommand(
+ logger,
+ projectRoot,
+ {
+ createPrompter: () => fake.prompter,
+ hasInteractiveTerminal: () => false,
+ nonInteractiveLinkDeps: linkDeps,
+ },
+ { nonInteractive: true, project: "my-agent", team: "acme" },
+ );
+
+ expect(logger.errors).toEqual([]);
+ expect(logger.logs).toContain("Project linked.");
+ expect(fetch).toHaveBeenCalledTimes(expectedRequests);
+ if (expectedRequests > 0) {
+ expect(fetch).toHaveBeenCalledWith(
+ "https://api.vercel.com/v1/drains/tracing/config?projectId=prj_new&teamId=team_123",
+ expect.objectContaining({
+ method: "PUT",
+ body: JSON.stringify({ enabled: true, sampling: [{ type: "head_sampling", rate: 1 }] }),
+ }),
+ );
+ }
+ },
+ );
+
test("refuses a directory without an eve agent", async () => {
const projectRoot = await mkdtemp(join(tmpdir(), "eve-link-empty-"));
const logger = new TestLogger();
diff --git a/packages/eve/src/cli/commands/link.ts b/packages/eve/src/cli/commands/link.ts
index 36cde7583..f181ddb0f 100644
--- a/packages/eve/src/cli/commands/link.ts
+++ b/packages/eve/src/cli/commands/link.ts
@@ -6,6 +6,7 @@ import { hasInteractiveTerminal, validateWorkspaceProjectCommand } from "./preco
import {
isNonInteractiveProjectCommand,
runNonInteractiveLink,
+ type NonInteractiveLinkDependencies,
type VercelProjectCliOptions,
} from "./vercel-non-interactive.js";
@@ -20,6 +21,7 @@ export interface LinkCommandDependencies {
isEveProject?: typeof isEveProject;
/** Test seam into the flow's detection and box effects. */
flowDeps?: Partial<LinkFlowDeps>;
+ nonInteractiveLinkDeps?: NonInteractiveLinkDependencies;
}
const defaultDependencies: LinkCommandDependencies = {
@@ -53,7 +55,14 @@ export async function runLinkCommand(
return;
}
if (isNonInteractiveProjectCommand(options)) {
- await runNonInteractiveLink({ logger, appRoot, options });
+ const prompter = dependencies.createPrompter?.() ?? createPrompter();
+ await runNonInteractiveLink({
+ logger,
+ appRoot,
+ options,
+ prompter,
+ dependencies: dependencies.nonInteractiveLinkDeps,
+ });
return;
}
if (!dependencies.hasInteractiveTerminal()) {
diff --git a/packages/eve/src/cli/commands/vercel-non-interactive.test.ts b/packages/eve/src/cli/commands/vercel-non-interactive.test.ts
index 6c937bfae..24803e0e3 100644
--- a/packages/eve/src/cli/commands/vercel-non-interactive.test.ts
+++ b/packages/eve/src/cli/commands/vercel-non-interactive.test.ts
@@ -1,10 +1,14 @@
import { afterEach, describe, expect, test, vi } from "vitest";
+import { createFakePrompter } from "#internal/testing/fake-prompter.js";
+import { configureTraceSampling } from "#setup/vercel-trace-sampling.js";
import {
runNonInteractiveLink,
type NonInteractiveLinkDependencies,
} from "./vercel-non-interactive.js";
+vi.mock("#setup/vercel-trace-sampling.js", () => ({ configureTraceSampling: vi.fn() }));
+
class TestLogger {
readonly errors: string[] = [];
readonly logs: string[] = [];
@@ -34,6 +38,7 @@ function dependencies(): NonInteractiveLinkDependencies {
}
afterEach(() => {
+ vi.clearAllMocks();
process.exitCode = undefined;
});
@@ -47,6 +52,7 @@ describe("runNonInteractiveLink", () => {
appRoot: "/agent",
options: { nonInteractive: true },
dependencies: deps,
+ prompter: createFakePrompter().prompter,
});
expect(logger.errors).toEqual([
@@ -63,8 +69,9 @@ describe("runNonInteractiveLink", () => {
await runNonInteractiveLink({
logger,
appRoot: "/agent",
- options: { nonInteractive: true, project: "wayfinder", team: "acme" },
+ options: { nonInteractive: true, project: "wayfinder", team: "acme", traceSampling: false },
dependencies: deps,
+ prompter: createFakePrompter().prompter,
});
expect(deps.runVercel).toHaveBeenCalledWith(
@@ -74,17 +81,18 @@ describe("runNonInteractiveLink", () => {
expect(deps.runVercelEnvPull).toHaveBeenCalledWith("/agent", undefined, undefined, true);
expect(logger.logs).toEqual(["Project linked."]);
expect(deps.resolveProjectByNameOrId).not.toHaveBeenCalled();
+ expect(configureTraceSampling).not.toHaveBeenCalled();
});
- test("reports a newly created project after checking the link scope", async () => {
+ test("configures sampling for a newly created project after checking the link scope", async () => {
const deps = dependencies();
- const onCreatedProject = vi.fn(async () => {});
+ const { prompter } = createFakePrompter();
await runNonInteractiveLink({
logger: new TestLogger(),
appRoot: "/agent",
options: { nonInteractive: true, project: "wayfinder", team: "acme" },
dependencies: deps,
- onCreatedProject,
+ prompter,
});
expect(deps.resolveTeam).toHaveBeenCalledWith("/agent", "acme");
@@ -92,37 +100,37 @@ describe("runNonInteractiveLink", () => {
expect(vi.mocked(deps.resolveProjectByNameOrId).mock.invocationCallOrder[0]).toBeLessThan(
vi.mocked(deps.runVercel).mock.invocationCallOrder[0]!,
);
- expect(onCreatedProject).toHaveBeenCalledWith({
- orgId: "team_a",
- projectId: "prj_new",
- projectName: "wayfinder",
- });
+ expect(configureTraceSampling).toHaveBeenCalledWith(
+ {
+ orgId: "team_a",
+ projectId: "prj_new",
+ projectName: "wayfinder",
+ },
+ prompter,
+ );
});
- test("does not report an existing project as created", async () => {
+ test("does not configure sampling for an existing project", async () => {
const deps = dependencies();
vi.mocked(deps.resolveProjectByNameOrId).mockResolvedValue({
projectId: "prj_existing",
projectName: "wayfinder",
});
- const onCreatedProject = vi.fn(async () => {});
await runNonInteractiveLink({
logger: new TestLogger(),
appRoot: "/agent",
options: { nonInteractive: true, project: "wayfinder" },
dependencies: deps,
- onCreatedProject,
+ prompter: createFakePrompter().prompter,
});
- expect(onCreatedProject).not.toHaveBeenCalled();
+ expect(configureTraceSampling).not.toHaveBeenCalled();
expect(deps.readProjectLink).not.toHaveBeenCalled();
});
test("links without configuring sampling if the scoped existence check fails", async () => {
const deps = dependencies();
vi.mocked(deps.resolveProjectByNameOrId).mockRejectedValue(new Error("Access denied"));
- const onCreatedProject = vi.fn(async () => {});
- const onProjectCreationUnknown = vi.fn();
await expect(
runNonInteractiveLink({
@@ -130,21 +138,17 @@ describe("runNonInteractiveLink", () => {
appRoot: "/agent",
options: { nonInteractive: true, project: "wayfinder" },
dependencies: deps,
- onCreatedProject,
- onProjectCreationUnknown,
+ prompter: createFakePrompter().prompter,
}),
).resolves.toBe(true);
expect(deps.runVercel).toHaveBeenCalled();
- expect(onCreatedProject).not.toHaveBeenCalled();
- expect(onProjectCreationUnknown).toHaveBeenCalledOnce();
+ expect(configureTraceSampling).not.toHaveBeenCalled();
});
test("continues linking when project metadata is unavailable for sampling", async () => {
const deps = dependencies();
vi.mocked(deps.readProjectLink).mockResolvedValue(undefined);
- const onCreatedProject = vi.fn(async () => {});
- const onProjectCreationUnknown = vi.fn();
await expect(
runNonInteractiveLink({
@@ -152,13 +156,11 @@ describe("runNonInteractiveLink", () => {
appRoot: "/agent",
options: { nonInteractive: true, project: "wayfinder" },
dependencies: deps,
- onCreatedProject,
- onProjectCreationUnknown,
+ prompter: createFakePrompter().prompter,
}),
).resolves.toBe(true);
expect(deps.runVercelEnvPull).toHaveBeenCalled();
- expect(onCreatedProject).not.toHaveBeenCalled();
- expect(onProjectCreationUnknown).toHaveBeenCalledOnce();
+ expect(configureTraceSampling).not.toHaveBeenCalled();
});
});
diff --git a/packages/eve/src/cli/commands/vercel-non-interactive.ts b/packages/eve/src/cli/commands/vercel-non-interactive.ts
index 5cf88af97..e13ed504e 100644
--- a/packages/eve/src/cli/commands/vercel-non-interactive.ts
+++ b/packages/eve/src/cli/commands/vercel-non-interactive.ts
@@ -1,8 +1,10 @@
import { runVercelEnvPull } from "#setup/run-vercel-link.js";
import { isEveProject } from "#setup/scaffold/index.js";
import { runVercel } from "#setup/primitives/index.js";
-import { readProjectLink, type VercelProjectReference } from "#setup/project-resolution.js";
+import { readProjectLink } from "#setup/project-resolution.js";
import { resolveProjectByNameOrId, resolveTeam } from "#setup/vercel-project.js";
+import type { Prompter } from "#setup/prompter.js";
+import { configureTraceSampling } from "#setup/vercel-trace-sampling.js";
import { NOT_AN_AGENT_MESSAGE } from "./preconditions.js";
@@ -43,10 +45,9 @@ export function isNonInteractiveProjectCommand(options: VercelProjectCliOptions)
export async function runNonInteractiveLink(input: {
logger: VercelNonInteractiveLogger;
appRoot: string;
- options: VercelProjectCliOptions;
+ options: VercelProjectCliOptions & { traceSampling?: boolean };
+ prompter: Pick<Prompter, "log">;
dependencies?: NonInteractiveLinkDependencies;
- onCreatedProject?: (link: VercelProjectReference) => Promise<void>;
- onProjectCreationUnknown?: () => void;
}): Promise<boolean> {
const { appRoot, logger, options } = input;
const dependencies = input.dependencies ?? defaultDependencies;
@@ -62,7 +63,7 @@ export async function runNonInteractiveLink(input: {
}
let existing: boolean | undefined;
- if (input.onCreatedProject !== undefined) {
+ if (options.traceSampling !== false) {
try {
existing =
(await dependencies.resolveProjectByNameOrId(
@@ -85,13 +86,9 @@ export async function runNonInteractiveLink(input: {
process.exitCode = 1;
return false;
}
- if (existing === false && input.onCreatedProject !== undefined) {
+ if (existing === false) {
const link = await dependencies.readProjectLink(appRoot).catch(() => undefined);
- if (link !== undefined) await input.onCreatedProject(link);
- else input.onProjectCreationUnknown?.();
- }
- if (existing === undefined && input.onCreatedProject !== undefined) {
- input.onProjectCreationUnknown?.();
+ if (link !== undefined) await configureTraceSampling(link, input.prompter);
}
if (!(await dependencies.runVercelEnvPull(appRoot, undefined, undefined, true))) {
logger.error("Vercel project linked, but pulling environment variables did not complete.");
diff --git a/packages/eve/src/setup/vercel-project.test.ts b/packages/eve/src/setup/vercel-project.test.ts
index c45595653..5970c1d64 100644
--- a/packages/eve/src/setup/vercel-project.test.ts
+++ b/packages/eve/src/setup/vercel-project.test.ts
@@ -627,6 +627,7 @@ describe("linkProject", () => {
).resolves.toEqual({ projectId: "prj_existing", projectName: "my-agent" });
expect(mockedCaptureVercel).not.toHaveBeenCalled();
+ expect(mockedConfigureTraceSampling).not.toHaveBeenCalled();
expect(mockedRunVercel).toHaveBeenCalledWith(
["link", "--project", "prj_existing", "--scope", "team-a", "--yes"],
expect.objectContaining({ cwd: "/tmp/eve-agent", nonInteractive: true }),
@@ -691,7 +692,6 @@ describe("linkProject", () => {
"/tmp/eve-agent",
{ kind: "new", project: "my-agent", team: "team-a" },
createPromptCommandOutput(prompter.log),
- { traceSampling: true },
),
).resolves.toEqual({ projectId: "prj_new", projectName: "my-agent" });
expect(mockedCaptureVercel).toHaveBeenCalledTimes(2);
@@ -717,36 +717,33 @@ describe("linkProject", () => {
);
});
- it.each([undefined, false])(
- "does not configure sampling without an explicit true value (%s)",
- async (traceSampling) => {
- mockedCaptureVercel
- .mockResolvedValueOnce(
- failedCapture(
- JSON.stringify({ error: { code: "not_found", message: "Project not found" } }),
- ),
- )
- .mockResolvedValueOnce(captured({ framework: "eve" }));
- mockedReadProjectLink.mockResolvedValueOnce({
- orgId: "team-a",
- projectId: "prj_new",
- projectName: "my-agent",
- });
- const { prompter } = createFakePrompter();
-
- await expect(
- linkProject(
- prompter,
- "/tmp/eve-agent",
- { kind: "new", project: "my-agent", team: "team-a" },
- createPromptCommandOutput(prompter.log),
- { traceSampling },
+ it("does not configure sampling when explicitly disabled", async () => {
+ mockedCaptureVercel
+ .mockResolvedValueOnce(
+ failedCapture(
+ JSON.stringify({ error: { code: "not_found", message: "Project not found" } }),
),
- ).resolves.toEqual({ projectId: "prj_new", projectName: "my-agent" });
+ )
+ .mockResolvedValueOnce(captured({ framework: "eve" }));
+ mockedReadProjectLink.mockResolvedValueOnce({
+ orgId: "team-a",
+ projectId: "prj_new",
+ projectName: "my-agent",
+ });
+ const { prompter } = createFakePrompter();
- expect(mockedConfigureTraceSampling).not.toHaveBeenCalled();
- },
- );
+ await expect(
+ linkProject(
+ prompter,
+ "/tmp/eve-agent",
+ { kind: "new", project: "my-agent", team: "team-a" },
+ createPromptCommandOutput(prompter.log),
+ { traceSampling: false },
+ ),
+ ).resolves.toEqual({ projectId: "prj_new", projectName: "my-agent" });
+
+ expect(mockedConfigureTraceSampling).not.toHaveBeenCalled();
+ });
it("uses the requested project name when Vercel's link metadata omits the name", async () => {
mockedCaptureVercel
diff --git a/packages/eve/src/setup/vercel-project.ts b/packages/eve/src/setup/vercel-project.ts
index 66d5a4415..b20b81d15 100644
--- a/packages/eve/src/setup/vercel-project.ts
+++ b/packages/eve/src/setup/vercel-project.ts
@@ -60,7 +60,7 @@ interface PickTeamOptions extends VercelProjectOperationOptions {
}
export interface LinkProjectOperationOptions extends CreatedProjectFrameworkOptions {
- /** Configure 100% trace sampling when creating a Vercel project. */
+ /** Configure 100% trace sampling when creating a Vercel project. Defaults to true. */
traceSampling?: boolean;
}
@@ -734,7 +734,7 @@ export async function linkProject(
if (!linked) return undefined;
const link = await readProjectLink(projectRoot);
if (link === undefined) return undefined;
- if (options.traceSampling === true)
+ if (options.traceSampling !== false)
await configureTraceSampling(link, prompter, options.signal);
await ensureCreatedProjectFramework(
prompter,