Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RequestWithClientTrace ¶
RequestWithClientTrace adds httptrace.ClientTrace instrumentation into the request if there is an OpenTelemetry trace.Span previously registered in the request Context. This is modeled after the Zipkin transport tracing: https://github.com/openzipkin/zipkin-go/blob/v0.2.5/middleware/http/transport.go#L165
func Transport ¶
func Transport(rt http.RoundTripper) http.RoundTripper
Transport creates an http transport that will automatically trace all requests if there is an OpenTelemetry trace.Span previously registered in the request Context.
Example ¶
package main
import (
"fmt"
"net/http"
"github.com/coryb/otelhttptrace"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
)
func main() {
client := &http.Client{
Transport: otelhttp.NewTransport(
otelhttptrace.Transport(http.DefaultTransport),
otelhttp.WithSpanNameFormatter(func(_ string, req *http.Request) string {
return fmt.Sprintf("%s %s", req.Method, req.URL.Path)
}),
),
}
resp, err := client.Get("https://github.com")
if err != nil {
panic(fmt.Sprintf("Failed to GET https://github.com %q", err))
}
defer resp.Body.Close()
fmt.Printf("Got %s", resp.Status)
}
Output: Got 200 OK
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.