Skip to main content
When your app runs on Vercel, AgentMark attributes its traces to the right environment automatically: a Production deployment to your promoted environment, and each Preview deployment to that pull request’s preview environment. The environment selector isn’t a secret, so the SDK derives it from the git context Vercel already exposes rather than injecting it per deployment.

Automatic environment derivation

@agentmark-ai/sdk’s initTracing() reads Vercel’s system environment variables and picks the target environment for you. A Vercel deploy needs no selector configuration.
VERCEL_ENVSignalTraces attributed to
previewAn open pull request (VERCEL_GIT_PULL_REQUEST_ID)That PR’s preview environment
previewA branch deploy with no open PRAn environment named after the branch ref
development(none)The dev environment
production(none)The key’s pinned or promoted environment
The derived selector is the lowest-precedence source. An explicit initTracing({ environment, prNumber }) option, or the AGENTMARK_ENVIRONMENT / AGENTMARK_PR_NUMBER environment variables, override it. See Attributing traces to an environment.

What the deployment needs

For derivation to authorize the right environment, the deployment’s AGENTMARK_API_KEY should be a key scoped to environment kinds (with Preview included, and Production if production traces should flow), not a key pinned to a single environment. A kind-scoped key lets the SDK select the target per request, and the gateway authorizes the derived environment against the key’s allowed kinds. See API key environment scope. Set these on the Vercel project (the same three values the SDK and client read everywhere):
  • AGENTMARK_API_KEY, a kind-scoped key (Preview, plus Production if needed).
  • AGENTMARK_APP_ID.
  • AGENTMARK_BASE_URL, the gateway URL.
These values don’t vary per deployment; only the derived selector does.
A one-click Vercel Marketplace connect that writes these three values into your Vercel project for you isn’t available yet. Until it ships, set the three variables in the Vercel project’s environment-variable settings yourself. The SDK already ships the automatic environment derivation described above, so it works as soon as you set those variables.

Have questions?

Reach out any time: