
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
github.com/pinpoint-apm/pinpoint-go-agent/plugin/http
Package pphttp instruments servers and clients that use net/http package.
$ go get github.com/pinpoint-apm/pinpoint-go-agent/plugin/http
import "github.com/pinpoint-apm/pinpoint-go-agent/plugin/http"
This package instruments inbound requests handled by a http.ServeMux. Use NewServeMux to trace all handlers:
mux := pphttp.NewServeMux()
mux.HandleFunc("/bar", outGoing)
Use WrapHandler or WrapHandlerFunc to select the handlers you want to track:
http.HandleFunc("/", pphttp.WrapHandlerFunc(index))
For each request, a pinpoint.Tracer is stored in the request context. By using the pinpoint.FromContext function, this tracer can be obtained in your handler. Alternatively, the context of the request may be propagated where the context that contains the pinpoint.Tracer is required.
package main
import (
"net/http"
"github.com/pinpoint-apm/pinpoint-go-agent"
"github.com/pinpoint-apm/pinpoint-go-agent/plugin/http"
)
func outGoing(w http.ResponseWriter, r *http.Request) {
tracer := pinpoint.FromContext(r.Context())
ctx := pinpoint.NewContext(context.Background(), tracer)
// or ctx := r.Context()
client := pphttp.WrapClientWithContext(ctx, &http.Client{})
resp, err := client.Get("http://localhost:9000/async_wrapper?foo=bar&say=goodbye")
...
}
func main() {
//setup agent
opts := []pinpoint.ConfigOption{
pinpoint.WithConfigFile(os.Getenv("HOME") + "/tmp/pinpoint-config.yaml"),
}
cfg, err := pinpoint.NewConfig(opts...)
agent, err := pinpoint.NewAgent(cfg)
defer agent.Shutdown()
mux := pphttp.NewServeMux()
mux.HandleFunc("/bar", outGoing)
http.ListenAndServe("localhost:8000", mux)
}
This package supports URL Statistics feature. It aggregates response times, successes and failures for each router pattern. But, WrapHandler and WrapHandlerFunc function doesn't support URL Statistics feature.
This package instruments outbound requests and add distributed tracing headers. Use WrapClient, WrapClientWithContext or DoClient.
client := pphttp.WrapClient(&http.Client{})
client.Get(external_url)
req, _ := http.NewRequestWithContext(ctx, "GET", url, nil)
pphttp.DoClient(http.DefaultClient.Do, req)
It is necessary to pass the context containing the pinpoint.Tracer to the http.Request.
import (
"net/http"
"github.com/pinpoint-apm/pinpoint-go-agent"
"github.com/pinpoint-apm/pinpoint-go-agent/plugin/http"
)
func wrapClient(w http.ResponseWriter, r *http.Request) {
req, _ := http.NewRequestWithContext(r.Context(), "GET", "http://localhost:9000/async", nil)
client := pphttp.WrapClient(&http.Client{})
resp, err := client.Do(req)
...
}
func main() {
... //setup agent
http.HandleFunc("/wrapclient", pphttp.WrapHandlerFunc(wrapClient))
http.ListenAndServe(":8000", nil)
}
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.