Magic behind App Insights Codeless Integration with App Services
Published Mar 14 2022 07:15 PM 2,494 Views
Microsoft

As the official tool for monitoring Azure App Services, App Insights is increasingly popular among App Services users. This article explores how App Insights codeless agent integrates with App Services.

 

To start with, here is an overview of current runtime support of App Insights codeless integration on App Services.

 

 

 

Codeless agent managed by platform

Code-based App Insights SDK

Windows

.NET Framework

Y

Y

 

.NET Core

Y

Y

 

.NET

Y

Y

 

Nodejs

Y

Y

 

Java

Y

Y

Linux

.NET Core

N

Y

 

.NET

Y (.NET 6+)

Y

 

Nodejs

Y

Y

 

Java

Y

Y

 

Python

N

Y

 

Next, we will take a look at current design of App Insights codeless integration with Azure App Services. Regardless of OS and runtime stack used, what App Insights codeless integration does is injecting App Insights modules into application process. On Windows web apps, it is achieved by XDT transform while Docker commands are employed on Linux equivalents to make things happen as Linux web apps run in container environment.

 

 

 

Codeless Integration

Windows

 

.NET Framework

XDT Transform, injecting the dll which implements IHttpModule

 

.NET Core

XDT Transform, the dll is injected to the .NET Core runtime by defining “ASPNETCORE_HOSTINGSTARTUPASSEMBLIES” env var

 

.NET

XDT Transform, similar as .NET Core

 

Nodejs

XDT Transform, injecting App Inisghts Nodejs agent by adding global env var

“NODE_OPTIONS =

--require %XDT_EXTENSIONPATH%\nodejs\build\src\Loader.js”

 

Java

XDT Transform, injecting App Insights Java agent by adding global env var

“JAVA_OPTIONS =

-javaagent:'%XDT_EXTENSIONPATH%\java\applicationinsights-agent-3.2.0.jar”

Linux

 

.NET Core

N/A

 

.NET (6+)

Similar as Windows .NET Core except that “ASPNETCORE_HOSTINGSTARTUPASSEMBLIES” env var is defined in Dockerfile

 

Nodejs

Similar as Windows Nodejs except that env var

“NODE_OPTIONS” is added via docker run –e command

 

Java

Similar as Windows Java except that env var

“JAVA_TOOL_OPTIONS” is added via docker run –e command

 

Python

N/A

 

Finally, as an example, App Insights codeless integration with Windows .NET Framework web app is elaborated below to help better understand how it works under the covers.

 

1. When enabling codeless App Insights agent on the Azure Portal, applicationhost.config (i.e. the root file of the configuration system when you are using IIS 7 and above) will be updated to load a pre-installed site extension (i.e. an application hosted under SCM domain) from path “%SystemDrive%\Program Files (x86)\SiteExtensions\ApplicationInsightsAgent\x.x.xx”.

 

YangYu_0-1647488053185.png

 

YangYu_1-1647488356779.png

 

2. Upon loading the pre-installed site extension, XDT transform (i.e. site config transformation) will be performed to insert Microsoft.AppInsights.IIS.ManagedHttpModuleHelper module from GAC for target site.

 

YangYu_0-1647308142887.png

 

YangYu_1-1647308142881.png

 

YangYu_2-1647308142889.png

 

3. ManagedHttpModuleHelper module implements IHttpModule, an interface offered by ASP.NET to intercept site requests. In this case, App Insights dlls are injected into application process to monitor both inbound and outbound requests.

 

YangYu_3-1647308142885.png

 

Have fun discovering!

 

 

Co-Authors
Version history
Last update:
‎Mar 19 2022 12:31 AM
Updated by: