Datadog Go Orchestrion
Middleware supports the Orchestrion Datadog feature to ensure seamless tracing integration.
Install Orchestrion
To install and set up Orchestrion:
1 Install Orchestrion:
1go install github.com/DataDog/orchestrion@latest
Note: Ensure that $(go env GOBIN)
or $(go env GOPATH)/bin
is in your $PATH
.
2 Register Orchestrion in your project’s go.mod
:
1orchestrion pin
Refer to the output of orchestrion pin -help
for more information about available customization options.
3 Commit changes to your version control system (unless you are integrating orchestrion directly in your CI/CD pipeline):
1git add go.mod go.sum orchestrion.tool.go
2git commit -m "chore: enable orchestrion"
Now you can manage your dependency on orchestrion like any other dependency using the go.mod file.
Ship to Middleware
Add the following code to your main.go
file. This will send your traces directly to the middleware, enabling seamless monitoring and trace management:
1// customTransport adds custom headers to the HTTP requests
2type customTransport struct {
3 transport http.RoundTripper
4 headers map[string]string
5}
6
7func (c *customTransport) RoundTrip(req *http.Request) (*http.Response, error) {
8 // Add custom headers
9 for key, value := range c.headers {
10 req.Header.Set(key, value)
11 }
12 return c.transport.RoundTrip(req)
13}
14
15func main() {
16 //dd:ignore
17 headers := map[string]string{
18 "user-agent": "Datadog Trace Agent",
19 "dd-api-key": "YOUR_MIDDLEWARE_API_KEY",
20 }
21 // Create a custom HTTP client with the custom transport
22 defaultTransport := http.DefaultTransport.(*http.Transport).Clone()
23 customClient := &http.Client{
24 Transport: &customTransport{
25 transport: defaultTransport,
26 headers: headers,
27 },
28 Timeout: 10 * time.Second,
29 }
30
31 // Initialize the tracer with the custom HTTP client
32 tracer.Start(
33 tracer.WithHTTPClient(customClient),
34 )
35}
Replace "YOUR_MIDDLEWARE_API_KEY" with your actual API key in the dd-api-key header.
Usage
To enable Orchestrion during the build, run, or test processes, prepend Orchestrion to your usual Go commands:
1orchestrion go build .
2DD_TRACE_AGENT_URL=https://<MW_UID>.middleware.io:443 orchestrion go run .
3orchestrion go test ./...
Verifying Tracing
After completing the integration, you can verify that traces are being sent to the middleware by checking Middleware APM system.