Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

Configure Vercel trace sampling for new projects (#3734)

Chad Hietala306f2ce2fdc9
diff --git a/.changeset/bright-rules-configure.md b/.changeset/bright-rules-configure.md
new file mode 100644
index 000000000..d57eb2547
--- /dev/null
+++ b/.changeset/bright-rules-configure.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Configure 100% Vercel trace sampling across all environments when `eve deploy` creates a new project, with `--no-trace-sampling` to opt out.
diff --git a/docs/guides/deployment/vercel.mdx b/docs/guides/deployment/vercel.mdx
index 10435020f..3b5dfa7ae 100644
--- a/docs/guides/deployment/vercel.mdx
+++ b/docs/guides/deployment/vercel.mdx
@@ -122,6 +122,8 @@ eve deploy
`eve deploy` installs dependencies, runs `vercel deploy --prod`, and pulls the project environment after deployment. You can also push to a Git-connected Vercel project. Hosted Vercel builds set `VERCEL`, so `eve build` writes the deployment bundle under `.vercel/output`.
+When `eve deploy` creates a new Vercel project, it configures trace sampling so traces appear in Agent Runs automatically. See [Agent Runs](../../observability/agent-runs) for details. Pass `--no-trace-sampling` to skip this setting.
+
For non-interactive use, confirm the production deploy up front. `--project` links first, so a new project needs no separate `eve link`:
```bash
diff --git a/docs/guides/instrumentation/agent-runs.mdx b/docs/guides/instrumentation/agent-runs.mdx
index 2eb312ee2..c4fe50c62 100644
--- a/docs/guides/instrumentation/agent-runs.mdx
+++ b/docs/guides/instrumentation/agent-runs.mdx
@@ -28,10 +28,10 @@ Omitting `agent/instrumentation/agent-runs.ts` preserves that default. Export
## Enable tracing on Vercel
-New eve deployments automatically sample 100% of requests. Existing eve
-deployments need a sampling rule configured for the Vercel project to collect
-traces. To enable tracing for an existing deployment, select your team and
-project, then open
+When `eve deploy` creates a new Vercel project, it configures 100% trace
+sampling for all environments. Existing Vercel projects need a sampling rule
+configured to collect traces. To enable tracing for an existing project, select
+your team and project, then open
[**Settings → Tracing**](https://vercel.com/d?to=%2F%5Bteam%5D%2F%5Bproject%5D%2Fsettings%2Ftracing&title=Go+to+Tracing+settings):
1. Select **Add Sampling Rule**.
diff --git a/packages/eve/src/cli/commands/deploy.integration.test.ts b/packages/eve/src/cli/commands/deploy.integration.test.ts
index b45f737d1..ae239fae2 100644
--- a/packages/eve/src/cli/commands/deploy.integration.test.ts
+++ b/packages/eve/src/cli/commands/deploy.integration.test.ts
@@ -6,11 +6,20 @@ import { afterEach, describe, expect, test, vi } from "vitest";
import { createFakePrompter } from "#internal/testing/fake-prompter.js";
import { packageInstallResult } from "#internal/testing/package-process.js";
+import { readVercelCliToken } from "#internal/model-auth/vercel-cli.js";
import type { DeployProjectDeps } from "#setup/boxes/deploy-project.js";
+import type { LinkProjectDeps } from "#setup/boxes/link-project.js";
+import type { ResolveProvisioningDeps } from "#setup/boxes/resolve-provisioning.js";
import type { DeploymentInfo } from "#setup/project-resolution.js";
import { isEveProject } from "#setup/scaffold/index.js";
import { runDeployCommand, type DeployCliLogger } from "./deploy.js";
+import type { NonInteractiveLinkDependencies } from "./vercel-non-interactive.js";
+
+vi.mock("#internal/model-auth/vercel-cli.js", async (importOriginal) => {
+ const original = await importOriginal<typeof import("#internal/model-auth/vercel-cli.js")>();
+ return { ...original, readVercelCliToken: vi.fn(async () => "vercel-token") };
+});
class TestLogger implements DeployCliLogger {
readonly errors: string[] = [];
@@ -70,8 +79,38 @@ function createDeployProjectDeps() {
};
}
+function createNonInteractiveLinkDeps(): NonInteractiveLinkDependencies {
+ return {
+ isEveProject: vi.fn(async () => true),
+ runVercel: vi.fn(async () => true),
+ runVercelEnvPull: vi.fn(async () => true),
+ readProjectLink: vi.fn(async () => ({
+ orgId: "team_123",
+ projectId: "prj_new",
+ projectName: "my-agent",
+ })),
+ resolveTeam: vi.fn(async () => "acme"),
+ resolveProjectByNameOrId: vi.fn(async () => null),
+ };
+}
+
+function createInteractiveLinkDeps() {
+ return {
+ linkProject: vi.fn<LinkProjectDeps["linkProject"]>(async () => ({
+ projectId: "prj_new",
+ projectName: "my-agent",
+ })),
+ detectProjectResolution: vi.fn<LinkProjectDeps["detectProjectResolution"]>(async () => ({
+ kind: "linked",
+ projectId: "prj_new",
+ })),
+ unresolvedProject: vi.fn<LinkProjectDeps["unresolvedProject"]>(() => ({ kind: "unresolved" })),
+ };
+}
+
afterEach(() => {
process.exitCode = undefined;
+ vi.unstubAllGlobals();
});
describe("runDeployCommand", () => {
@@ -146,4 +185,133 @@ describe("runDeployCommand", () => {
);
expect(fake.prompter.outro).toHaveBeenCalledWith("Deployed: https://my-agent.vercel.app");
});
+
+ test.each([
+ { traceSampling: undefined, expected: true },
+ { traceSampling: false, expected: false },
+ ])(
+ "passes the deploy tracing default to interactive linking",
+ async ({ traceSampling, expected }) => {
+ const projectRoot = await createAgentProject();
+ const fake = createFakePrompter({
+ single: (opts) => {
+ if (opts.message === "Vercel project") return "new";
+ throw new Error(`Unexpected select: ${opts.message}`);
+ },
+ });
+ const linkDeps = createInteractiveLinkDeps();
+ const provisioningDeps: ResolveProvisioningDeps = {
+ requireAuth: vi.fn(async () => {}),
+ isVercelAuthenticated: vi.fn(async () => true),
+ detectProjectResolution: vi.fn<ResolveProvisioningDeps["detectProjectResolution"]>(
+ async () => ({ kind: "unresolved" }),
+ ),
+ pathExists: vi.fn(async () => false),
+ validateTeam: vi.fn(async () => {}),
+ resolveTeam: vi.fn(async () => "acme"),
+ pickTeam: vi.fn(async () => "acme"),
+ pickProject: vi.fn<ResolveProvisioningDeps["pickProject"]>(async () => ({
+ kind: "new",
+ project: "my-agent",
+ team: "acme",
+ })),
+ resolveProjectByNameOrId: vi.fn(async () => null),
+ pickNewProjectName: vi.fn(async () => "my-agent"),
+ assertNewProjectNameAvailable: vi.fn(async () => {}),
+ };
+ const logger = new TestLogger();
+
+ await runDeployCommand(
+ logger,
+ projectRoot,
+ {
+ createPrompter: () => fake.prompter,
+ hasInteractiveTerminal: () => true,
+ flowDeps: {
+ detectDeployment: vi.fn(async () => ({ state: "unlinked" as const })),
+ runLoginFlow: vi.fn(async () => ({ kind: "already" as const })),
+ resolveProvisioning: provisioningDeps,
+ linkProject: linkDeps,
+ deployProject: createDeployProjectDeps(),
+ },
+ },
+ { traceSampling },
+ );
+
+ expect(logger.errors).toEqual([]);
+ expect(linkDeps.linkProject).toHaveBeenCalledWith(
+ fake.prompter,
+ projectRoot,
+ expect.objectContaining({ kind: "new" }),
+ expect.any(Function),
+ { signal: undefined, traceSampling: expected },
+ );
+ },
+ );
+
+ test.each([
+ { existing: false, traceSampling: undefined, shouldConfigure: true },
+ { existing: false, traceSampling: false, shouldConfigure: false },
+ { existing: true, traceSampling: undefined, shouldConfigure: false },
+ { existing: "unknown", traceSampling: undefined, shouldConfigure: false },
+ ])(
+ "non-interactive deploy: existing=$existing traceSampling=$traceSampling",
+ async ({ existing, traceSampling, shouldConfigure }) => {
+ const projectRoot = await createAgentProject();
+ const logger = new TestLogger();
+ const fake = createFakePrompter({});
+ const linkDeps = createNonInteractiveLinkDeps();
+ if (existing === true) {
+ vi.mocked(linkDeps.resolveProjectByNameOrId).mockResolvedValue({
+ projectId: "prj_existing",
+ projectName: "my-agent",
+ });
+ } else if (existing === "unknown") {
+ vi.mocked(linkDeps.resolveProjectByNameOrId).mockRejectedValue(
+ new Error("Vercel API unavailable"),
+ );
+ }
+ const fetchMock = vi.fn(async () => new Response("{}", { status: 200 }));
+ vi.stubGlobal("fetch", fetchMock);
+ const deployDeps = createDeployProjectDeps();
+
+ await runDeployCommand(
+ logger,
+ projectRoot,
+ {
+ createPrompter: () => fake.prompter,
+ hasInteractiveTerminal: () => false,
+ nonInteractiveLinkDeps: linkDeps,
+ flowDeps: {
+ detectDeployment: vi.fn(async () => LINKED),
+ deployProject: deployDeps,
+ },
+ },
+ { nonInteractive: true, project: "my-agent", yes: true, traceSampling },
+ );
+
+ expect(logger.errors).toEqual([]);
+ expect(process.exitCode).toBeUndefined();
+ expect(deployDeps.runVercel).toHaveBeenCalled();
+ if (shouldConfigure) {
+ expect(readVercelCliToken).toHaveBeenCalled();
+ expect(fetchMock).toHaveBeenCalledWith(
+ "https://api.vercel.com/v1/drains/tracing/config?projectId=prj_new&teamId=team_123",
+ expect.objectContaining({ method: "PUT" }),
+ );
+ } else {
+ expect(fetchMock).not.toHaveBeenCalled();
+ }
+ 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();
+ }
+ },
+ );
});
diff --git a/packages/eve/src/cli/commands/deploy.ts b/packages/eve/src/cli/commands/deploy.ts
index a2e78a909..5d957cd3a 100644
--- a/packages/eve/src/cli/commands/deploy.ts
+++ b/packages/eve/src/cli/commands/deploy.ts
@@ -1,11 +1,13 @@
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 {
isNonInteractiveProjectCommand,
runNonInteractiveLink,
+ type NonInteractiveLinkDependencies,
type VercelProjectCliOptions,
} from "./vercel-non-interactive.js";
@@ -20,6 +22,7 @@ export interface DeployCommandDependencies {
isEveProject?: typeof isEveProject;
/** Test seam into the flow's detection and box effects. */
flowDeps?: Partial<DeployFlowDeps>;
+ nonInteractiveLinkDeps?: NonInteractiveLinkDependencies;
}
const defaultDependencies: DeployCommandDependencies = {
@@ -38,7 +41,7 @@ export async function runDeployCommand(
logger: DeployCliLogger,
appRoot: string,
dependencies: DeployCommandDependencies = defaultDependencies,
- options: VercelProjectCliOptions & { yes?: boolean } = {},
+ options: VercelProjectCliOptions & { yes?: boolean; traceSampling?: boolean } = {},
): Promise<void> {
if (
!(await validateWorkspaceProjectCommand({
@@ -51,27 +54,44 @@ export async function runDeployCommand(
) {
return;
}
- if (isNonInteractiveProjectCommand(options)) {
- if (options.yes !== true) {
- logger.error(
- "`eve deploy --non-interactive` requires `--yes` to confirm production deployment.",
- );
- process.exitCode = 1;
- return;
- }
- if (options.project !== undefined) {
- if (!(await runNonInteractiveLink({ logger, appRoot, options }))) return;
- }
+ const nonInteractive = isNonInteractiveProjectCommand(options);
+ if (nonInteractive && options.yes !== true) {
+ logger.error(
+ "`eve deploy --non-interactive` requires `--yes` to confirm production deployment.",
+ );
+ process.exitCode = 1;
+ return;
}
const prompter = dependencies.createPrompter?.() ?? createPrompter();
- prompter.intro("Deploy your eve agent to Vercel");
try {
+ if (nonInteractive && options.project !== undefined) {
+ if (
+ !(await runNonInteractiveLink({
+ logger,
+ appRoot,
+ options,
+ 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;
+ }
+ prompter.intro("Deploy your eve agent to Vercel");
const result = await runDeployFlow({
appRoot,
prompter,
- interactive: isNonInteractiveProjectCommand(options)
- ? false
- : dependencies.hasInteractiveTerminal(),
+ traceSampling: options.traceSampling !== false,
+ interactive: nonInteractive ? false : dependencies.hasInteractiveTerminal(),
deps: dependencies.flowDeps,
});
if (result.kind === "needs-link") {
diff --git a/packages/eve/src/cli/commands/register-project-commands.ts b/packages/eve/src/cli/commands/register-project-commands.ts
index 6016bf0a4..5c37ee528 100644
--- a/packages/eve/src/cli/commands/register-project-commands.ts
+++ b/packages/eve/src/cli/commands/register-project-commands.ts
@@ -42,12 +42,14 @@ export function registerProjectCommands(input: {
.option("--project <name-or-id>", "Vercel project name or ID")
.option("--team <team-id-or-slug>", "Vercel team ID or slug")
.option("-y, --yes", "Confirm a non-interactive production deployment")
+ .option("--no-trace-sampling", "Skip 100% Vercel trace sampling for a new project")
.action(
async (options: {
nonInteractive?: boolean;
project?: string;
team?: string;
yes?: boolean;
+ traceSampling?: boolean;
}) => {
const { runDeployCommand } = await import("./deploy.js");
await runDeployCommand(input.logger, input.applicationContext.root, undefined, options);
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 595d401a3..6c937bfae 100644
--- a/packages/eve/src/cli/commands/vercel-non-interactive.test.ts
+++ b/packages/eve/src/cli/commands/vercel-non-interactive.test.ts
@@ -23,6 +23,13 @@ function dependencies(): NonInteractiveLinkDependencies {
isEveProject: vi.fn(async () => true),
runVercel: vi.fn(async () => true),
runVercelEnvPull: vi.fn(async () => true),
+ readProjectLink: vi.fn(async () => ({
+ orgId: "team_a",
+ projectId: "prj_new",
+ projectName: "wayfinder",
+ })),
+ resolveTeam: vi.fn(async () => "acme"),
+ resolveProjectByNameOrId: vi.fn(async () => null),
};
}
@@ -66,5 +73,92 @@ describe("runNonInteractiveLink", () => {
);
expect(deps.runVercelEnvPull).toHaveBeenCalledWith("/agent", undefined, undefined, true);
expect(logger.logs).toEqual(["Project linked."]);
+ expect(deps.resolveProjectByNameOrId).not.toHaveBeenCalled();
+ });
+ test("reports a newly created project after checking the link scope", async () => {
+ const deps = dependencies();
+ const onCreatedProject = vi.fn(async () => {});
+
+ await runNonInteractiveLink({
+ logger: new TestLogger(),
+ appRoot: "/agent",
+ options: { nonInteractive: true, project: "wayfinder", team: "acme" },
+ dependencies: deps,
+ onCreatedProject,
+ });
+
+ expect(deps.resolveTeam).toHaveBeenCalledWith("/agent", "acme");
+ expect(deps.resolveProjectByNameOrId).toHaveBeenCalledWith("/agent", "acme", "wayfinder");
+ 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",
+ });
+ });
+ test("does not report an existing project as created", 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,
+ });
+
+ expect(onCreatedProject).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({
+ logger: new TestLogger(),
+ appRoot: "/agent",
+ options: { nonInteractive: true, project: "wayfinder" },
+ dependencies: deps,
+ onCreatedProject,
+ onProjectCreationUnknown,
+ }),
+ ).resolves.toBe(true);
+
+ expect(deps.runVercel).toHaveBeenCalled();
+ expect(onCreatedProject).not.toHaveBeenCalled();
+ expect(onProjectCreationUnknown).toHaveBeenCalledOnce();
+ });
+
+ 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({
+ logger: new TestLogger(),
+ appRoot: "/agent",
+ options: { nonInteractive: true, project: "wayfinder" },
+ dependencies: deps,
+ onCreatedProject,
+ onProjectCreationUnknown,
+ }),
+ ).resolves.toBe(true);
+
+ expect(deps.runVercelEnvPull).toHaveBeenCalled();
+ expect(onCreatedProject).not.toHaveBeenCalled();
+ expect(onProjectCreationUnknown).toHaveBeenCalledOnce();
});
});
diff --git a/packages/eve/src/cli/commands/vercel-non-interactive.ts b/packages/eve/src/cli/commands/vercel-non-interactive.ts
index de056e584..9ae9aa75a 100644
--- a/packages/eve/src/cli/commands/vercel-non-interactive.ts
+++ b/packages/eve/src/cli/commands/vercel-non-interactive.ts
@@ -1,6 +1,8 @@
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 { resolveProjectByNameOrId, resolveTeam } from "#setup/vercel-project.js";
import { NOT_AN_AGENT_MESSAGE } from "./preconditions.js";
@@ -19,12 +21,18 @@ export interface NonInteractiveLinkDependencies {
isEveProject: typeof isEveProject;
runVercel: typeof runVercel;
runVercelEnvPull: typeof runVercelEnvPull;
+ readProjectLink: typeof readProjectLink;
+ resolveTeam: typeof resolveTeam;
+ resolveProjectByNameOrId: typeof resolveProjectByNameOrId;
}
const defaultDependencies: NonInteractiveLinkDependencies = {
isEveProject,
runVercel,
runVercelEnvPull,
+ readProjectLink,
+ resolveTeam,
+ resolveProjectByNameOrId,
};
export function isNonInteractiveProjectCommand(options: VercelProjectCliOptions): boolean {
@@ -37,6 +45,8 @@ export async function runNonInteractiveLink(input: {
appRoot: string;
options: VercelProjectCliOptions;
dependencies?: NonInteractiveLinkDependencies;
+ onCreatedProject?: (link: VercelProjectReference) => Promise<void>;
+ onProjectCreationUnknown?: () => void;
}): Promise<boolean> {
const { appRoot, logger, options } = input;
const dependencies = input.dependencies ?? defaultDependencies;
@@ -51,6 +61,19 @@ export async function runNonInteractiveLink(input: {
return false;
}
+ let existing: boolean | undefined;
+ if (input.onCreatedProject !== undefined) {
+ try {
+ existing =
+ (await dependencies.resolveProjectByNameOrId(
+ appRoot,
+ await dependencies.resolveTeam(appRoot, options.team),
+ options.project,
+ )) !== null;
+ } catch {
+ // An uncertain project identity must not turn on billable sampling.
+ }
+ }
const args = [
"link",
"--project",
@@ -62,6 +85,14 @@ export async function runNonInteractiveLink(input: {
process.exitCode = 1;
return false;
}
+ if (existing === false && input.onCreatedProject !== undefined) {
+ 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 (!(await dependencies.runVercelEnvPull(appRoot, undefined, undefined, true))) {
logger.error("Vercel project linked, but pulling environment variables did not complete.");
process.exitCode = 1;
diff --git a/packages/eve/src/cli/run.test.ts b/packages/eve/src/cli/run.test.ts
index b54645bcf..4e3d6d0fb 100644
--- a/packages/eve/src/cli/run.test.ts
+++ b/packages/eve/src/cli/run.test.ts
@@ -107,6 +107,17 @@ describe("CLI command registration", () => {
expect(help).not.toContain("setup [options] <item>");
});
+ it("lists the trace sampling opt-out on deploy", async () => {
+ const output: string[] = [];
+
+ await runCli(["deploy", "--help"], {
+ error: (message) => output.push(message),
+ log: (message) => output.push(message),
+ });
+
+ expect(output.join("\n")).toContain("--no-trace-sampling");
+ });
+
it("forwards model settings to the set command", async () => {
const logger = { error: vi.fn(), log: vi.fn() };
runSetCommand.mockClear();
@@ -133,6 +144,22 @@ describe("CLI command registration", () => {
nonInteractive: undefined,
project: undefined,
team: undefined,
+ traceSampling: true,
+ yes: undefined,
+ });
+ });
+
+ it("lets deploy opt out of default trace sampling for a new project", async () => {
+ const logger = { error: vi.fn(), log: vi.fn() };
+ runDeployCommand.mockClear();
+
+ await runCli(["deploy", "--no-trace-sampling"], logger);
+
+ expect(runDeployCommand).toHaveBeenCalledWith(logger, resolve(process.cwd()), undefined, {
+ nonInteractive: undefined,
+ project: undefined,
+ team: undefined,
+ traceSampling: false,
yes: undefined,
});
});
diff --git a/packages/eve/src/internal/model-auth/vercel-cli.test.ts b/packages/eve/src/internal/model-auth/vercel-cli.test.ts
index df8f23468..49e3c325a 100644
--- a/packages/eve/src/internal/model-auth/vercel-cli.test.ts
+++ b/packages/eve/src/internal/model-auth/vercel-cli.test.ts
@@ -20,7 +20,7 @@ vi.mock("node:module", () => ({
},
}),
}));
-import { readVercelCliConnection } from "./vercel-cli.js";
+import { readVercelCliConnection, readVercelCliToken } from "./vercel-cli.js";
const base =
process.platform === "darwin"
? "/test/home/Library/Application Support"
@@ -71,3 +71,17 @@ it("does not guess a team when the CLI has no selection", async () => {
mocks.read.mockResolvedValue("{}");
expect(await readVercelCliConnection()).toBeUndefined();
});
+it("reads personal-scope file credentials without a selected team", async () => {
+ mocks.read.mockImplementation(async (path: string) => {
+ if (path === configPath) return JSON.stringify({ credStorage: "file" });
+ if (path === authPath) return JSON.stringify({ token: "personal-token" });
+ throw new Error("ENOENT");
+ });
+ expect(await readVercelCliConnection()).toBeUndefined();
+ expect(await readVercelCliToken()).toBe("personal-token");
+});
+it("uses VERCEL_TOKEN without CLI configuration", async () => {
+ mocks.read.mockRejectedValue(new Error("ENOENT"));
+ vi.stubEnv("VERCEL_TOKEN", "env-token");
+ expect(await readVercelCliToken()).toBe("env-token");
+});
diff --git a/packages/eve/src/internal/model-auth/vercel-cli.ts b/packages/eve/src/internal/model-auth/vercel-cli.ts
index 9670d572d..3745fcb42 100644
--- a/packages/eve/src/internal/model-auth/vercel-cli.ts
+++ b/packages/eve/src/internal/model-auth/vercel-cli.ts
@@ -19,7 +19,7 @@ async function readObject(path: string): Promise<Record<string, unknown> | undef
}
async function readCliConfiguration(): Promise<
- { directory: string; config: Record<string, unknown>; teamId: string } | undefined
+ { directory: string; config: Record<string, unknown>; teamId?: string } | undefined
> {
const home = homedir();
const base =
@@ -32,7 +32,6 @@ async function readCliConfiguration(): Promise<
const config = await readObject(join(dir, "config.json"));
if (config === undefined) continue;
const teamId = typeof config.currentTeam === "string" ? config.currentTeam : undefined;
- if (!teamId) return undefined;
return { directory: dir, config, teamId };
}
return undefined;
@@ -47,9 +46,22 @@ export async function readVercelCliConnection(): Promise<
{ token: string; teamId: string } | undefined
> {
const configuration = await readCliConfiguration();
+ if (!configuration?.teamId) return undefined;
+ const token = await readCliToken(configuration);
+ return token === undefined ? undefined : { token, teamId: configuration.teamId };
+}
+
+/** Read a CLI token without requiring a selected team (personal accounts have none). */
+export async function readVercelCliToken(): Promise<string | undefined> {
+ return readCliToken(await readCliConfiguration());
+}
+
+async function readCliToken(
+ configuration: Awaited<ReturnType<typeof readCliConfiguration>>,
+): Promise<string | undefined> {
+ if (process.env.VERCEL_TOKEN) return process.env.VERCEL_TOKEN;
if (!configuration) return undefined;
- const { directory: dir, config, teamId } = configuration;
- if (process.env.VERCEL_TOKEN) return { token: process.env.VERCEL_TOKEN, teamId };
+ const { directory: dir, config } = configuration;
const storage = process.env.VERCEL_TOKEN_STORAGE ?? config.credStorage ?? "file";
const path = join(dir, "auth.json");
let auth: Record<string, unknown> | undefined;
@@ -66,7 +78,7 @@ export async function readVercelCliConnection(): Promise<
if (!auth && storage === "auto") auth = await readObject(path);
}
if (typeof auth?.token !== "string" || !auth.token) return undefined;
- return { token: auth.token, teamId };
+ return auth.token;
}
export async function refreshVercelCliConnection(): Promise<void> {
diff --git a/packages/eve/src/setup/boxes/link-project.ts b/packages/eve/src/setup/boxes/link-project.ts
index fc392c880..bfbdbf0fc 100644
--- a/packages/eve/src/setup/boxes/link-project.ts
+++ b/packages/eve/src/setup/boxes/link-project.ts
@@ -8,7 +8,11 @@ import {
import type { Prompter } from "../prompter.js";
import { requireProjectPath, type SetupState } from "../state.js";
import type { SetupBox } from "../step.js";
-import { linkProject, unresolvedProject } from "../vercel-project.js";
+import {
+ linkProject,
+ unresolvedProject,
+ type LinkProjectOperationOptions,
+} from "../vercel-project.js";
/** Injected for tests; defaults to the real Vercel project helpers. */
export interface LinkProjectDeps {
@@ -22,6 +26,8 @@ export interface LinkProjectOptions {
prompter: Prompter;
/** Headless runs must not ask follow-up questions after the plan is fixed. */
headless?: boolean;
+ /** Configure 100% trace sampling for a newly created project. */
+ traceSampling?: boolean;
deps?: LinkProjectDeps;
}
@@ -64,12 +70,15 @@ export function linkVercelProject(
}
const projectRoot = requireProjectPath(state);
const onOutput = createPromptCommandOutput(options.prompter.log);
+ const linkOptions: LinkProjectOperationOptions = { signal };
+ if (options.headless) linkOptions.headless = true;
+ if (options.traceSampling !== undefined) linkOptions.traceSampling = options.traceSampling;
const linked = await deps.linkProject(
options.prompter,
projectRoot,
plan,
onOutput,
- options.headless ? { signal, headless: true } : { signal },
+ linkOptions,
);
signal?.throwIfAborted();
if (!linked) {
diff --git a/packages/eve/src/setup/flows/deploy.test.ts b/packages/eve/src/setup/flows/deploy.test.ts
index 57fb66660..cab504534 100644
--- a/packages/eve/src/setup/flows/deploy.test.ts
+++ b/packages/eve/src/setup/flows/deploy.test.ts
@@ -176,6 +176,7 @@ describe("runDeployFlow", () => {
const result = await runDeployFlow({
appRoot: APP_ROOT,
prompter: fake.prompter,
+ traceSampling: false,
interactive: true,
deps: {
detectDeployment: vi.fn(async () => UNLINKED),
@@ -197,6 +198,13 @@ describe("runDeployFlow", () => {
provisioningDeps.pickTeam.mock.invocationCallOrder[0]!,
);
expect(linkDeps.linkProject).toHaveBeenCalled();
+ expect(linkDeps.linkProject).toHaveBeenCalledWith(
+ fake.prompter,
+ APP_ROOT,
+ { kind: "new", project: "my-agent", team: "acme" },
+ expect.anything(),
+ { signal: undefined, traceSampling: false },
+ );
expect(deployDeps.runVercel).toHaveBeenCalledWith(
["deploy", "--prod", "--yes"],
expect.objectContaining({ cwd: APP_ROOT }),
diff --git a/packages/eve/src/setup/flows/deploy.ts b/packages/eve/src/setup/flows/deploy.ts
index 16e9571ae..f67de4d73 100644
--- a/packages/eve/src/setup/flows/deploy.ts
+++ b/packages/eve/src/setup/flows/deploy.ts
@@ -53,6 +53,7 @@ export async function runDeployFlow(input: {
appRoot: string;
prompter: Prompter;
signal?: AbortSignal;
+ traceSampling?: boolean;
/** False when no TTY: an unlinked directory refuses instead of prompting. */
interactive: boolean;
deps?: Partial<DeployFlowDeps>;
@@ -117,7 +118,11 @@ export async function runDeployFlow(input: {
mode: { headless: false },
deps: deps.resolveProvisioning,
}),
- linkVercelProject({ prompter, deps: deps.linkProject }),
+ linkVercelProject({
+ prompter,
+ traceSampling: input.traceSampling,
+ deps: deps.linkProject,
+ }),
deployProject({ prompter, headless: !interactive, deps: deps.deployProject }),
];
diff --git a/packages/eve/src/setup/vercel-project.test.ts b/packages/eve/src/setup/vercel-project.test.ts
index c3dc68bba..9be5f1b0d 100644
--- a/packages/eve/src/setup/vercel-project.test.ts
+++ b/packages/eve/src/setup/vercel-project.test.ts
@@ -7,6 +7,7 @@ import { HumanActionRequiredError } from "#setup/human-action.js";
import type { Prompter, PrompterValue, SingleSelectOptions } from "./prompter.js";
import { createFakePrompter } from "#internal/testing/fake-prompter.js";
import { readProjectLink } from "./project-resolution.js";
+import { configureTraceSampling } from "./vercel-trace-sampling.js";
import {
assertNewProjectNameAvailable,
ensureLinkedVercelProject,
@@ -30,6 +31,8 @@ vi.mock("#setup/primitives/index.js", async (importOriginal) => {
};
});
+vi.mock("./vercel-trace-sampling.js", () => ({ configureTraceSampling: vi.fn() }));
+
vi.mock("./project-resolution.js", async (importOriginal) => {
const original = await importOriginal<typeof import("./project-resolution.js")>();
return {
@@ -40,6 +43,7 @@ vi.mock("./project-resolution.js", async (importOriginal) => {
const mockedCaptureVercel = vi.mocked(captureVercel);
const mockedRunVercel = vi.mocked(runVercel);
+const mockedConfigureTraceSampling = vi.mocked(configureTraceSampling);
const mockedReadProjectLink = vi.mocked(readProjectLink);
/** Wraps stdout as a successful capture result for the mocked `captureVercel`. */
@@ -71,6 +75,7 @@ beforeEach(() => {
mockedCaptureVercel.mockReset();
mockedRunVercel.mockReset();
mockedRunVercel.mockResolvedValue(true);
+ mockedConfigureTraceSampling.mockReset();
mockedReadProjectLink.mockReset();
});
@@ -702,7 +707,7 @@ describe("linkProject", () => {
)
.mockResolvedValueOnce(captured({ framework: "eve" }));
mockedReadProjectLink.mockResolvedValueOnce({
- orgId: "team-a",
+ orgId: "team_123",
projectId: "prj_new",
projectName: "my-agent",
});
@@ -714,6 +719,7 @@ 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);
@@ -731,8 +737,45 @@ describe("linkProject", () => {
["link", "--project", "my-agent", "--scope", "team-a", "--yes"],
expect.objectContaining({ cwd: "/tmp/eve-agent", nonInteractive: true }),
);
+ expect(mockedRunVercel).toHaveBeenCalledTimes(1);
+ expect(mockedConfigureTraceSampling).toHaveBeenCalledWith(
+ { orgId: "team_123", projectId: "prj_new", projectName: "my-agent" },
+ prompter,
+ undefined,
+ );
});
+ 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 },
+ ),
+ ).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
.mockResolvedValueOnce(
diff --git a/packages/eve/src/setup/vercel-project.ts b/packages/eve/src/setup/vercel-project.ts
index c79173c3e..bdd4f427e 100644
--- a/packages/eve/src/setup/vercel-project.ts
+++ b/packages/eve/src/setup/vercel-project.ts
@@ -32,6 +32,7 @@ import {
ensureCreatedProjectFramework,
type CreatedProjectFrameworkOptions,
} from "./vercel-project-framework.js";
+import { configureTraceSampling } from "./vercel-trace-sampling.js";
const VercelProjectReferenceSchema = z.object({
id: z.string().min(1),
@@ -54,7 +55,10 @@ export interface PickTeamOptions extends VercelProjectOperationOptions {
selectMessage?: (currentTeam: string) => string;
}
-export interface LinkProjectOperationOptions extends CreatedProjectFrameworkOptions {}
+export interface LinkProjectOperationOptions extends CreatedProjectFrameworkOptions {
+ /** Configure 100% trace sampling when creating a Vercel project. */
+ traceSampling?: boolean;
+}
/** Effects used to ensure an interactive Vercel project link. */
export interface EnsureLinkedVercelProjectDeps {
@@ -659,6 +663,8 @@ export async function linkProject(
if (!linked) return undefined;
const link = await readProjectLink(projectRoot);
if (link === undefined) return undefined;
+ if (options.traceSampling === true)
+ await configureTraceSampling(link, prompter, options.signal);
await ensureCreatedProjectFramework(
prompter,
projectRoot,
diff --git a/packages/eve/src/setup/vercel-trace-sampling.test.ts b/packages/eve/src/setup/vercel-trace-sampling.test.ts
new file mode 100644
index 000000000..945ff832f
--- /dev/null
+++ b/packages/eve/src/setup/vercel-trace-sampling.test.ts
@@ -0,0 +1,72 @@
+import { afterEach, beforeEach, expect, it, vi } from "vitest";
+
+import { readVercelCliToken } from "#internal/model-auth/vercel-cli.js";
+import { createFakePrompter } from "#internal/testing/fake-prompter.js";
+
+import { configureTraceSampling } from "./vercel-trace-sampling.js";
+
+vi.mock("#internal/model-auth/vercel-cli.js", () => ({
+ readVercelCliToken: vi.fn(),
+}));
+
+const token = vi.mocked(readVercelCliToken);
+const link = { orgId: "team_123", projectId: "prj_new" };
+
+beforeEach(() => {
+ token.mockReset();
+ token.mockResolvedValue("vercel-token");
+});
+
+afterEach(() => vi.unstubAllGlobals());
+
+it.each([200, 204])("accepts a successful PUT with status %i", async (status) => {
+ const fetchMock = vi.fn(async () => new Response(status === 204 ? null : "{}", { status }));
+ vi.stubGlobal("fetch", fetchMock);
+ const { prompter } = createFakePrompter();
+
+ await configureTraceSampling(link, prompter);
+
+ expect(fetchMock).toHaveBeenCalledWith(
+ "https://api.vercel.com/v1/drains/tracing/config?projectId=prj_new&teamId=team_123",
+ expect.objectContaining({
+ body: JSON.stringify({
+ enabled: true,
+ sampling: [{ type: "head_sampling", rate: 1 }],
+ }),
+ headers: {
+ authorization: "Bearer vercel-token",
+ "content-type": "application/json",
+ },
+ method: "PUT",
+ redirect: "error",
+ signal: expect.any(AbortSignal),
+ }),
+ );
+ expect(prompter.log.warning).not.toHaveBeenCalled();
+});
+
+it("warns but does not fail when Vercel rejects the PUT", async () => {
+ vi.stubGlobal(
+ "fetch",
+ vi.fn(async () => new Response(null, { status: 403 })),
+ );
+ const { prompter } = createFakePrompter();
+
+ await configureTraceSampling(link, prompter);
+
+ expect(prompter.log.warning).toHaveBeenCalledWith(
+ expect.stringContaining("100% for all environments"),
+ );
+});
+
+it("warns if no token is available without attempting a PUT", async () => {
+ token.mockResolvedValue(undefined);
+ const fetchMock = vi.fn();
+ vi.stubGlobal("fetch", fetchMock);
+ const { prompter } = createFakePrompter();
+
+ await configureTraceSampling(link, prompter);
+
+ expect(fetchMock).not.toHaveBeenCalled();
+ expect(prompter.log.warning).toHaveBeenCalledOnce();
+});
diff --git a/packages/eve/src/setup/vercel-trace-sampling.ts b/packages/eve/src/setup/vercel-trace-sampling.ts
new file mode 100644
index 000000000..58bad6770
--- /dev/null
+++ b/packages/eve/src/setup/vercel-trace-sampling.ts
@@ -0,0 +1,47 @@
+import { readVercelCliToken } from "#internal/model-auth/vercel-cli.js";
+
+import type { VercelProjectReference } from "./project-resolution.js";
+import type { Prompter } from "./prompter.js";
+
+const AGENT_PROJECT_TRACING_SAMPLING = [{ type: "head_sampling", rate: 1 }] as const;
+
+export async function configureTraceSampling(
+ link: VercelProjectReference,
+ prompter: Pick<Prompter, "log">,
+ signal?: AbortSignal,
+): Promise<void> {
+ try {
+ const token = await readVercelCliToken();
+ if (token === undefined) throw new Error("Vercel CLI credentials are unavailable.");
+ const tracingQuery = new URLSearchParams({
+ projectId: link.projectId,
+ teamId: link.orgId,
+ });
+ const response = await fetch(
+ `https://api.vercel.com/v1/drains/tracing/config?${tracingQuery.toString()}`,
+ {
+ body: JSON.stringify({
+ enabled: true,
+ sampling: AGENT_PROJECT_TRACING_SAMPLING,
+ }),
+ headers: {
+ authorization: `Bearer ${token}`,
+ "content-type": "application/json",
+ },
+ method: "PUT",
+ redirect: "error",
+ signal: signal
+ ? AbortSignal.any([signal, AbortSignal.timeout(15_000)])
+ : AbortSignal.timeout(15_000),
+ },
+ );
+ if (!response.ok) {
+ throw new Error("Vercel rejected the trace sampling configuration.");
+ }
+ } catch {
+ signal?.throwIfAborted();
+ prompter.log.warning(
+ "The Vercel project was created, but trace sampling could not be configured. Set it to 100% for all environments in the Vercel project settings.",
+ );
+ }
+}