Customize Xamarin Automatic Instrumentation
You can customize automatic instrumentation of the following:
- Automatic Network Request Instrumentation
- Automatic Page Tracking Instrumentation
- Automatic UI Tracking Instrumentation
To make customizations to automatic instrumentation, make sure you have the AppDynamics.Agent.AutoInstrument.Fody package added to your project. See Set Up Automatic Network Request Instrumentation.
Customize Automatic Network Request Instrumentation
When automatic network request instrumentation is enabled, the weaver will search the project for all new instances of HttpClient or Refit usages. In instances that are found, the agent instrumentation code will be injected to the HttpClient or Refit request.
You can further customize the automatic instrumentation at the project level or class level (see sections below). For example, you could:
-
Enable the automatic instrumentation at a project level from the
FodyWeavers.xmlfile, but exclude some files at the class level using theDisableNetworkInstrumentationattribute. -
Disable the automatic instrumentation at a project level from the
FodyWeavers.xmlfile, but includesome files at the class level using theEnableNetworkInstrumentationattribute.
semi-automatic network request tracking
via theHttpRequestTrackerHandler, the network request will not be reported twice.
Enable/Disable at the Project Level
You can enable or disable automatic instrumentation at the project level using the NetworkInstrumentationEnabled flag in the FodyWeavers.xml file.
For example:
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
... Existing weavers ...
<AppDynamics.Agent.AutoInstrument NetworkInstrumentationEnabled="true"/>
</Weavers>
Enable/Disable at the Class Level
You can enable or disable automatic instrumentation at the class level by using one of the following attributes per class:
-
[EnableNetworkInstrumentation]
JAVA[EnableNetworkInstrumentation] public class MyClass { ... } -
[DisableNetworkInstrumentation]
JAVA[DisableNetworkInstrumentation] public class MyClass { ... }
Recommendations
-
If you are using DisableNetworkInstrumentation manual network request tracking, you will see duplicate entries for the same network request. To avoid this, you can either remove the manual instrumentation or use the
- If your HTTP requests are handled in a different project, you should add both the
AppDynamics.AgentandAppDynamics.Agent.AutoInstrument.Fodyto that project as well for instrumentation to work. - If you are using a
HttpClientinstance generated in another library, you should only create and use the instance within the same project for instrumentation to work. Automatic instrumentation works by targeting new HttpClient instances within the project.
Customize Automatic Page Tracking Instrumentation
When automatic page tracking instrumentation is enabled, the weaver will search the project for all instances of Xamarin.Forms Page in the project and inject the instrumentation code.
Enable/Disable at the Project Level
You can enable or disable automatic Page Tracking instrumentation at the project level using the PageTrackingInstrumentationEnabled flag in the FodyWeavers.xml file:
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
... Existing weavers ...
<AppDynamics.Agent.AutoInstrument PageTrackingInstrumentationEnabled="true"/>
</Weavers>
Enable/Disable at the Class Level
You can enable or disable automatic instrumentation at the class level by using one of the following attributes per class:
-
[EnablePageTracking]
JAVA[EnablePageTracking] public class MyPage : Xamarin.Forms.ContentPage { ... } -
[DisableUITRacking]
JAVA[DisablePageTracking] public class MyPage : Xamarin.Forms.ContentPage { ... }
Automatic UI Tracking Instrumentation
When automatic UI tracking instrumentation is enabled, the weaver will search the project for all instances of Xamarin.Forms Button, Entry and ListView in the project and inject the instrumentation code.
Enable/Disable at the Project Level
You can enable or disable automatic instrumentation at the project level using the UITrackingInstrumentationEnabled flag in the FodyWeavers.xml file.
For example:
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
... Existing weavers ...
<AppDynamics.Agent.AutoInstrument UITrackingInstrumentationEnabled="true"/>
</Weavers>
Enable/Disable at the Class Level
You can enable or disable automatic instrumentation at the class level by using one of the following attributes per class:
-
[EnableUITracking]
JAVA[EnableUITracking] public class MyPage : Xamarin.Forms.ContentPage { ... } -
[DisableUITRacking]
JAVA[DisableUITracking] public class MyPage : Xamarin.Forms.ContentPage { ... }
Automatic UI Tracking and XAML
Automatic UI Tracking works with both XAML and code-behind UI elements. But even though code-behind UIs are automatically instrumented, there's a required extra step to auto-instrument XAML. Add the following configuration to your .csproj file:
<PropertyGroup>
<FodyDependsOnTargets>
XamlC
</FodyDependsOnTargets>
</PropertyGroup>
Automatic UI Tracking only works with pre-compiled XAML, so you will need to use XamlCompilationOptions.Compile:
[XamlCompilation(XamlCompilationOptions.Compile)]
By default, a project created with a Visual Studio Xamarin.Forms template will already include this. See XAML Compilation in Xamarin.Forms for more information.