Skip to content

Tracing: Allow programmatic configuration of OpenTelemetry tracer #213

@drewdrewthis

Description

@drewdrewthis

Problem

The scenario SDK sets up OpenTelemetry observability at module import time in src/tracing/setup.ts:

const envConfig = getEnv();

export const observabilityHandle = setupObservability({
  langwatch: {
    apiKey: envConfig.LANGWATCH_API_KEY,
    endpoint: envConfig.LANGWATCH_ENDPOINT,
  },
  spanProcessors: [judgeSpanCollector],
});

This means:

  1. The tracer is configured once at import time using env vars
  2. The programmatic RunOptions.langwatch config only affects the EventBus for scenario events
  3. OpenTelemetry traces/spans are sent to the env var endpoint, not the project-specific endpoint

Impact

When running scenarios for multiple projects (e.g., in the LangWatch server), traces will all go to the same endpoint instead of each project's endpoint. The scenario events work correctly since they use the programmatic config via EventBus.

Proposed Solution

Allow the tracer to be configured per-run:

// Option 1: Pass langwatch config to ScenarioExecution
const execution = new ScenarioExecution(cfg, steps, batchRunId, {
  langwatch: options?.langwatch,
});

// Option 2: Create a scoped tracer per execution
const tracer = createScopedTracer({
  apiKey: options?.langwatch?.apiKey,
  endpoint: options?.langwatch?.endpoint,
});

Files Affected

  • src/tracing/setup.ts
  • src/execution/scenario-execution.ts
  • src/runner/run.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions