Search code examples
asp.netiistracedatadogapm

Datadog - Monitoring multiple applications in the same site hosted by IIS


I'm trying to monitor several applications within the same site in IIS. With just running the msi of the tracer dd-trace-dotnet, I started to see the events, but these are registered as [site name]/[application] e.g default_web_site/docs_webhook
I would love to be able to logs them under a custom service name for each application, but according to the documentation, this is only possible at the site level.
Manual instrumentation is described for windows services, setting the environment variable DD_SERVICE_NAME in the registry entry HKLM\System\CurrentControlSet\Services\{service name}\Environment is enough, but does not apply to IIS applications.

NOTE: Creating separate sites for each application is not an option right now.


Solution

  • For each web application that you want to configure with a different Datadog APM service name, you need to set the environment variable DD_SERVICE_NAME. If they're all running under the same IIS process, that's not possible.

    In IIS there's a feature named Application Pool, which can be used to isolate multiple web applications by running them under different processes.

    The first thing you need to do is to create a separate application pool for each web application. Once you're done with that, you can set a different DD_SERVICE_NAME for each application pool. The command to set an environment variable scoped to a specific application pool is

    appcmd.exe set config -section:system.applicationHost/applicationPools /+"[name='MyAppPool'].environmentVariables.[name='DD_SERVICE_NAME',value='my-service']" /commit:apphost
    

    where MyAppPool is the name of the application pool, and my-service is the service name that you want to use for the Datadog APM.

    After running the above command, you have to restart IIS for the changes to take effect:

    net stop was /y
    
    net start w3svc