Setting Up Datadog APM for Go - Orchestrion and Manual Instrumentation

For Datadog APM in Go, you choose between an approach in which Orchestrion writes instrumentation into your code and dependencies on every build, and one in which you call the dd-trace-go SDK yourself. Which one you choose changes how much you touch the code and how you run the go command.

In Go, First Decide Whether to Add Instrumentation at Build Time or Write It in Code

The official documentation shows two paths for adding Datadog APM to a Go app: compile-time instrumentation and manual instrumentation. In the former, a tool called Orchestrion writes instrumentation into the code during the build; in the latter, you build the dd-trace-go SDK and integration packages into your code yourself. The minimums listed for the tracer are Go 1.18 and Datadog Agent 5.21.1. On the other hand, the official policy is to fully support the two most recent Go releases. The third most recent release is treated as being in maintenance (as of October 2026; source: Tracing Go Applications / Go Compatibility Requirements).

Differences between the two kinds of Go instrumentation
AspectCompile-time (Orchestrion)Manual (SDK and integration packages)
Scope of instrumentationAll of your own code and dependencies (including the standard library)Libraries into which you built integration packages, and the parts you wrote yourself
Source code changesNot neededNeeded
How the build changesInsert Orchestrion into the go commandNo change
Advantages listed in the official documentationPrevents gaps in instrumentation and is easy to build into the CI/CD stageLets you decide in detail what to trace
Source: Tracing Go Applications

The deciding factors when choosing are two: whether you can change the build steps, and whether you can modify the code. Exploit Prevention in App and API Protection is also listed as a feature available only on the Orchestrion side. Orchestrion assumes an app managed with go modules, also supports vendoring, and likewise supports the two most recent Go releases, in line with Go's official release policy. As one way to proceed, start with Orchestrion if your own team can change the CI build, and with manual instrumentation if another team owns the build. The overall picture of APM is in the APM explanation, and where Exploit Prevention fits is in the App and API Protection explanation.

Register Orchestrion in go.mod and Put It in Front of the go Command

Preparing Orchestrion takes three steps. Install the tool with go install, run orchestrion pin in the project to register it in go.mod, and commit the changed go.mod / go.sum / orchestrion.tool.go to version control. If you build it directly into CI/CD, you can skip the commit. So that you can call the installed tool, include $(go env GOBIN) or $(go env GOPATH)/bin in PATH (as of October 2026; source: Tracing Go Applications). You can choose from the following three ways to insert it into the build.

orchestrion go build .
go build -toolexec="orchestrion toolexec" .
export GOFLAGS="${GOFLAGS} '-toolexec=orchestrion toolexec'"
Three ways to insert Orchestrion into the build (situations are examples)
FormWhat changesExample of a suitable situation
orchestrion go …The start of the go commandTrying it locally, rewriting one line of a Makefile
The -toolexec argumentThe arguments of the go commandBuild arguments are assembled in one place
The GOFLAGS environment variableThe build environmentYou want to change only the environment without touching the go command line
Source: Tracing Go Applications

There is a note that when adding it to GOFLAGS, you should quote it exactly as in the example so that the Go toolchain reads it correctly. The examples in the official documentation list three commands, build / run / test, and you use the same form for running tests too. After registering it in go.mod, you can manage Orchestrion in go.mod like any other dependency. For the Dockerfile when building a container image, the official documentation has a separate guide for Orchestrion.

Adjust the Scope of Instrumentation with Comment Directives and orchestrion.tool.go

With special comments written in the source, you can add or remove Orchestrion's instrumentation. Writing //dd:span immediately before a function automatically creates a span around that function, and you can pass tags as well, as in custom_tag:tag_value. The same form also works on function literals. Conversely, Orchestrion makes no changes at all to code marked with //orchestrion:ignore (as of October 2026; source: Tracing Go Applications).

  • The operation name (span.name) is the value of the span.name: tag if the directive's arguments include one
  • Otherwise, the function's declared name (this does not apply to unnamed function literals)
  • Failing that, the value of the first tag in the directive's arguments
  • When the function returns an error, the returned error is automatically attached to the span
Source: Tracing Go Applications

