microsoft / appcenter-sdk-dotnet

Development repository for the App Center SDK for .NET platforms, including Xamarin
Other
310 stars 141 forks source link

Very odd gaps between StartServiceLog and StartSessionLog #1789

Closed munkii closed 1 week ago

munkii commented 1 month ago

Gaps between StartSessionLog call and StartSessionLog call from 55mins to 11hours with nothing logged in between Description

Please describe the issue you are facing using the SDK.

Repro Steps

Please list the steps used to reproduce your issue.

  1. We have a Xamarin Forms app that uses Microsoft.AppCenter.Analytics and Microsoft.AppCenter.Crashes version 5.0.3
  2. We export those logs to Azure AppInSights

Details

  1. Whilst investigating some odd behvior where our app was sending expired Azure B2C Access Tokens we were macthing the failed requests to AppCenter logs. Of the 8 occurences of this expired token issue i can match them to 6 failures in the AppCenter logs

  2. They are all iOS users but that could be a coincidence

  3. In the logs i see something like this each time

Timestamp name
9/28/2024, 6:40:05.638 PM StartSessionLog
9/28/2024, 6:37:29.081 PM StartSessionLog
9/28/2024, 6:00:54.541 PM DataSyncService - Sync All Finished
  LOTS OF LOG ROWS NOT INCLUDED Nothng unusual
9/28/2024, 6:00:30.862 PM DataSyncService - Sync All Requested
9/28/2024, 6:00:30.850 PM ThirdPartyService - Sync All Completed
9/28/2024, 6:00:27.821 PM ThirdPartyService - Sync All Requested
9/28/2024, 6:00:26.601 PM StartSessionLog
9/28/2024, 5:05:00.723 PM ViewModel - HomeViewModel Appearing
9/28/2024, 5:05:00.349 PM Connecting UserId To AppCenter
9/28/2024, 5:04:59.866 PM StartServiceLog

Note the 55minute gap between one log 'ViewModel - HomeViewModel Appearing' and the 'StartSessionLog'. I have seen one occurence where the gao to StartSesssionLog was 11hours

IlyaBausovAkvelon commented 1 month ago

Hi @munkii, thank you for reporting! Could you please tell us how AppCenter.Analytics is being started in the app? Where is called Appcenter.Start? Is App being put into background right after launch? I am asking because Analytics is trying to send start session event while initializing and after app is being put back to foreground.

munkii commented 1 month ago

We call it in Xamarin.Forms.Application OnStart

protected override void OnStart()
{
#if !RELEASE_LIVECONFIG
    AppCenter.Start(
        $"ios={AppSettings.AppCenterAnalyticsIosDevTest};" +
        $"android={AppSettings.AppCenterAnalyticsAndroidDevTest}",
        typeof(Analytics),
        typeof(Crashes));
#else
    AppCenter.Start(
        $"ios={AppSettings.AppCenterAnalyticsIos};" +
        $"android={AppSettings.AppCenterAnalyticsAndroid}",
        typeof(Analytics),
        typeof(Crashes));
#endif

    base.OnStart();

    Page pageToShow = null;

    if (Xamarin.Essentials.VersionTracking.IsFirstLaunchEver == false)
    {
        pageToShow = FreshPageModelResolver.ResolvePageModel<HomeViewModel>();
    }
    else
    {
        pageToShow = FreshPageModelResolver.ResolvePageModel<FirstRunViewModel>();
    }

    var mainNavContainer = new FreshNavigationContainer(pageToShow, NavigationContainerNames.MainContainer);
    this.MainPage = mainNavContainer;

    App.Current.On<Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
}

Is App being put into background right after launch? To be honest I don't know.

IlyaBausovAkvelon commented 4 weeks ago

Hi @munkii, Thank you for the information you've shared. These two events not necessary happen simultaneously. There could be a gap between start of service log and start of session log when the app has been put in background between them. Start service log potentially couldn't be sent in time because of that. Also do you use manual control of the session? Do you enable the following in your code: Analytics.EnableManualSessionTracker(); https://learn.microsoft.com/en-us/appcenter/sdk/analytics/xamarin#manage-start-session

DmitriyKirakosyan commented 1 week ago

Closing due to inactivity.