Skip to main content

How Environments Work

1

Set environment via environment variable or SDK

Configure the environment using the ABV_TRACING_ENVIRONMENT environment variable (recommended) or the environment parameter during client initialization. Common values: production, staging, development, dev.
.env
ABV_TRACING_ENVIRONMENT=production
2

All events tagged with environment

Once configured, every trace, observation (span/event/generation), score, and session automatically includes the environment attribute. This happens transparently without code changes.
3

Filter by environment in the ABV UI

Use the environment filter in the ABV dashboard navigation bar to switch between environments. The filter applies across all views, showing only events from the selected environment.
4

Analyze metrics by environment

Compare performance, costs, and error rates between environments. Identify staging vs production differences. Track environment-specific trends over time.
5

Reuse prompts and datasets across environments

Create prompts in staging, test them thoroughly, then use the same prompts in production. Share datasets between environments while keeping traces separate.

Why Use Environments?

The Challenge: Your team has 10 developers running code locally, 3 staging deployments for different features, and 1 production deployment. All traces flow into the same ABV project, creating chaos in your dashboard.The Solution: Set environment variables per deployment context.Locally (.env.local):
ABV_TRACING_ENVIRONMENT=dev
Staging (Kubernetes/Docker):
ABV_TRACING_ENVIRONMENT=staging
Production (Kubernetes/Docker):
ABV_TRACING_ENVIRONMENT=production
The Result: Production dashboard shows only real user traffic. Developers can experiment freely in dev without polluting production data. Staging provides a clean pre-production testing ground.Operational benefit: On-call engineers filter to production and see only what matters. No false alarms from dev experiments or staging tests.
The Challenge: You’re deploying a new RAG implementation that changes how documents are chunked. It might improve accuracy or it might break everything. You need to validate before exposing to customers.The Solution: Deploy the change to staging first with environment separation.
# This runs in staging with ABV_TRACING_ENVIRONMENT=staging
@observe()
def process_document_v2(doc):
    # New chunking logic
    chunks = new_chunking_strategy(doc)
    abv.update_current_trace(metadata={"chunking": "v2"})
    return chunks
The Result:
  1. Deploy to staging, generate traces tagged staging
  2. Analyze staging performance, accuracy, cost
  3. Compare staging metrics to production baseline
  4. If good, deploy to production with confidence
  5. If issues found, fix in staging first
Best practice: Keep staging as production-like as possible (same models, similar data volume) so staging results predict production behavior accurately.
The Challenge: Customer support forwards a bug report: β€œThe LLM isn’t working.” You need to know: Is this production? Staging? Someone’s local dev environment? Without context, you can’t prioritize or debug effectively.The Solution: Every trace includes environment information, visible in the UI and queryable via API.The Result:
  • See environment: production β†’ drop everything, production is down
  • See environment: staging β†’ important but not urgent, investigate during business hours
  • See environment: dev β†’ probably a developer debugging, low priority
Communication benefit: When asking for help, developers can say β€œcheck trace XYZ in staging” and everyone knows exactly where to look. No ambiguity.
Filter cost dashboards by environment to identify spending on non-production workloads.Example breakdown:
  • Production: 70% (real customer value)
  • Staging: 25% (integration tests, load tests)
  • Dev: 5% (developer experiments)
Optimization: Identify expensive staging tests using premium models and switch to cheaper alternatives for testing.
The Challenge: Your compliance team asks: β€œCan you prove that customer PII is only processed in production, never in development?” Without environment separation, this is nearly impossible to demonstrate.The Solution: Use environments to create clear separation boundaries.
import os

ENVIRONMENT = os.getenv("ABV_TRACING_ENVIRONMENT", "dev")

@observe()
def process_customer_data(customer_id, pii_data):
    if ENVIRONMENT != "production":
        raise ValueError("PII processing only allowed in production")

    # Process PII only in production environment
    # All traces tagged with environment=production
