hyperhttp

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 License: Apache-2.0 Imports: 3 Imported by: 1

README

goagent for net/http

Getting started

HTTP server

The server instrumentation relies on the http.Handler component of the server declarations.

import (
    "net/http"

    "github.com/gorilla/mux"
    "github.com/hypertrace/goagent/instrumentation/net/hyperhttp"
    "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
)

func main() {
    // ...

    r := mux.NewRouter()
    r.Handle("/foo/{bar}", otelhttp.NewHandler(
        hyperhttp.WrapHandler(fooHandler),
        "/foo/{bar}",
    ))

    // ...
}
HTTP client

The client instrumentation relies on the http.Transport component of the HTTP client in Go.

import (
    "net/http"
    "github.com/hypertrace/goagent/instrumentation/net/hyperhttp"
    "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
)

// ...

client := http.Client{
    Transport: otelhttp.NewTransport(
        hyperhttp.WrapDefaultTransport(),
        ...
    ),
}

req, _ := http.NewRequest("GET", "http://example.com", nil)

res, err := client.Do(req)

// ...

Running example

In terminal 1 run

make run-http-server-example

In terminal 2 run

make run-http-client-example

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WrapHandler

func WrapHandler(delegate http.Handler, options *sdkhttp.Options) http.Handler

WrapHandler returns a new round tripper instrumented that relies on the needs to be used with OTel instrumentation.

func WrapTransport

func WrapTransport(delegate http.RoundTripper) http.RoundTripper

WrapTransport wraps an uninstrumented RoundTripper (e.g. http.DefaultTransport) and returns an instrumented RoundTripper that has to be used as base for the OTel's RoundTripper.

Types

This section is empty.

Jump to

Keyboard shortcuts

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