Automatic Instrumentation with Datadog APM - unix1998/technical_notes GitHub Wiki
Yes, "automatic instrumentation" with Datadog means that you typically don't need to add manual instrumentation code, such as annotations, to your application. The Datadog instrumentation agents automatically instrument your application and collect trace information out of the box. Here’s how it works:
Automatic Instrumentation with Datadog APM
-
Install the Datadog Agent: Ensure the Datadog Agent is installed and running on your host.
-
Add the Datadog Library: Add the Datadog APM library to your application. The installation process varies by language:
- Java: Add the Datadog Java APM agent as a JVM argument when starting your application.
- Python: Install the
ddtrace
library using pip. - Node.js: Install the
dd-trace
package using npm. - Ruby: Install the
ddtrace
gem. - .NET: Install the Datadog .NET tracer package.
- Go: Use the Datadog APM library for Go.
- PHP: Install the Datadog PHP tracer.
-
Enable Tracing: Enable tracing by setting the necessary configuration options. For many languages, this involves setting environment variables or modifying a configuration file.
-
Start Your Application: Once the Datadog library is included and configured, start your application. The Datadog agent will automatically instrument supported frameworks and libraries.
Example for Java
For a Java application, you might do something like this:
- Download the Datadog Java APM agent.
- Start your Java application with the agent attached:
java -javaagent:/path/to/dd-java-agent.jar -Ddd.trace.agent.port=8126 -Ddd.service=my-service -Ddd.env=production -jar my-application.jar
Example for Python
For a Python application, you would do the following:
- Install the Datadog tracing library:
pip install ddtrace
- Configure the tracer by setting environment variables or updating your application code:
DD_SERVICE=my-service DD_ENV=production DD_AGENT_HOST=localhost DD_TRACE_ENABLED=true python my_application.py
Supported Frameworks and Libraries
Datadog automatically instruments many popular frameworks and libraries for each language, such as:
- Java: Spring, Hibernate, Jersey, Kafka, etc.
- Python: Django, Flask, Celery, SQLAlchemy, etc.
- Node.js: Express, Hapi, Koa, etc.
- Ruby: Rails, Sinatra, Sidekiq, etc.
- .NET: ASP.NET Core, ADO.NET, etc.
Custom Instrumentation
While automatic instrumentation covers many common use cases, you can still add custom instrumentation if needed. This is useful for capturing additional details or spans that are not automatically captured by the Datadog agent.
Summary
With Datadog's automatic instrumentation:
- You don’t need to modify your application code to add tracing annotations.
- Simply install and configure the Datadog instrumentation library/agent.
- Start your application, and trace data will be automatically collected and sent to Datadog, where it will be visible in the console and dashboards.