//orchestrion:ignore applies only to instrumentation added on the calling side; instrumentation added inside dependency libraries cannot be removed from your own code. When you want to remove it per library, rewrite the imports in orchestrion.tool.go. By default it contains an import that loads every library that has an Orchestrion integration, and replacing it with imports for only the integrations you use also reduces the transitive dependencies of integrations you do not use. In that case, you need to update this file yourself each time you add an integration. Frameworks that Orchestrion does not yet support can be instrumented by using the SDK alongside it in the same app. However, the official documentation warns that spans may be duplicated in the future as Orchestrion's support expands, and recommends reading the release notes when you upgrade the orchestrion dependency.

Manual Instrumentation Starts with tracer.Start and defer tracer.Stop

In manual instrumentation, you first start the SDK in the main function and stop it when the program ends. When stopped, the SDK sends everything it has buffered locally to the Agent, so the example in the official documentation says to keep defer tracer.Stop() in main. There is also the case where the program is stopped by SIGTERM, as with a Kubernetes container. For that case, a form that receives the signal and explicitly calls tracer.Stop() is also shown (as of October 2026; source: Configuring the Go SDK).

tracer.Start(
    tracer.WithEnv("prod"),
    tracer.WithService("test-go"),
    tracer.WithServiceVersion("abc123"),
)
defer tracer.Stop()
  • Import the SDK and put tracer.Start at the beginning of main
  • Put defer tracer.Stop() in the same main
  • Choose and import the integration packages that match the frameworks and libraries you use from the compatibility table
  • Build them in following the setup steps in each integration's entry
Source: Tracing Go Applications / Go Compatibility Requirements

Spans are created by the integration packages, and the v2 tab of the compatibility table lists frameworks such as Gin, Gorilla Mux, gRPC, chi, echo, and Fiber. The documentation says the supported frameworks changed between v1 and v2, so read the table on the tab for the version you use. The official documentation recommends v2 for everyone, and the steps for upgrading from v1 are collected, together with the rewriting tool v2fix, in Migrate to Go Tracer v2.

Pass Tags and the Destination Through Runtime Environment Variables

For the three tags env / service / version, the form Datadog recommends with either kind of instrumentation is to set DD_ENV / DD_SERVICE / DD_VERSION in the app's runtime environment. The Orchestrion steps emphasize setting them in the runtime environment, not at build time. With manual instrumentation, you can also pass the same tags as startup options. These environment variables are available from Go tracer 1.24.0 (as of October 2026; source: Configuring the Go SDK).

How to pass the three tags
TagRuntime environment variableStartup option for manual instrumentation
envDD_ENVtracer.WithEnv
serviceDD_SERVICEtracer.WithService
versionDD_VERSIONtracer.WithServiceVersion
Source: Configuring the Go SDK

The destination is determined by DD_AGENT_HOST and DD_TRACE_AGENT_PORT. If you set DD_TRACE_AGENT_URL, available from SDK v2.6.0, it takes precedence over those two. Apps built with Orchestrion also include profiler instrumentation, and setting DD_PROFILING_ENABLED=true at runtime enables the Continuous Profiler. How to decide whether the destination should be an Agent on the same host or a separate container is covered in the section on where data is sent in the Python setup. The meaning of the three tags is in the unified service tagging explanation.

You Can Keep the Source Orchestrion Rewrote Locally with the -work Flag

Because Orchestrion rewrites the source during the build, a way to check with your own eyes what went in is provided. Adding -work, as in orchestrion go build -work ./..., makes the go toolchain keep its working directory instead of deleting it, and its location is shown as WORK= at the start of the build. The rewritten files are placed in orchestrion/src in each package's stage directory. When the import configuration was changed, the original file remains with the .original suffix (as of October 2026; source: Troubleshooting Go Compile-Time Instrumentation).

Ways to check what Orchestrion is doing
MethodWhat you learnCaution
The -work flagThe rewritten source and the original filesContains source code and dependency names
ORCHESTRION_LOG_LEVEL or --log-levelErrors, warnings, and detailed behaviorThe default is no output, and DEBUG and TRACE can significantly affect build performance
ORCHESTRION_LOG_FILE or --log-fileKeeps the logs in a fileSetting it changes the default log level to WARN
Source: Troubleshooting Go Compile-Time Instrumentation

Once traces start arriving, open Service Config on the service page in Datadog APM. On the SDK Configuration tab, you can confirm the settings that are actually in effect (source: Configuring the Go SDK). Because the files kept by -work can contain source code and dependency names, a way to hand them privately to Datadog support is offered if you are worried about posting them in public. Run orchestrion go build -work ./... once in your own repository. Reading whether the instrumentation for the web framework and database clients you use has gone in under orchestrion/src is the last task before rewriting the CI build.

References

Share