This is a settings
that
enables constructing an http client whose transport logs key HTTP
metrics with configurable names on every request. The resulting client
is powered by xstats
and
httpstats
.
package main
import (
"context"
"net/http"
"os"
"github.com/asecurityteam/component-httpstats"
"github.com/asecurityteam/transport"
"github.com/asecurityteam/settings/v2"
)
func main() {
ctx := context.Background()
os.SetEnv("METRICS_BACKEND", "testdependency")
envSource := settings.NewEnvSource(os.Environ())
client := &http.Client(
Transport: httpstats.New(ctx, envSource)(
transport.New(
transport.OptionMaxResponseHeaderBytes(4096),
transport.OptionDisableCompression(true)
)
)
)
req, _ := http.NewRequest(http.MethodGet, "www.google.com", http.NoBody)
// various HTTP metrics emitted and tagged with a "client_dependency"
// value of "testdependency", among other default tag keys and values
_, _ := client.Do(req)
}
This project is in incubation which means we are not yet operating this tool in production and the interfaces are subject to change.
We publish a docker image called SDCLI that bundles all of our build dependencies. It is used by the included Makefile to help make building and testing a bit easier. The following actions are available through the Makefile:
-
make dep
Install the project dependencies into a vendor directory
-
make lint
Run our static analysis suite
-
make test
Run unit tests and generate a coverage artifact
-
make integration
Run integration tests and generate a coverage artifact
-
make coverage
Report the combined coverage for unit and integration tests
This project is licensed under Apache 2.0. See LICENSE.txt for details.
Atlassian requires signing a contributor's agreement before we can accept a patch. If you are an individual you can fill out the individual CLA. If you are contributing on behalf of your company then please fill out the corporate CLA.