Overview
Dynamic Instrumentation lets you add metrics, spans, and span tags to running production systems without restarts or code changes, including in third-party libraries.
To use autocomplete and search, opt in to the preview.
Note: Dynamic Instrumentation is not compatible with Azure App Services or serverless environments.
Requirements
Datadog SDK
- Datadog Java SDK (JDK 8 or higher)
- Minimum for in-app enablement: 1.48.0
- Minimum for manual enablement: 1.34.0
- Does not support Kotlin coroutines
- Datadog Python SDK (
ddtrace)- Minimum for in-app enablement: 3.10.0
- Minimum for manual enablement: 2.2.0
- Datadog .NET SDK (.NET Framework or .NET Core)
- Minimum for in-app enablement: 3.29.0
- Minimum for manual enablement: 2.54.0
- Datadog PHP SDK (
dd-trace-php), minimum version 1.5.0- File and line instrumentations are not supported
Datadog configuration
- Install the Datadog Agent, version 7.49.0 or higher.
- Configure Unified Service Tagging with
service,env, andversiontags. - Enable Remote Configuration in the Agent.
- (Recommended) Set up Source Code Integration.
Permissions
The following permissions are required to use Dynamic Instrumentation:
- Dynamic Instrumentation Read Configuration (
debugger_read): Required to access the Dynamic Instrumentation page. - One of the following write permissions:
- Dynamic Instrumentation Write Configuration (
debugger_write): Required to create or modify instrumentations in any environment. - Dynamic Instrumentation Write Pre-Prod (
debugger_write_preprod): Required to create or modify instrumentations in known pre-production environments only (such as staging or QA).
- Dynamic Instrumentation Write Configuration (
For more information about roles and how to assign roles to users, see Role Based Access Control.
Enable Dynamic Instrumentation
Dynamic Instrumentation and Live Debugger share the same enablement state per service and environment: enabling or disabling one also enables or disables the other. The two products have separate permissions and Settings pages.
You can enable Dynamic Instrumentation in-app or manually.
Enable in-app (recommended)
Enable Dynamic Instrumentation in-app in one of two ways:
- On the Dynamic Instrumentation Settings page, enable the service and environment.
- Create an instrumentation. Dynamic Instrumentation is enabled automatically on the selected service and environment.
Enable manually
Follow these steps if your SDK is below the in-app minimum, or if you want to manage enablement outside the Datadog UI.
If you don't already have APM enabled, set
DD_APM_ENABLED=trueand configure the Agent to listen on port8126/TCP.Download
dd-java-agent.jar:wget -O dd-java-agent.jar 'https://dtdg.co/latest-java-tracer'curl -Lo dd-java-agent.jar 'https://dtdg.co/latest-java-tracer'ADD 'https://dtdg.co/latest-java-tracer' dd-java-agent.jarStart your service with Dynamic Instrumentation enabled. The
-javaagentargument must come before-jar:java \ -javaagent:dd-java-agent.jar \ -Ddd.service=<YOUR_SERVICE> \ -Ddd.env=<YOUR_ENVIRONMENT> \ -Ddd.version=<YOUR_VERSION> \ -Ddd.dynamic.instrumentation.enabled=true \ -jar <YOUR_SERVICE>.jar <YOUR_SERVICE_FLAGS>export DD_SERVICE=<YOUR_SERVICE> export DD_ENV=<YOUR_ENV> export DD_VERSION=<YOUR_VERSION> export DD_DYNAMIC_INSTRUMENTATION_ENABLED=true java \ -javaagent:dd-java-agent.jar \ -jar <YOUR_SERVICE>.jar <YOUR_SERVICE_FLAGS>Note: On JDK 18 and earlier, classes compiled with the
-parametersflag (default in Spring 6+, Spring Boot 3+, and Scala) may fail to instrument with the errorMethod Parameters detected.After you start your service, open the Dynamic Instrumentation page.
If you don't already have APM enabled, set
DD_APM_ENABLED=trueand configure the Agent to listen on port8126/TCP.Install
ddtrace:pip install ddtraceEnable Dynamic Instrumentation with environment variables or in code:
export DD_SERVICE=<YOUR_SERVICE> export DD_ENV=<YOUR_ENV> export DD_VERSION=<YOUR_VERSION> export DD_DYNAMIC_INSTRUMENTATION_ENABLED=true ddtrace-run python -m myapp.pyimport os os.environ["DD_DYNAMIC_INSTRUMENTATION_ENABLED"] = "true" import ddtrace.auto # this must be imported as soon as possibleAfter you start your service, open the Dynamic Instrumentation page.
If you don't already have APM enabled, set
DD_APM_ENABLED=trueand configure the Agent to listen on port8126/TCP.Start your service with the following environment variables set:
DD_SERVICE=<YOUR_SERVICE> DD_ENV=<YOUR_ENV> DD_VERSION=<YOUR_VERSION> DD_DYNAMIC_INSTRUMENTATION_ENABLED=trueAfter you start your service, open the Dynamic Instrumentation page.
If you don't already have APM enabled, set
DD_APM_ENABLED=trueand configure the Agent to listen on port8126/TCP.Start your service with the following environment variables set:
DD_SERVICE=<YOUR_SERVICE> DD_ENV=<YOUR_ENV> DD_VERSION=<YOUR_VERSION> DD_DYNAMIC_INSTRUMENTATION_ENABLED=trueAfter you start your service, open the Dynamic Instrumentation page.
Configure Dynamic Instrumentation
Configure Dynamic Instrumentation using the following environment variables:
| Environment variable | Type | Description |
|---|---|---|
DD_DYNAMIC_INSTRUMENTATION_ENABLED | Boolean | Set to true to enable Dynamic Instrumentation. |
DD_SERVICE | String | The service name, for example, web-backend. |
DD_ENV | String | The environment name, for example, production. |
DD_VERSION | String | The version of your service. |
DD_TAGS | String | Tags to apply to produced data. Must be a list of <key>:<value> separated by commas such as: layer:api,team:intake. |
Note: You can also set -Ddd.dynamic.instrumentation.enabled=true instead of DD_DYNAMIC_INSTRUMENTATION_ENABLED.
Explore Dynamic Instrumentation
Dynamic Instrumentation can help you understand what your application is doing at runtime. By adding an instrumentation at a specific code location, you can capture additional telemetry from your application without the need to change code or redeploy it.
Using instrumentations
An instrumentation allows you to collect additional telemetry from specific points in your code without halting the execution of the program.
Dynamic spans, span tags, and metrics are a UI-based alternative to adding custom instrumentation directly to your source code. Datadog receives the instrumentation configurations you define and dynamically applies them to the running service without requiring restarts.
Datadog captures and processes spans, tags, and metrics generated by Dynamic Instrumentation like other telemetry from the running application. Unlike manual custom instrumentation, Dynamic Instrumentation does not require code changes, deployments, or service restarts. To stop collecting data, disable the instrumentation in Datadog.
To redact sensitive data from instrumentations, see Sensitive data scrubbing.
Creating an instrumentation
All instrumentation types require the same initial setup:
- Go to the Dynamic Instrumentation page.
- Click Create Instrumentation in the top right, or click the three-dot menu on a service and select Add an instrumentation for this service.
- If the fields are not prefilled, choose service, runtime, environment, and version (optional).
- Specify where to set the instrumentation in the source code by selecting either a class and method, or a specific line of code in a file. When autocomplete and search are available, use them to find files, methods, or symbols.Specify where to set the instrumentation in the source code by selecting a class and method. When autocomplete and search are available, use them to find methods or symbols.
For the best experience, set up Source Code Integration to view code directly in Datadog and select instrumentation locations as you would with breakpoints in an IDE.
For creation steps specific to each instrumentation type, see the following sections.
Dynamic log instrumentations are supported in Live Debugger. Use Live Debugger to capture logs and variable snapshots in real time from running applications.
Creating dynamic metrics
A dynamic metric emits a metric when it executes. To create a dynamic metric:
- Select Metric as the instrumentation type.
- Complete the generic instrumentation setup (choose service, environment, and location).
- Specify a name for the metric, which is prefixed with
dynamic.instrumentation.metric.probe.. - Select a metric type (count, gauge, or histogram).
- Choose the value of the metric using the Dynamic Instrumentation expression language. You can use any numeric value from the execution context, such as a method parameter, local variable, a class field, or an expression that yields a numeric value. For count metrics, this is optional, and if you omit it, every invocation increments the count by one.
Metric instrumentations are automatically enabled on all service instances that match the configured environment and version. Metric instrumentations are not rate limited and execute every time the method
Dynamic Instrumentation supports the following metric types:
- Count: Counts how many times a given methodor lineis executed. Can be combined with metric expressions to use the value of a variable to increment the count.
- Gauge: Generates a gauge based on the last value of a variable. This metric requires a metric expression.
- Histogram: Generates a statistical distribution of a variable. This metric requires a metric expression.
Creating dynamic spans
A dynamic span emits a span when a method is executed. To create a dynamic span:
- Select Span as the instrumentation type.
- Complete the generic instrumentation setup (choose service, environment, version, and location).
You can use a dynamic span as an alternative to creating spans with Custom Instrumentation. If the method throws an exception, the details of the exception are associated with the newly created span's error tag.
Creating dynamic span tags
A dynamic span tag adds a tag value to an existing span. You can add a tag to either the active span or the service entry span.
Note: Internal spans are not indexed by default and so might not be searchable in APM.
To create a dynamic span tag:
- Select Span Tag as the instrumentation type.
- Complete the generic instrumentation setup (choose service, environment, version, and location).
- Specify a name for the tag.
- Specify the value of the tag using the Dynamic Instrumentation expression language.
- Optionally define a condition using the Dynamic Instrumentation expression language. The tag is added only when the expression evaluates to true.
- Optionally add additional tags, each with their own name, expression, and optional condition.
You can use a dynamic span tag as an alternative to using Custom Instrumentation to add tags in code.
Further reading
Additional helpful documentation, links, and articles:
- Learn more about the Dynamic Instrumentation Expression LanguageDOCUMENTATION