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

RxAmplify.Analytics - Crash #2943

Closed
1 task done
lolucosmin opened this issue Nov 6, 2024 · 9 comments
Closed
1 task done

RxAmplify.Analytics - Crash #2943

lolucosmin opened this issue Nov 6, 2024 · 9 comments
Assignees
Labels
analytics Related to the Analytics category/plugins bug Something isn't working rx bindings The Rx facade for Amplify

Comments

@lolucosmin
Copy link

lolucosmin commented Nov 6, 2024

Before opening, please confirm:

Language and Async Model

RxJava

Amplify Categories

Analytics

Gradle script dependencies

implementation("com.amplifyframework:core:2.24.0") implementation("com.amplifyframework:aws-auth-cognito:2.24.0") implementation("com.amplifyframework:aws-api:2.24.0") implementation("com.amplifyframework:aws-analytics-pinpoint:2.24.0") implementation("com.amplifyframework:aws-storage-s3:2.24.0") implementation("com.amplifyframework:aws-analytics-pinpoint:2.24.0") implementation("com.amplifyframework:rxbindings:2.24.0") coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.3")

Environment information

# Put output below this line
------------------------------------------------------------
Gradle 8.6
------------------------------------------------------------

Build time:   2024-02-02 16:47:16 UTC
Revision:     d55c486870a0dc6f6278f53d21381396d0741c6e

Kotlin:       1.9.20
Groovy:       3.0.17
Ant:          Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM:          21.0.3 (JetBrains s.r.o. 21.0.3+-12282718-b509.11)
OS:           Windows 11 10.0 amd64

Please include any relevant guides or documentation you're referencing

Amplify V2

Describe the bug

Hi, I am migrating the project to Amplify 2. I followed the steps in the documentation to initialize then to add plugins and everything was fine.

I created hubs for each plugin and for all of them I have InitializationStatus.SUCCEEDED.
I use RxAmplify in my code and was fine until I tried to record a event with RxAmplify.Analytics.recordEvent(event).
When I run that command i get this error:

java.lang.IllegalStateException: Tried to get a plugin but that plugin was not present. Check if the plugin was added originally or perhaps was already removed.
at com.amplifyframework.core.category.Category.getPluginIfConfiguredOrThrow(Category.java:257)
at com.amplifyframework.core.category.Category.getSelectedPlugin(Category.java:252)
at com.amplifyframework.analytics.AnalyticsCategory.enable(AnalyticsCategory.java:72)
at com.bfan.sso.logic.services.analitycs.AnalyticsTracker.createEvent(AnalyticsTracker.java:33)
at com.bfan.sso.gui.base.fragment.BaseFragment.lambda$onViewCreated$0(BaseFragment.java:88)

As you can see from a base fragment I track the content name.
After a while I decide to use Amplify.Analytics.recordEvent(event) and is works fine.

Issue: RxAmplify.Analytics.recordEvent(event) has a problem.
Mention: I use everywhere in the app RxAmplify

Reproduction steps (if applicable)

No response

Code Snippet

// Put your code below this line.

Log output

// Put your logs below this line
java.lang.IllegalStateException: Tried to get a plugin but that plugin was not present. Check if the plugin was added originally or perhaps was already removed.
at com.amplifyframework.core.category.Category.getPluginIfConfiguredOrThrow(Category.java:257)
at com.amplifyframework.core.category.Category.getSelectedPlugin(Category.java:252)
at com.amplifyframework.analytics.AnalyticsCategory.enable(AnalyticsCategory.java:72)
at com.bfan.sso.logic.services.analitycs.AnalyticsTracker.createEvent(AnalyticsTracker.java:33)
at com.bfan.sso.gui.base.fragment.BaseFragment.lambda$onViewCreated$0(BaseFragment.java:88)

amplifyconfiguration.json

No response

GraphQL Schema

// Put your schema below this line

Additional information and screenshots

No response

@github-actions github-actions bot added pending-triage Issue is pending triage pending-maintainer-response Issue is pending response from an Amplify team member labels Nov 6, 2024
@mattcreaser
Copy link
Member

Hi @lolucosmin, could you post your code where you configure Amplify? This exception indicates that the Analytics Plugin isn't being added, you should have something like:

Amplify.addPlugin(AWSCognitoAuthPlugin())
Amplify.addPlugin(AWSS3StoragePlugin())
Amplify.addPlugin(AWSPinpointAnalyticsPlugin()) // ensure this is here
Amplify.configure(...)

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Nov 6, 2024
@mattcreaser mattcreaser added analytics Related to the Analytics category/plugins question General question pending-maintainer-response Issue is pending response from an Amplify team member labels Nov 6, 2024
@github-actions github-actions bot removed the pending-triage Issue is pending triage label Nov 6, 2024
@mattcreaser mattcreaser added pending-community-response Issue is pending response from the issue requestor and removed pending-maintainer-response Issue is pending response from an Amplify team member labels Nov 6, 2024
@lolucosmin
Copy link
Author

