owehttp

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: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandler

func NewHandler(next http.Handler) http.Handler
Example
package main

import (
	"io"
	"log"
	"net/http"

	"github.com/dmathieu/owe"
	"github.com/dmathieu/owe/owehttp"
	"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
	"go.opentelemetry.io/otel/attribute"
)

func main() {
	helloHandler := func(w http.ResponseWriter, req *http.Request) {
		// Always retrieve the wide event span, which was defined by the otelhttp
		// middleware.
		span := owe.SpanFromContext(req.Context())
		// Wide event spans are meant to hold lots of attributes. So let's add some
		// data to it!
		span.SetAttributes(attribute.String("user.id", "42"))

		_, _ = io.WriteString(w, "Hello, world!\n")
	}

	handler := otelhttp.NewHandler(
		owehttp.NewHandler(
			http.HandlerFunc(helloHandler),
		), "Hello")

	http.Handle("/hello", handler)
	err := http.ListenAndServe(":7777", nil)
	if err != nil {
		log.Fatal(err)
	}
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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