⚙️Integrate Datadog with a .NET Application
Kiran Rongali

Kiran Rongali @kiranrongali

Location:
Florida
Joined:
Apr 15, 2025

⚙️Integrate Datadog with a .NET Application

Publish Date: Apr 21
14 3

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).
Enter fullscreen mode Exit fullscreen mode
  • Step 2: Install the Datadog Agent (on your dev machine, server, or container)
  1. Download the agent from Datadog Agent Downloads.
  2. 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:
  1. Install the NuGet package:

     #bash
     dotnet add package Datadog.Trace
    
  2. 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
Enter fullscreen mode Exit fullscreen mode

Example Config:

   //csharp
   Log.Logger = new LoggerConfiguration()
    .WriteTo.DatadogLogs("<your-api-key>", source: "csharp", service: "my-dotnet-app")
    .CreateLogger();
Enter fullscreen mode Exit fullscreen mode
  • 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

    1. Create a custom dashboard:
      • Add widgets: charts, traces, logs, etc.
    2. Add monitors/alerts:
      • Example: “Notify if error rate > 5% for 5 min”
    3. Integrate with Slack, Teams, PagerDuty, etc. for alert delivery.
  • 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

Comments 3 total

  • Chi nav
    Chi navApr 22, 2025

    Thanks for this post! It helped me.

  • Chnet
    ChnetApr 30, 2025

    Thanks for the walkthrough

  • Chi nav
    Chi navApr 30, 2025

    Nice post!!

Add comment