Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About using new session in AnalyticsClient #2759

Open
1 task done
AumJobs opened this issue Apr 8, 2024 · 4 comments
Open
1 task done

About using new session in AnalyticsClient #2759

AumJobs opened this issue Apr 8, 2024 · 4 comments
Assignees
Labels
analytics Related to the Analytics category/plugins improvement Any improvement that's not a bug and not requesting new functionality pending-response Issue is pending response from the issue requestor

Comments

@AumJobs
Copy link

AumJobs commented Apr 8, 2024

Before opening, please confirm:

Language and Async Model

Kotlin

Amplify Categories

Analytics

Gradle script dependencies

dependencies {
    ...

    api ("com.amplifyframework:aws-analytics-pinpoint:2.14.13") {
        exclude( group = "androidx.lifecycle", module = "lifecycle-viewmodel-ktx")
    }
    api ("com.amplifyframework:aws-auth-cognito:2.14.13") {
        exclude( group = "androidx.lifecycle", module = "lifecycle-viewmodel-ktx")
    }

    ...
}

Environment information

------------------------------------------------------------
Gradle 8.1.1
------------------------------------------------------------

Build time:   2023-04-21 12:31:26 UTC
Revision:     1cf537a851c635c364a4214885f8b9798051175b

Kotlin:       1.8.10
Groovy:       3.0.15
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          19.0.1 (Oracle Corporation 19.0.1+10-21)
OS:           Mac OS X 12.0.1 aarch64

Please include any relevant guides or documentation you're referencing

No response

Describe the feature request

When I did not initialize Amplify at the Application level,
AutoSessionTracker was behaving strangely.
This prevented sessions from being created and deleted properly.

After that, a new session was created every time we sent an event.
While trying to figure out what was causing this issue, I came across a suggestion in AnalyticsClient > createEvent.
In createEvent, if the session of sessionClient doesn't exist, we create a new Session and pass it over.
In this case, the newly created session is not stored in the sessionClient and seems to be created anew each time.
If this is not the intention, my suggestion would be to save the session to the sessionClient when it is newly created.
This would make the behavior a bit more understandable.
Thanks!

link

Initialization steps (if applicable)

No response

Code Snippet

// Put your code below this line.

amplifyconfiguration.json

No response

GraphQL Schema

// Put your schema below this line

Additional information and screenshots

No response

@github-actions github-actions bot added the pending-triage Issue is pending triage label Apr 8, 2024
@joon-won
Copy link
Contributor

joon-won commented Apr 8, 2024

Hi @AumJobs, our team member will take a look into the issue.

@joon-won joon-won added bug Something isn't working analytics Related to the Analytics category/plugins labels Apr 8, 2024
@github-actions github-actions bot removed the pending-triage Issue is pending triage label Apr 8, 2024
@yuhengshs
Copy link
Contributor

Hi @AumJobs ,

Can you please elaborate the part where you said did not initialize Amplify at the Application level.
Does it mean that you initialized it else where? If so, where did you initialize Amplify at? Does the behavior change when you initialized Amplify in Application.onCreate?

Can you also provide some log information from LogCat with the tag AutoSessionTracker so that we will have a better picture on what will be the root cause.

Thank you!

@yuhengshs yuhengshs self-assigned this Apr 10, 2024
@yuhengshs yuhengshs added the pending-response Issue is pending response from the issue requestor label Apr 10, 2024
@AumJobs
Copy link
Author

AumJobs commented Apr 15, 2024

Hi @yuhengshs

Due to the nature of the app service, we initialized when the first Amplify SDK reference occurs, not in Application.onCreate().
After the issue occurred,
Application.onCreate(), which seemed to resolve some of the issues.

However, my suggestion is that if the sessionClient's session is null, as shared as a link in the body, the current SDK logic for creating a new session does not update the sessionClient with this created session, hence my request for improvement.

It would be great if you could focus on the enhancement request to update the sessionClient when a new Session() is created.

Thank you !

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue requestor label Apr 15, 2024
@yuhengshs yuhengshs added improvement Any improvement that's not a bug and not requesting new functionality and removed bug Something isn't working labels Apr 15, 2024
@vincetran
Copy link
Contributor

Hi @AumJobs, thanks for your patience. I took a look at the code you linked and I can kind of see where you're coming from but ultimately I think it may be a symptom of a different issue. Tracing through the code for AutoSessionTracker there shouldn't be a scenario where AnalyticsClient.createEvent(..) is called without an active session (where an active session is created via SessionClient.startSession())

If AutoSessionTracker is working properly, startSession should already be called automatically when the app comes into the foreground and that session should be persisted via SessionClient.

So when the app goes into the background, SessionClient.stopSession() should be called which should act explicitly on that persisted Session from above to call CreateEvent. If that session was null, AnalyticsClient.createEvent(..) would not even be called.

Can you do a further investigation from your side to track down what's causing your specific edge case as this is the first we've seen a report of this happening?

@vincetran vincetran added the pending-response Issue is pending response from the issue requestor label Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analytics Related to the Analytics category/plugins improvement Any improvement that's not a bug and not requesting new functionality pending-response Issue is pending response from the issue requestor
Projects
None yet
Development

No branches or pull requests

4 participants