---
title: Code Origin for Spans
description: >-
  Learn how to use Code Origin to understand where your spans originate in your
  codebase
breadcrumbs: Docs > APM > Code Origin for Spans
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# Code Origin for Spans

## Overview{% #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](https://docs.datadoghq.com/glossary.md#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:

{% image
   source="https://docs.dd-static.net/images/tracing/code_origin/code_origin_details_spotlight.10171a5059e9927169d8b0aab5a69ea0.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/tracing/code_origin/code_origin_details_spotlight.10171a5059e9927169d8b0aab5a69ea0.png?auto=format&fit=max&w=850&dpr=2 2x"
   alt="Code Origin Details" /%}



## Getting started{% #getting-started %}

### Prerequisites{% #prerequisites %}

- [Datadog APM](https://docs.datadoghq.com/tracing/trace_collection.md) is configured to capture spans.
- [Source Code Integration](https://docs.datadoghq.com/integrations/guide/source-code-integration.md) is enabled.
- Your service meets the compatibility requirements.

### Compatibility requirements{% #compatibility-requirements %}

{% tab title="Java" %}

| 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.
{% /tab %}

{% tab title="Python" %}

| SDK Version | Frameworks                                |
| ----------- | ----------------------------------------- |
| 2.15.0+     | Django, Flask, Starlette, and derivatives |

{% /tab %}

{% tab title="Node.js" %}

| 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.
{% /tab %}

{% tab title=".NET" %}

| SDK Version | Frameworks            |
| ----------- | --------------------- |
| 3.15.0+     | ASP.NET, ASP.NET Core |

{% /tab %}

{% tab title="PHP" %}

| SDK Version | Frameworks                   |
| ----------- | ---------------------------- |
| 1.11.0+     | All supported web frameworks |

{% /tab %}

{% tab title="Go" %}
Go services get Code Origin data through Source Code Integration rather than the SDK flag.

| Requirement                                                                                                 | Frameworks                                                                                 |
| ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
| [Source Code Integration](https://docs.datadoghq.com/integrations/guide/source-code-integration.md) enabled | Custom spans, gRPC servers, Gin, Chi, Echo, Fiber, gorilla/mux, OpenTelemetry, OpenTracing |

{% /tab %}

### Enable Code Origin{% #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:

```shell
export DD_CODE_ORIGIN_FOR_SPANS_ENABLED=true
```

{% alert level="info" %}
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`](https://nodejs.org/docs/latest/api/cli.html#--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](https://docs.datadoghq.com/integrations/guide/source-code-integration.md?tab=nodejs#setup) documentation for more details.
{% /alert %}

## Using Code Origin{% #using-code-origin %}

### In the Trace Explorer{% #in-the-trace-explorer %}

1. Navigate to the [Trace Explorer](https://app.datadoghq.com/apm/traces).

1. Search for "Service Entry Spans" from your Code Origin-enabled services.

   {% image
      source="https://docs.dd-static.net/images/tracing/code_origin/code_origin_service_entry_spans_filter.39f81532a0989c68548c6a3da007487a.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/tracing/code_origin/code_origin_service_entry_spans_filter.39f81532a0989c68548c6a3da007487a.png?auto=format&fit=max&w=850&dpr=2 2x"
      alt="Code Origin - Search for Service Entry Spans" /%}

1. Click on a span to view its details.

1. In the trace details side panel, look for the "Code Origin" section.

   {% image
      source="https://docs.dd-static.net/images/tracing/code_origin/code_origin_details_spotlight.10171a5059e9927169d8b0aab5a69ea0.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/tracing/code_origin/code_origin_details_spotlight.10171a5059e9927169d8b0aab5a69ea0.png?auto=format&fit=max&w=850&dpr=2 2x"
      alt="Code Origin Details in Traces Explorer" /%}

1. From the Code Origin section:

   - Kick off a [Live Debugger](https://docs.datadoghq.com/tracing/live_debugger.md) 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.

     {% image
        source="https://docs.dd-static.net/images/tracing/code_origin/code_origin_start_debug_session.21c5483902fe2e45f85fa158dbbf42f8.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/tracing/code_origin/code_origin_start_debug_session.21c5483902fe2e45f85fa158dbbf42f8.png?auto=format&fit=max&w=850&dpr=2 2x"
        alt="Code Origin - Start Live Debugger Session" /%}

   - Click on source code variables to add them as attributes to future spans with [Dynamic Instrumentation](https://docs.datadoghq.com/dynamic_instrumentation.md).

     {% image
        source="https://docs.dd-static.net/images/tracing/code_origin/code_origin_add_span_tag_spotlight.e8ea782271c0a1337083c5791c735aaf.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/tracing/code_origin/code_origin_add_span_tag_spotlight.e8ea782271c0a1337083c5791c735aaf.png?auto=format&fit=max&w=850&dpr=2 2x"
        alt="Code Origin - Add span tag with Dynamic Instrumentation" /%}

### In your IDE{% #in-your-ide %}

1. Set up your [Datadog IDE Integration](https://docs.datadoghq.com/ide_plugins.md).

   - Supported IDEs: IntelliJ, VS Code
   - Supported Languages: Java, Python

1. View RED metrics (Requests, Errors, and Duration) as inline annotations above your endpoint methods.

   {% image
      source="https://docs.dd-static.net/images/tracing/code_origin/code_origin_ide_details.cc58ae4b94a1159222e11efe93da3e35.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/tracing/code_origin/code_origin_ide_details.cc58ae4b94a1159222e11efe93da3e35.png?auto=format&fit=max&w=850&dpr=2 2x"
      alt="Code Origin Details in IDE" /%}

## Troubleshooting{% #troubleshooting %}

### Code Origin section is missing{% #code-origin-section-is-missing %}

- Verify Code Origin is enabled in your SDK configuration.

- Confirm that your service meets all compatibility requirements, including service language, supported frameworks, and minimum tracer version. If it doesn't, you might still get some Code Origin data automatically if the source code repository is linked in Datadog. See Code Origin coverage through Source Code Integration.

- For most services, Code Origin data is captured for [service entry spans](https://docs.datadoghq.com/glossary.md#service-entry-span) only. You can filter to "Service Entry Spans" in the [APM Trace Explorer](https://app.datadoghq.com/apm/traces).

  {% image
     source="https://docs.dd-static.net/images/tracing/code_origin/code_origin_service_entry_spans_filter.39f81532a0989c68548c6a3da007487a.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/tracing/code_origin/code_origin_service_entry_spans_filter.39f81532a0989c68548c6a3da007487a.png?auto=format&fit=max&w=850&dpr=2 2x"
     alt="Code Origin - Search for Service Entry Spans" /%}

### Code preview is not visible or the file is not found{% #code-preview-is-not-visible-or-the-file-is-not-found %}

- Ensure all [Source Code Integration](https://docs.datadoghq.com/integrations/guide/source-code-integration.md) 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`](https://nodejs.org/docs/latest/api/cli.html#--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](https://docs.datadoghq.com/integrations/guide/source-code-integration.md?tab=nodejs#setup) 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](https://www.datadoghq.com/support/) and help improve these references.

## Code Origin coverage through Source Code Integration{% #code-origin-coverage-through-source-code-integration %}

[Source Code Integration](https://docs.datadoghq.com/integrations/guide/source-code-integration.md) (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{% #further-reading %}

- [Learn about APM terms and concepts](https://docs.datadoghq.com/tracing/glossary.md)
- [Learn how to set up APM tracing with your application](https://docs.datadoghq.com/tracing/trace_collection.md)
- [Learn more about services in Datadog](https://docs.datadoghq.com/tracing/services/service_page.md)
- [Dive into your resource performance and traces](https://docs.datadoghq.com/tracing/services/resource_page.md)
- [Learn how to debug production services with Live Debugger](https://docs.datadoghq.com/tracing/live_debugger.md)
- [Learn how to add custom spans with Dynamic Instrumentation](https://docs.datadoghq.com/dynamic_instrumentation.md)
