Overview
Code Origin captures the exact locations in your codebase where APM spans are created. When enabled on a compatible service, it automatically adds file path, line number, and function name to each service entry span, making it easier to:
- Debug performance issues
- Understand code execution flow
- Identify performance bottlenecks
In Trace Explorer, select a span from an enabled service to see Code Origin details on the Overview tab:
Getting started
Prerequisites
Compatibility requirements
| SDK Version | Frameworks |
|---|
| 1.47.0+ | Spring Boot/Data, gRPC servers, Micronaut 4, Kafka consumers |
Limitation: On JDK 18 and below, classes compiled with the -parameters flag may not be supported. Spring 6+, Spring Boot 3+, and Scala use this flag by default.
| SDK Version | Frameworks |
|---|
| 2.15.0+ | Django, Flask, Starlette, and derivatives |
| SDK Version | Frameworks |
|---|
| 4.49.0+ | Fastify |
| 5.54.0+ | Express |
Note: NestJS is not supported, even though the underlying framework is either Express or Fastify.
| SDK Version | Frameworks |
|---|
| 3.15.0+ | ASP.NET, ASP.NET Core |
| SDK Version | Frameworks |
|---|
| 1.11.0+ | All supported web frameworks |
Go services get Code Origin data through Source Code Integration rather than the SDK flag.
| Requirement | Frameworks |
|---|
| Source Code Integration enabled | Custom spans, gRPC servers, Gin, Chi, Echo, Fiber, gorilla/mux, OpenTelemetry, OpenTracing |
Enable Code Origin
Source Code Integration alone can infer some Code Origin details automatically, even for services that don’t meet the compatibility requirements. See Code Origin coverage through Source Code Integration.
Enabling the SDK flag for a compatible language and framework gets you full tracer-instrumented coverage.
To enable through the SDK, run your service with the following environment variable:
export DD_CODE_ORIGIN_FOR_SPANS_ENABLED=true
For transpiled Node.js applications (for example, TypeScript), make sure to generate and publish source maps with the deployed application, run Node.js with the
--enable-source-maps flag, and use v5.59.0 or newer of the Node.js tracer. Otherwise, code previews do not work. See the Node.js
Source Code Integration documentation for more details.
Using Code Origin
In the Trace Explorer
Navigate to the Trace Explorer.
Search for “Service Entry Spans” from your Code Origin-enabled services.
Click on a span to view its details.
In the trace details side panel, look for the “Code Origin” section.
From the Code Origin section:
Kick off a Live Debugger session on the running service by clicking “Start Debug Session” to capture logs at the Code Origin method location. Or, select a breakpoint in the gutter of the code preview to capture logs at the selected line of code.
Click on source code variables to add them as attributes to future spans with Dynamic Instrumentation.
In your IDE
Set up your Datadog IDE Integration.
- Supported IDEs: IntelliJ, VS Code
- Supported Languages: Java, Python
View RED metrics (Requests, Errors, and Duration) as inline annotations above your endpoint methods.
Troubleshooting
Code Origin section is missing
Code preview is not visible or the file is not found
- Ensure all Source Code Integration setup requirements are met, including your
DD_GIT_* environment variables are configured with the correct values. - For transpiled Node.js applications (for example, TypeScript), make sure to generate and publish source maps with the deployed application, run Node.js with the
--enable-source-maps flag, and use v5.59.0 or newer of the Node.js tracer. Otherwise, code previews will not work. See the Node.js Source Code Integration documentation for more details. - Code Origin is designed to reference user code only, but in some cases, third-party code references may slip through. You can report these cases to Datadog support and help improve these references.
Code Origin coverage through Source Code Integration
Source Code Integration (for example, with GitHub, GitLab, or Azure DevOps) is required as a prerequisite. On its own, it uses static analysis of your repository to automatically determine code locations for some languages and frameworks, without meeting the other requirements.
To get full tracer-instrumented coverage for the languages and frameworks listed in compatibility requirements, also enable Code Origin in your SDK. Data from both methods appears in the same Code Origin section of the Trace Explorer and powers the same IDE integration and Live Debugger workflows.
Further Reading
Additional helpful documentation, links, and articles: