Distributed Tracing for Xamarin

Gnana jothi 5 Reputation points
2023-07-25T13:25:28.3433333+00:00

Hi

I am having query

As we know we will be able to capture the trace from xamarin to app center and we can export all the log to Application Insights.

From the above approach we wont be able to trace issue, Where it is whether it is from Mobile side or API side?

Is there a way to trace an exception, log directly to Application insight in xamarin?

Are we able to capture trace from xamarin and send directly to Application Insights instead from App center using OpenTelemetry?

I see OpenTelemetry is not supporting for Mobile Application

Here the objective is

How we can trace the issue from xamarin mobile application insight to other application insight component?

Developer technologies .NET Xamarin
{count} vote

1 answer

Sort by: Most helpful
  1. Chathura Munasinghe 170 Reputation points
    2023-07-25T16:53:02.6766667+00:00

    To correlate Mobile(Xamarin.forms) App error telemetry with dependencies monitored in Application Insights, you can use the following steps:

    1. Enable distributed tracing in Application Insights.
    2. Configure your Xamarin.Forms app to send traces to Application Insights.
    3. Configure your dependencies to send traces to Application Insights.
    4. Generate an error in your Xamarin.Forms app.

    Here are the details of each step:

    1. Enable distributed tracing in Application Insights

    To enable distributed tracing in Application Insights, you need to set the EnableDistributedTracing property to true in the TelemetryConfiguration object.

    2. Configure your Xamarin.Forms app to send traces to Application Insights

    To configure your Xamarin.Forms app to send traces to Application Insights, you need to add the following code to your app:

    using Microsoft.ApplicationInsights.Extensibility;
    
    namespace MyApp
    {
        public partial class MainPage : ContentPage
        {
            public MainPage()
            {
                InitializeComponent();
    
                // Configure Application Insights to send traces to Application Insights.
                TelemetryConfiguration configuration = new TelemetryConfiguration();
                configuration.InstrumentationKey = "MyInstrumentationKey";
                configuration.ApplicationInsightsComponentId = "MyApplicationInsightsComponentId";
    
                // Enable distributed tracing in Application Insights.
                configuration.EnableDistributedTracing = true;
    
                // Create a TelemetryClient and start sending traces.
                TelemetryClient telemetryClient = new TelemetryClient(configuration);
                telemetryClient.Start();
            }
        }
    }
    
    
    

    3. Configure your dependencies to send traces to Application Insights

    To configure your dependencies to send traces to Application Insights, you need to follow the instructions provided by the dependency's documentation.

    4. Generate an error in your Xamarin.Forms app

    Once you have configured your Xamarin.Forms app and your dependencies to send traces to Application Insights, you can generate an error in your app. When the error occurs, the trace will be sent to Application Insights.

    You can then use the Application Insights portal to correlate the error telemetry with the dependencies that were involved in the error. This will help you to identify the source of the error and to troubleshoot the issue.

    I hope this helps! Let me know if you have any other questions.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.