package
2.0.1+incompatible
Repository: https://github.com/accelbyte/go-restful-plugins.git
Documentation: pkg.go.dev

# README

Datadog Tracing

This package enables Datadog tracing in go-restful apps.

The Trace() filter function will automatically detect the trace in HTTP request header, if any, and generate trace for that request.

Usage

Importing

import "github.com/AccelByte/go-restful-plugins/pkg/apm/datadog"

Start the tracer

Important, Datadog tracer will not send any trace if not started. You only need to call this once.

datadog.Start("localhost:8126", "example-service", false)

Trace all endpoints

ws := new(restful.WebService)
ws.Filter(datadog.Trace)

Trace specific endpoint

ws := new(restful.WebService)
ws.Route(ws.GET("/user/{id}").
    Filter(datadog.Trace).
    To(func(request *restful.Request, response *restful.Response) {
}))

Inject trace header to outgoing request

To propagate trace into other services, instrument the request by injecting Datadog trace to the request.

outReq := httptest.NewRequest("GET", "localhost/example", nil)
Inject(outReq, request)
http.DefaultClient.Do(outReq)

# Functions

Inject adds tracer header to a HTTP request.
Start initiates the tracer.
Trace is a filter that will trace incoming request.