owe

package module
v0.0.0-...-6362b4b Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 3 Imported by: 2

README

OpenTelemetry Wide Events for Go

OpenTelemetry makes it easy to retrieve the current span stored in context.

span := trace.SpanFromContext(ctx)

With the notion of Wide Events originally introduces by Charity Majors, you will also want to retrieve that main span all the time.

And yet, if a child span has been created, you will retrieve that new span and not the wide event you expected.

This package allows you to define a wide event for a context, which will not change unless you manually do so. You can then retrieve the proper main span all the time, even if child spans were created.

span := owe.SpanFromContext(ctx)

diagram

Usage

In order to have a span to retrieve, one needs to be added to the context.

You can do that manually with the ContextWithSpan method:

ctx := owe.ContextWithSpan(ctx, span)

Or you can use one of the provided handlers that will automatically create a wide event span.

net/http

The owehttp package allows setting wide events for HTTP servers.

handler := func(http.ResponseWriter, *http.Request) {
	// the HTTP handler sets my app's behavior
	event := owe.SpanFromContext(r.Context())
}

endpoint := otelhttp.NewHandler(owe.NewHandler(handler), "otelhttp")
server := &http.Server{
	Handler: endpoint,
}
log.Fatal(server.ListenAndServe())
gRPC

The owegrpc package allows setting wide events for gRPC servers.

s := grpc.NewServer(
		grpc.StatsHandler(otelgrpc.NewServerHandler()),
		grpc.StatsHandler(owegrpc.NewHandler()),
)

// Register your gRPC services

if err := s.Serve(lis); err != nil {
	log.Fatalf("failed to serve: %v", err)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithSpan

func ContextWithSpan(parent context.Context, span trace.Span) context.Context

ContextWithSpan returns a copy of parent with span set as the current Span.

func SpanFromContext

func SpanFromContext(ctx context.Context) trace.Span

SpanFromContext returns the current Span from ctx.

If no Span is currently set in ctx an implementation of a Span that performs no operations is returned.

Types

This section is empty.

Directories

Path Synopsis
owegrpc module
owehttp module

Jump to

Keyboard shortcuts

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