Skip to main content

Examples

A/B Testing Setup

This example demonstrates how to set up a simple A/B test where you route traffic to two different variants and track them as separate experiments.

Experiment Loop (Batch Evaluation)

Process multiple items under the same experiment. Each start_observe() call creates a separate trace automatically — the context manager cleans up OpenTelemetry context on exit, so the next iteration starts with a fresh trace_id.
Do not call basalt.shutdown() inside the loop or recreate the Basalt client per iteration. shutdown() permanently kills the global TracerProvider — all subsequent traces would be silently dropped.

Context Manager Usage

You can also use the context manager to wrap specific blocks of code with experiment context.