otelstack

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2025 License: MIT Imports: 8 Imported by: 0

README

OTEL TestContainer stack for go

godoc license Build Status Go Coverage

Package otelstack provides a full OTEL collector and receiver clients conveniently contained within testcontainers. It removes the hassle of managing inter-container communication, has built in querying for validating your tests, and uses lightweight services (seq and Jaeger) to keep startup time low.

Usage

stack := New()
shutdownFunc, err := stack.Start(t.Context())
require.NotNil(t, err, "the stack must start up")

// be sure to defer shutdown of the stack
t.Cleanup(func() {
  if err := shutdownFunc(context.Background()); err != nil {
    t.Logf("error shutting down stack: %v", err)
  }
})

// For optionally setting OTEL_EXPORTER_OTLP_ENDPOINT
stack.SetTestEnv(t)

// ports can be accessed as such
t.Logf("Seq ui: http://localhost:%d", stack.Seq.Ports[80].Int())
t.Logf("Jaeger ui: http://localhost:%d", stack.Seq.Ports[16686].Int())

// Continue to initialise your own otel setup here
...

// Get traces from Jaeger
  traces, err := stack.Jaeger.GetTraces(5, serviceName)
  require.NoError(t, err, "must be able to get traces")
  assert.Equal(t, "test-segment", traces.Data[0].Spans[0].OperationName)

  // Get log events from Seq
  events, err := stack.Seq.GetEvents(5)
  require.NoError(t, err)
  assert.Equal(t, "test message", events[0].MessageTemplateTokens[0].Text)


TODO

  • Add metrics to stack (prometheus, but maybe grafana?)
  • Increase test coverage

Documentation

Overview

Package otelstack provides a full OTEL collector and receiver clients conveniently contained within testcontainers. It removes the hassle of managing inter-container communication, has built in querying for validating your tests, and uses lightweight services (seq and Jaeger) to keep start time low.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Stack added in v1.0.4

type Stack struct {
	Collector collector.Collector
	Jaeger    jaeger.Jaeger
	Seq       seq.Seq
}

Stack holds structs containing to all the testcontainers.

func New

func New() *Stack

New creates a new Stack and populates it with child container structs.

func (*Stack) SetTestEnvGRPC added in v1.0.4

func (s *Stack) SetTestEnvGRPC(t *testing.T)

SetTestEnvGRPC sets the environment variableOTEL_EXPORTER_OTLP_ENDPOINT to the gRPC endpoint.

func (*Stack) SetTestEnvHTTP added in v1.0.4

func (s *Stack) SetTestEnvHTTP(t *testing.T)

SetTestEnvHTTP sets the environment variableOTEL_EXPORTER_OTLP_ENDPOINT to the HTTP endpoint

func (*Stack) Start added in v1.0.4

func (s *Stack) Start(ctx context.Context) (func(context.Context) error, error)

Start creates a testcontainer network and starts up all the child containers.

Directories

Path Synopsis
Package collector holds the resources needed to start an OTEL collector testcontainer
Package collector holds the resources needed to start an OTEL collector testcontainer
Package jaeger holds the resources needed to start a Jaeger testcontainer container.
Package jaeger holds the resources needed to start a Jaeger testcontainer container.
Package seq holds the resources needed to start a Seq testcontainer.
Package seq holds the resources needed to start a Seq testcontainer.

Jump to

Keyboard shortcuts

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