IIS 7: Instrumenting, Diagnosing,
And Debugging Web Applications
Eric Deily
COM320
Program Manager
ericde@microsoft.com
Highlights
“I love IIS7 because…”
I can easily see the state of all Sites, AppPools, Worker
Processes, and AppDomains
I can see the currently executing requests in real-time
I can trace a request from start to finish in production
I can see both ASP.NET and IIS events in the same file
I can enable automatic tracing for all ‘failed’ requests
I can instrument my managed code using existing
methods and see those events in the same file as my IIS
events
Runtime Status And Control API
Introduction
API to obtain runtime status and control the
following
AppPools
WorkerProcesses
WebSites
AppDomains
Goals
Provide means of obtaining current runtime state of
Pools, Sites, AppDomains, and Worker Processes
Provide direct and consistent way to control
above objects
Expose detailed runtime state
Using RSCA To Find What
Requests Are Executing
Runtime Status And Control API
Improvements
Current Request Listing
Exposes detailed data on each request, including
Pipeline state and time in that state
Current module it’s in and time it’s been in that module
Able to pull requests per-worker process
AppDomain Listing
New runtime data -> see what appDomains are
loaded!
Ability to on-demand unload appDomain
Exposed via WMI as well!
Runtime Status And Control API
Objects and data
IRSCA_WAS: Provides access to WorkerProcesses and AppPools
IRSCA_AppPool: Exposed from IRSCA_WAS
Status Data
Name
State
Enumerate Worker Processes
Actions/Controls
Start
Stop
Recycle
IRSCA_WorkerProcess: Exposed from IRSCA_WAS and
IRSCA_AppPool
Status Data
PID/GUID/AppPool Name
State – can be starting/running/stopping/unknown
Loaded ISAPI Extensions and Filters
Currently Executing Requests
Currently loaded AppDomains
Runtime Status And Control API
Objects and data
IRSCA_WAS: Continued
IRSCA_AppDomain: Exposed from IRSCA_WorkerProcess
Status Data
AppDomain ID
Virtual and Physical Paths
Site ID
Idle
Control
Unload app domain
IRSCA_W3SVC: Provides access to Virtual Sites (i.e. websites)
IRSCA_VirtualSite: Exposed from IRSCA_W3SVC
Status Data
ID
State
Actions/Controls
Start
Stop
Using WMI To Access
RSCA Data
Tracing Infrastructure
Overview
Flexible tracing infrastructure
Storage independent: Trace event
consumers are just MODULES
trace
event
sources
w3core
trace event
providers
/consumers
ETW
Automatic Failure Req Tracing (FREB)
…insert your own format here…
Flexible: Add new modules as new
storage formats are needed
How it works…
Consumer module registers for
GL_TRACE_EVENT
Consumer passes in trace configuration
Pipeline modules read configuration
Pipeline modules raise trace event
Event is delivered to consumers
Consumer “handles” event
Infrastructure Events raised through
this infrastructure!
300+ events by IIS7 RTM!
any
module
pipeline
module
Read trace
config
TRACE_EVENT
Trace
config
consumer
module
(etw, freb
etc.)
my trace
output
format
Automatic Failed Request Tracing
Goals
Enable no-repro instrumentation for “failed requests”
Turn tracing on, but only keep the events for “failed requests”
Allow for custom failure definitions per URL
Time taken
Status/substatus codes
Enable per-URL trace configuration
Allow me to define what to trace per URL
Example: only trace aspnet events for “*.aspx”
Persist failure log files beyond process lifetime
Common scenarios
Request takes too long/hangs -> very common today
Request error -> request completes, but with error status code
Authentication/Authorization problems
Server 500 errors
Automatic Failed Request Tracing
How to use it!
Supported providers and
flags pre-defined in
configuration in
applicationHost.config
Configure failure definitions
in web.config
Define URL
Define failure definitions
Define what areas to
trace per URL
Automatic Failed
Request Tracing
Unified Web Platform Tracing
Allows you to route the following through
IIS7 Tracing Infrastructure
ASP.NET Page Trace.Write() and
Trace.Warn() calls
System.Diagnostics.TraceSource calls
WebEvents raised on context of request
Done using existing infrastructure support
– Provider model
Compat! All above features continue to work
as they do on Visual Studio 2005 w/o IIS7
Adding Trace Events To Managed Modules
Part 1 – Configuration
Built on top of System.Diagnostics.TraceSource
How to use it:
IIS7 adds a new Trace Listener for TraceSource calls –
IIS7TraceListener
<system.Diagnostics>
<sharedListeners>
<add name=“IIS7TraceListener” type=“Microsoft.IIS.IIS7Tra…”/>
</sharedListeners>
Create new trace source in config for your module –
ex: myModuleSource
Add the IIS7TraceListener as a listener for your
module trace source:
<sources>
<source name=“myModuleSource” >
<!-- now I add the IIS7TraceListener as a listener -->
<listeners>
<add name=“IIS7TraceListener” />
</listeners>
</source>
</sources>
Adding Trace Events To Managed Modules
Part 2 – Code and Failed Req Tracing
How to use it, continued:
Create the traceSource in your module code
and raise a trace event
// define traceSource first
TraceSource ts = new TraceSource(“myModuleSource”);
// raise trace event
ts.TraceEvent(TraceEventType.Start, “STARTING req processing”);
Configure FREB to look for ASPNET provider, Module area
NOTE: Event type and verbosity depend on TraceEventType
<traceFailedRequests>
<add path=“login.aspx” >
<traceAreas>
<add provider=“ASPNET” area=“Module” verbosity=“verbose” />
</traceAreas>
<failureDefinitions>
<add statusCodes=“401” timeTaken=“” />
</failureDefinitions>
</add>
<traceFailedRequests>
Tracing A Module
Unified Web Platform Tracing
Page Tracing
How to enable it:
Turn page tracing on first (nothing new here)
<%@ Page Trace=“True” %>
Configure FREB to look for ASPNET provider, Page flag
<traceFailedRequests>
<add path=“login.aspx” >
<traceAreas>
<add provider=“ASPNET” area=“Page” verbosity=“verbose” />
</traceAreas>
<failureDefinitions>
<add statusCodes=“401” timeTaken=“” />
</failureDefinitions>
</add>
<traceFailedRequests>
Events come out with
Data: Connection ID, Activity ID (for correlation), Uri, and the message logged in the Write() or
Warn() call
Separate event types for Trace.Warn() and Trace.Write()
Write() events : verbosity=“verbose”
Warn() events : verbosity=“warning”
Tracing In An aspx Page
Summary
On-demand runtime state and control
of objects
Extensible tracing subsystem
Subsystem publishing and consumption APIs
are exposed publicly
You can roll your own trace output module
IIS modules are built on these public API’s
No-repro Tracing via FREB
Add your own trace events via
existing mechanisms!
Discussion
Community Resources
At PDC
For more information, go see
Ask the Experts Table: IIS (tonight, 6:30-9pm)
PNL06: What’s Next for Microsoft’s Web Platform
COM431: IIS7 Extensibility Part 2: Building
Configuration & UI Modules
COM Track lounge: I’ll be there Today 2-5pm
After PDC
You can email me at eric.deily@microsoft.com
My blog: www.ericdeily.net
Want to do the same demos I did? Your
attendee DVD should contain all my demos +
lab docs on walking through them.
© 2005 Microsoft Corporation. All rights reserved.
This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.