lolucosmin commented Nov 6, 2024

Hi @lolucosmin, could you post your code where you configure Amplify? This exception indicates that the Analytics Plugin isn't being added, you should have something like:

Amplify.addPlugin(AWSCognitoAuthPlugin())
Amplify.addPlugin(AWSS3StoragePlugin())
Amplify.addPlugin(AWSPinpointAnalyticsPlugin()) // ensure this is here
Amplify.configure(...)

Sure @mattcreaser :

//init Amplify
AWSApiPlugin apiPlugin = AWSApiPlugin.builder().build();
apiPlugin.configure(AmplifyConfig.Companion.getInstance().getApiConfiguration(), AppApplication.Companion.getInstance());

        RxAmplify.addPlugin(apiPlugin);
        RxAmplify.addPlugin(new AWSCognitoAuthPlugin());
        RxAmplify.addPlugin(new AWSS3StoragePlugin());
        RxAmplify.addPlugin(new AWSPinpointAnalyticsPlugin());

        AmplifyConfiguration configuration = AmplifyConfiguration.builder(AmplifyConfig.Companion.getInstance().getAWSConfiguration())
                .devMenuEnabled(BuildConfig.DEBUG)
                .build();
        RxAmplify.configure(configuration, AppApplication.Companion.getInstance());
        if (BuildConfig.DEBUG) {
            RxAmplify.Logging.enable();
        }

Also I have hub:

Disposable analitycsHubDisposable = RxAmplify.Hub.on(HubChannel.ANALYTICS)
.map(HubEvent::getName)
.subscribe(name -> {
if (name.equals(InitializationStatus.SUCCEEDED.name())) {
isAnalyticsInitialized = true;
LogUtils.i("RxAmplify.ANALYTICS Initialization: " + InitializationStatus.SUCCEEDED.name());

                } else if (name.equals(InitializationStatus.FAILED.name())) {
                    isAnalyticsInitialized = false;
                    LogUtils.i("RxAmplify.ANALYTICS Initialization: " + InitializationStatus.FAILED.name());
                }
            });

    this.compositeDisposable.add(authHubDisposable);
    this.compositeDisposable.add(storageHubDisposable);
    this.compositeDisposable.add(analitycsHubDisposable);

And in hub I get the success event.
Weird is why is working with Amplify.Analytics.recordEvent(event)

@github-actions github-actions bot added pending-maintainer-response Issue is pending response from an Amplify team member and removed pending-community-response Issue is pending response from the issue requestor labels Nov 6, 2024
@mattcreaser
Copy link
Member

mattcreaser commented Nov 6, 2024

Thanks for the additional info @lolucosmin, it seems you have uncovered a surprising bug. This line is a clear bug that means Analytics will never work when using RxAmplify.

I will submit a fix for this issue and we will try to get it released as quickly as we can.

@mattcreaser mattcreaser added bug Something isn't working rx bindings The Rx facade for Amplify labels Nov 6, 2024
@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Nov 6, 2024
@mattcreaser
Copy link
Member

Note: you should also be able to work around this crash by calling RxAmplify.addPlugin(...) instead of Amplify.addPlugin(...). It appears that is the intended way to register plugins when using Rx, but it still should not crash and the current implementation prevents mixing usage for the Analytics category, but not for other categories.

@lolucosmin
Copy link
Author

RxAmplify.addPlugin(...)

I use this if you check my code so still is crashing.

@github-actions github-actions bot added the pending-maintainer-response Issue is pending response from an Amplify team member label Nov 6, 2024
@mattcreaser
Copy link
Member

Ah my mistake, you're right. It doesn't matter which you use. This will be fixed soon.

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Nov 6, 2024
@mattcreaser mattcreaser self-assigned this Nov 14, 2024
@mattcreaser mattcreaser added pending-release Code has been merged but pending release and removed question General question labels Nov 15, 2024
@mattcreaser
Copy link
Member

The fix for this issue has been merged and will be included in our next release.

@mattcreaser
Copy link
Member

This fix has been released in Amplify 2.24.1. Please let us know if you have any issues!

@github-actions github-actions bot removed the pending-release Code has been merged but pending release label Nov 21, 2024
Copy link
Contributor

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

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 bug Something isn't working rx bindings The Rx facade for Amplify
Projects
None yet
Development

No branches or pull requests

2 participants