As mentioned in a previous post https://dev.to/kiranrongali/how-datadog-helps-developers-teams-kkg, we discussed how Datadog can benefit developers and teams. In this post, we'll focus on integrating it with a .NET application.
- Step 1: Create a Datadog Account
1. Go to https://www.datadoghq.com.
2. Sign up for a free trial.
3. Once logged in, choose your region (important for API keys and endpoints).
- Step 2: Install the Datadog Agent (on your dev machine, server, or container)
- Download the agent from Datadog Agent Downloads.
- Follow the OS-specific instructions:
- Windows: Run the .msi installer and enter your API Key during setup.
- Linux/macOS: Use the shell script provided.
🔑 Your API key can be found in Datadog → Integrations → APIs.
- Step 3: Install Datadog Tracer for .NET In your .NET Core or ASP.NET Core project:
-
Install the NuGet package:
#bash dotnet add package Datadog.Trace
-
Enable automatic instrumentation:
Add this to your environment (or launch profile):
#bash DOTNET_Diagnostics=1 DD_TRACE_ENABLED=true DD_ENV=dev DD_SERVICE=my-dotnet-app DD_VERSION=1.0.0 DD_AGENT_HOST=localhost # or your agent IP DD_TRACE_DEBUG=true # optional for debugging
-
Or set in appsettings.json (if using Datadog.Config):
#json { "DD_SERVICE": "my-dotnet-app", "DD_ENV": "dev", "DD_AGENT_HOST": "localhost", "DD_TRACE_ENABLED": "true" }
- Step 4: Enable APM (Tracing) If using IIS or Kestrel, no code changes are needed but: To trace web requests, background jobs, or SQL calls:
//csharp using Datadog.Trace; public IActionResult Index() { var span = Tracer.Instance.StartActive("custom.operation"); try { // your logic here } finally { span.Dispose(); // ends trace } return View(); }
Step 5: Enable Logging (Optional but Recommended)
Use Serilog, NLog, or Microsoft Logging to forward logs:
For Serilog:
#bash
dotnet add package Serilog.Sinks.Datadog.Logs
Example Config:
//csharp
Log.Logger = new LoggerConfiguration()
.WriteTo.DatadogLogs("<your-api-key>", source: "csharp", service: "my-dotnet-app")
.CreateLogger();
-
Step 6: Verify in Datadog Dashboard
- Go to APM → Services in Datadog.
- Select your service (my-dotnet-app) to view: Response times Error rates Traces and spans Host metrics (CPU, memory, etc.)
-
Step 7: Set Up Dashboards & Alerts
- Create a custom dashboard:
- Add widgets: charts, traces, logs, etc.
- Add monitors/alerts:
- Example: “Notify if error rate > 5% for 5 min”
- Integrate with Slack, Teams, PagerDuty, etc. for alert delivery.
- Create a custom dashboard:
-
Optional: Monitor SQL, Redis, HTTP, etc.
- Install additional NuGet packages if needed (e.g., Datadog.Trace.ClrProfiler.Managed).
- You can trace:
- SQL Server (SqlClient)
- HTTP calls (HttpClient)
- Entity Framework
- Background Services (e.g., Hangfire)
That's it!
With this setup, you'll now have:
- Real-time visibility into your .NET app’s performance
- Detailed traces and logs
- Dashboards and alerts
Thanks for this post! It helped me.