Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddTracingToClient ¶ added in v2.8.0
AddTracingToClient wraps the net/http.Client to automatically create child-spans, and append to HTTP Headers.
Example ¶
package main import ( "context" "net/http" "time" datadogMiddleware "github.com/coopnorge/go-datadog-lib/v2/middleware/http" "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer" ) func main() { ctx := context.Background() client := &http.Client{ Timeout: 10 * time.Second, } client = datadogMiddleware.AddTracingToClient(client) span, ctx := tracer.StartSpanFromContext(ctx, "http.request") defer span.Finish() req, err := http.NewRequestWithContext(ctx, "GET", "https://example.com", nil) if err != nil { span.Finish(tracer.WithError(err)) panic(err) } resp, err := client.Do(req) if err != nil { span.Finish(tracer.WithError(err)) panic(err) } println(resp) }
Output:
func WrapClient
deprecated
Types ¶
type Option ¶ added in v2.8.0
type Option func(cfg *config)
Option allows for overriding our default-config.
func WithCustomTag ¶ added in v2.8.0
WithCustomTag will attach the value to the span tagged by the key.
func WithRequestIgnorer ¶ added in v2.8.0
func WithRequestIgnorer(requestIgnorer RequestIgnorer) Option
WithRequestIgnorer specifies a function that will be called to determined if the request should be traced or not.
func WithResourceNamer ¶ added in v2.8.0
func WithResourceNamer(resourceNamer ResourceNamer) Option
WithResourceNamer specifies a function that will be called to determine what the ResourceName of the span should be. For example, in the span "http.client https://coop.no/", the ResourceName is "https://coop.no/"
func WithServiceName ¶ added in v2.8.0
WithServiceName overrides the service-name set in environment-variable "DD_SERVICE".
type RequestIgnorer ¶ added in v2.8.0
RequestIgnorer is a function that will be called to determine if the request should be traced or not.
type ResourceNamer ¶ added in v2.8.0
ResourceNamer is a function that will be called to determine what the ResourceName of the span should be.
func FullURLResourceNamer ¶ added in v2.8.0
func FullURLResourceNamer() ResourceNamer
FullURLResourceNamer will name the ResourceName to "GET https://www.coop.no/api/some-service/some-endpoint" NOTE! This might leak unintended user-ids, if they are part of the URL-path.
func FullURLWithParamsResourceNamer ¶ added in v2.8.0
func FullURLWithParamsResourceNamer() ResourceNamer
FullURLWithParamsResourceNamer will name the ResourceName to "GET https://www.coop.no/api/some-service/some-endpoint?foo=bar" NOTE! This might leak unintended user-ids, credentials, or other things that are part of a URL.
func HostResourceNamer ¶ added in v2.8.0
func HostResourceNamer() ResourceNamer
HostResourceNamer will name the ResourceName to "www.coop.no"
func StaticResourceNamer ¶ added in v2.8.0
func StaticResourceNamer(str string) ResourceNamer
StaticResourceNamer will set every span's ResourceName to str.