|
| 1 | +--- |
| 2 | +title: Code Origins for Spans |
| 3 | +description: "Learn how to use Code Origins to understand where your spans originate in your codebase" |
| 4 | +further_reading: |
| 5 | +- link: "/tracing/glossary/" |
| 6 | + tag: "Documentation" |
| 7 | + text: "Learn about APM terms and concepts" |
| 8 | +- link: "/tracing/trace_collection/" |
| 9 | + tag: "Documentation" |
| 10 | + text: "Learn how to set up APM tracing with your application" |
| 11 | +- link: "/tracing/services/service_page/" |
| 12 | + tag: "Documentation" |
| 13 | + text: "Learn more about services in Datadog" |
| 14 | +- link: "/tracing/services/resource_page/" |
| 15 | + tag: "Documentation" |
| 16 | + text: "Dive into your resource performance and traces" |
| 17 | +- link: "/dynamic_instrumentation/" |
| 18 | + tag: "Documentation" |
| 19 | + text: "Learn how to add custom spans with Dynamic Instrumentation" |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +{{< beta-callout url="#" btn_hidden="true" >}} |
| 24 | +Code Origins is currently in Preview. To join the preview, follow the instructions below. |
| 25 | + |
| 26 | +To submit questions, feedback, or requests related to Code Origins, fill out <a href="https://docs.google.com/forms/d/e/1FAIpQLScyeRsF2GJjYdf9bUyeDjt8_9id-gvqiBU1SHR3ioDGe5eF3g/viewform?usp=header">this form</a> with details. |
| 27 | +{{< /beta-callout >}} |
| 28 | + |
| 29 | +## Overview |
| 30 | + |
| 31 | +Code Origins captures the exact locations in your codebase where APM spans are created. When enabled, it automatically adds file path, line number, and function name to each span, making it easier to: |
| 32 | + |
| 33 | +- Debug performance issues |
| 34 | +- Understand code execution flow |
| 35 | +- Identify performance bottlenecks |
| 36 | + |
| 37 | +In Trace Explorer, select a span to see Code Origin details on the Overview tab: |
| 38 | +{{< img src="tracing/guide/code_origins/code_origin_details_spotlight.png" alt="Code Origin Details" style="width:100%;">}} |
| 39 | + |
| 40 | + |
| 41 | +## Getting started |
| 42 | + |
| 43 | +### Prerequisites |
| 44 | +- [Datadog APM][6] is configured to capture spans. |
| 45 | +- [Source Code Integration][7] is enabled (recommended for code previews). |
| 46 | +- Your service meets the [compatibility requirements](#compatibility-requirements). |
| 47 | + |
| 48 | +### Compatibility requirements |
| 49 | + |
| 50 | +| Runtime Language | Tracing Library Version | Frameworks | |
| 51 | +|---|---|---| |
| 52 | +| Java | 1.47.0+ | Spring Boot/Data, gRPC servers, Micronaut 4, Kafka consumers| |
| 53 | +| Python | 2.15.0+ | Django, Flask, Starlette and derivatives| |
| 54 | +| Node.js | 4.49.0+ | Fastify| |
| 55 | +| .NET | 3.15.0+ | ASP.NET, ASP.NET Core| |
| 56 | + |
| 57 | +### Enable Code Origins |
| 58 | + |
| 59 | +Run your service with the following environment variable: |
| 60 | + |
| 61 | +```shell |
| 62 | +export DD_CODE_ORIGIN_FOR_SPANS_ENABLED=true |
| 63 | +``` |
| 64 | + |
| 65 | +## Using Code Origins |
| 66
6D4E
| + |
| 67 | +### In the Trace Explorer |
| 68 | + |
| 69 | +1. Navigate to the [Trace Explorer][1]. |
| 70 | +2. Click on any trace to view its details. |
| 71 | +3. In the span details panel, look for the "Code Origin" section. |
| 72 | + |
| 73 | + {{< img src="tracing/guide/code_origins/code_origin_details_spotlight.png" alt="Code Origin Details in Traces Explorer" style="width:100%;">}} |
| 74 | + |
| 75 | +4. Optionally, click on source code variables to add them as attributes to future spans with [Dynamic Instrumentation][5]. |
| 76 | + |
| 77 | + {{< img src="tracing/guide/code_origins/code_origin_add_span_tag_spotlight.png" alt="Code Origin - Add span tag with Dynamic Instrumentation" style="width:100%;">}} |
| 78 | + |
| 79 | +### In your IDE |
| 80 | + |
| 81 | +1. Set up your [Datadog IDE Integration][4]. |
| 82 | + - Supported IDEs: IntelliJ, VS Code |
| 83 | + - Supported Languages: Java, Python |
| 84 | +2. View RED metrics (Requests, Errors, and Duration) as inline annotations above your endpoint methods. |
| 85 | + |
| 86 | + {{< img src="tracing/guide/code_origins/code_origin_ide_details.png" alt="Code Origin Details in IDE" style="width:100%;">}} |
| 87 | + |
| 88 | +## Troubleshooting |
| 89 | + |
| 90 | +If Code Origin information is missing: |
| 91 | + |
| 92 | +1. Verify Code Origins is [enabled](#enable-code-origins) in your tracing library configuration. |
| 93 | +1. Confirm that your service meets all [compatibility requirements](#compatibility-requirements). |
| 94 | + - In particular, check whether your service's language and framework support Code Origins. |
| 95 | +1. Filter for spans that include Code Origins using the query `@_dd.code_origin.type:*` in the [Trace Explorer][1]. |
| 96 | +1. Enable [Source Code Integration][7] to see code previews in the APM Trace side panel. |
| 97 | + |
| 98 | + |
| 99 | +## Further Reading |
| 100 | + |
| 101 | +{{< partial name="whats-next/whats-next.html" >}} |
| 102 | + |
| 103 | +[1]: https://app.datadoghq.com/apm/traces |
| 104 | +[2]: /tracing/services/service_page/ |
| 105 | +[3]: /tracing/services/resource_page/ |
| 106 | +[4]: /developers/ide_plugins/ |
| 107 | +[5]: /dynamic_instrumentation/ |
| 108 | +[6]: /tracing/trace_collection/ |
| 109 | +[7]: /integrations/guide/source-code-integration/ |
| 110 | +[8]: /tracing/trace_collection/compatibility/nodejs#web-framework-compatibility |
0 commit comments