DEV Community

Kiran Rongali
Kiran Rongali

Posted on • Edited on

2 3 3 3 3

⚙️Integrate Datadog with a .NET Application

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

I ❤️ building dashboards for my customers

I ❤️ building dashboards for my customers

Said nobody, ever. Embeddable's dashboard toolkit is built to save dev time. It loads fast, looks native and doesn't suck like an embedded BI tool.

Get early access

Top comments (3)

Collapse
 
7dfe2fc1e8def3 profile image
Chnet

Thanks for the walkthrough

Collapse
 
lavanya_chiriki_ff88ce272 profile image
Chi nav

Nice post!!

Collapse
 
lavanya_chiriki_ff88ce272 profile image
Chi nav

Thanks for this post! It helped me.

Feature flag article image

Create a feature flag in your IDE in 5 minutes with LaunchDarkly’s MCP server 🏁

How to create, evaluate, and modify flags from within your IDE or AI client using natural language with LaunchDarkly's new MCP server. Follow along with this tutorial for step by step instructions.

Read full post