The Result: Audit logs show PII traces exist only in production environment. Development and staging use synthetic data only. Clear compliance demonstration.Bonus: Combine with RBAC to restrict who can view production traces containing sensitive data.
The Challenge: You’ve crafted the perfect prompt in staging after days of iteration. Now you need to use the exact same prompt in production. Manually copying risks errors and version drift.The Solution: ABV prompts and datasets are shared across environments within a project. Create in staging, reference by name in production.Staging (create prompt):
# Iterate and refine prompt in staging
abv.create_prompt(
    name="customer-support-v2",
    template="You are a helpful customer support agent..."
)
Production (use same prompt):
# Use the same prompt in production
prompt = abv.get_prompt("customer-support-v2")
response = llm.complete(prompt.render(context=user_query))
The Result: Prompts tested in staging work identically in production. Version control ensures consistency. Test thoroughly before production rollout.

Implementation Guide

Installation:
pip install abvdev python-dotenv
Environment naming rules:
  • Must match regex: ^(?!abv)[a-z0-9-_]+$
  • Cannot start with β€œabv”
  • Only lowercase letters, numbers, hyphens, underscores
  • Maximum 40 characters
  • Examples: production, staging, dev, local, qa-team-1
See Python SDK docs for more details.
Installation:
npm install @abvdev/tracing @abvdev/otel @opentelemetry/sdk-node dotenv
See JS/TS SDK docs for complete reference.
When using OpenTelemetry directly, ABV recognizes these attributes for environment:
  • abv.environment (recommended)
  • deployment.environment.name
  • deployment.environment
Set environment globally for all spans using resource attributes:
import os
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.resources import Resource
from abvdev import ABV

# Set environment via resource attributes
os.environ["OTEL_RESOURCE_ATTRIBUTES"] = "abv.environment=staging"

# Initialize tracer provider
resource = Resource.create({"abv.environment": "staging"})
provider = TracerProvider(resource=resource)
trace.set_tracer_provider(provider)

# Initialize ABV
abv = ABV(
    api_key="sk-abv-...",
    host="https://app.abv.dev"
)

# All spans automatically tagged with environment=staging
tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span("my-operation") as span:
    # Your code here
    pass

abv.flush()
See OpenTelemetry Integration for more details.

Filtering & Analysis

UI Filtering

In the ABV dashboard, use the environment filter in the navigation bar to switch between environments. The filter applies across:
  • Traces list
  • Sessions view
  • Scores and evaluations
  • Custom dashboards
  • Analytics and metrics

API Filtering

Filter by environment when querying the ABV API:
curl https://app.abv.dev/api/v1/traces?environment=production \
  -H "Authorization: Bearer sk-abv-..."
See API Reference for complete filtering options.

Best Practices

Use environment variables for configuration. Set ABV_TRACING_ENVIRONMENT via environment variables rather than hardcoding in your application. This prevents accidentally deploying wrong environment settings and follows 12-factor app principles.
Establish naming conventions early. Decide on environment names (production vs prod, development vs dev) and document them for your team. Consistency prevents filtering confusion.
Don’t use environments for multi-tenancy. Environments are for deployment contexts (dev/staging/prod), not for separating customer data. Use metadata or separate ABV projects for multi-tenant isolation.
Keep staging production-like. Configure staging with the same models, similar data volumes, and realistic workloads. The more staging resembles production, the more valuable its testing becomes.
Default environment: If no environment is specified, ABV uses default as the environment name. Explicitly set environments even in development to avoid mixing default data from different contexts.

Environments vs Tags vs Metadata

Choosing the right feature:
FeatureBest ForExample Use Cases
EnvironmentsDeployment contexts with formal separationproduction, staging, development
TagsSimple categorization, experiments, filteringrag, beta, few-shot, v2.1.0
MetadataStructured data, detailed attributes{"tenant_id": "acme", "user_tier": "premium"}
When to use together:
  • Set environment to production AND use tags like beta for gradual feature rollouts
  • Set environment to staging AND use metadata for detailed test scenario tracking
  • All traces should have an environment, most will have metadata, many will have tags