testopeninference

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2025 License: Apache-2.0 Imports: 33 Imported by: 0

README

OpenInference Test Support

This package provides OpenInference spans for testing AI Gateway's OpenTelemetry tracing implementation.

How It Works

  1. Cached spans: Pre-recorded spans are stored as JSON in the spans directory.
  2. Automatic recording: Missing spans are recorded using Docker when RECORD_SPANS=true
  3. OpenInference instrumentation: Uses the official Python OpenInference library to generate spans.
  4. OpenTelemetry collector: Spans are sent to an in-memory OTLP HTTP collector for validation and storage.

Usage

Choose an appropriate testopenai cassette, and get an OpenTelemetry span for it like this:

span, err := testopeninference.GetChatSpan(t.Context(), os.Stdout, testopenai.CassetteChatBasic)

Recording New Spans

You can record new spans for the following scenarios:

In any of these cases, you can backfill any missing spans like this:

RECORD_SPANS=true go test -v -run TestGetAllSpans

Any missing spans will be automatically recorded using a Docker container that runs the OpenAI Python SDK with OpenInference instrumentation.

Why is this needed?

This package bridges two open source communities:

  • Envoy AI Gateway, who are experts in GenAI routing and policy, and typically program in Go and C++.
  • OpenInference, who are experts in GenAI observability and typically program in Python and JavaScript.

As this project grows from dozens to hundreds of request shapes, it is important to have a standardized bridge between the two communities, so that troubleshooting or getting to the same page is easy.


Documentation

Overview

Package testopeninference provides OpenInference span recording and caching for testing AI Gateway's OpenTelemetry tracing implementation. It uses a similar pattern to testopenai but generates trace spans instead of serving API responses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSpan

func GetSpan(ctx context.Context, out io.Writer, cassette testopenai.Cassette) (*tracev1.Span, error)

GetSpan returns the OpenInference span for a given cassette. If the span doesn't exist in the cache, it records one using Docker.

func RequireSpanEqual

func RequireSpanEqual(t testing.TB, expected, actual *tracev1.Span)

RequireSpanEqual asserts that two spans are equal after normalizing variable fields like IDs, timestamps, and JSON formatting.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL