Skip to content

CloudWatch Logging Plugin Does Not Update Category State to CONFIGURED, Causing Initialization Issues #3019

@giacomocarrozzo

Description

@giacomocarrozzo

Before opening, please confirm:

Language and Async Model

Kotlin

Amplify Categories

Logging

Gradle script dependencies

implementation(libs.amplify.core)
implementation(libs.amplify.auth.cognito)
implementation(libs.amplify.logging.cloudwatch)
implementation(libs.apollo.appsync.amplify)
coreLibraryDesugaring(libs.desugar)

amplify-core = { group = "com.amplifyframework", name = "core-kotlin", version.ref = "amplify" }
amplify-auth-cognito = { group = "com.amplifyframework", name = "aws-auth-cognito", version.ref = "amplify" }
amplify-logging-cloudwatch = { group = "com.amplifyframework", name = "aws-logging-cloudwatch", version.ref = "amplify" }
apollo-appsync-amplify = { module = "com.amplifyframework:apollo-appsync-amplify", version.ref = "apollo-appsync-amplify" }

amplify = "2.27.1"
apollo-appsync-amplify = "1.1.0"

Environment information

------------------------------------------------------------ Gradle 8.11.1 ------------------------------------------------------------

Build time: 2024-11-20 16:56:46 UTC
Revision: 481cb05a490e0ef9f8620f7873b83bd8a72e7c39

Kotlin: 2.0.20
Groovy: 3.0.22
Ant: Apache Ant(TM) version 1.10.14 compiled on August 16 2023
Launcher JVM: 21.0.5 (JetBrains s.r.o. 21.0.5+-13047016-b750.29)
Daemon JVM: C:\Program Files\Android\Android Studio\jbr (no JDK specified, using current Java home)
OS: Windows 11 10.0 amd64

Please include any relevant guides or documentation you're referencing

https://docs.amplify.aws/android/build-a-backend/add-aws-services/logging/set-up-logging/

Describe the bug

Describe the bug
When following the official Amplify Android logging setup guide, the CloudWatch Logging Plugin never sets the LoggingCategory state to CONFIGURED. As a result, calls to Amplify.Logging.getPlugin("awsCloudWatchLoggingPlugin") fail with a Failed to get plugin because initialization previously failed exception, even though the plugin is added and configured in code.

Other plugins (for example, the Auth Plugin) properly update the category’s state to CONFIGURED upon a successful configure(). However, in the LoggingCategory implementation, there is no corresponding state update, and this leads to ongoing initialization and usage issues.

Expected behavior
After the plugin is successfully configured, the LoggingCategory should be set to CONFIGURED—similar to how other categories (e.g., Auth) behave—allowing calls to retrieve the plugin instance without failing.


Logs

Worker Logs 2025-04-12 15:35:09.061 12261-12261 WM-DelayedWorkTracker it.evenpos.kiosk D Scheduling work 3f90de6a-de2c-46aa-a998-0895557625f2 2025-04-12 15:35:09.063 12261-12261 WM-GreedyScheduler it.evenpos.kiosk D Starting tracking for 3f90de6a-de2c-46aa-a998-0895557625f2 2025-04-12 15:35:09.071 12261-12328 WM-ConstraintTracker it.evenpos.kiosk D NetworkStateTracker24: initial state = NetworkState(isConnected=true, isValidated=true, isMetered=false, isNotRoaming=true) 2025-04-12 15:35:09.071 12261-12328 WM-NetworkStateTracker it.evenpos.kiosk D Registering network callback 2025-04-12 15:35:09.076 12261-12333 WM-GreedyScheduler it.evenpos.kiosk D Constraints met: Scheduling work ID WorkGenerationalId(workSpecId=3f90de6a-de2c-46aa-a998-0895557625f2, generation=0) 2025-04-12 15:35:09.081 12261-12335 WM-NetworkStateTracker it.evenpos.kiosk D Network capabilities changed: [ Transports: WIFI Capabilities: NOT_METERED&INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VPN&VALIDATED&NOT_ROAMING&FOREGROUND&NOT_CONGESTED&NOT_SUSPENDED&NOT_VCN_MANAGED LinkUpBandwidth>=61727Kbps LinkDnBandwidth>=41893Kbps TransportInfo: , BSSID: 02:00:00:00:00:00, MAC: 02:00:00:00:00:00, IP: /192.168.0.133, Security type: 2, Supplicant state: COMPLETED, Wi-Fi standard: 5, RSSI: -41, Link speed: 200Mbps, Tx Link speed: 200Mbps, Max Supported Tx Link speed: 200Mbps, Rx Link speed: 6Mbps, Max Supported Rx Link speed: 200Mbps, Frequency: 5220MHz, Net ID: -1, Metered hint: false, score: 60, isUsable: true, CarrierMerged: false, SubscriptionId: -1, IsPrimary: 1, Trusted: true, Restricted: false, Ephemeral: false, OEM paid: false, OEM private: false, OSU AP: false, FQDN: , Provider friendly name: , Requesting package name: MLO Information: , AP MLD Address: , AP MLO Link Id: , AP MLO Affiliated links: > SignalStrength: -41 AdminUids: [1000] SSID: "BrunoNet" UnderlyingNetworks: Null] 2025-04-12 15:35:09.099 12261-12333 WM-Processor it.evenpos.kiosk D Processor: processing WorkGenerationalId(workSpecId=3f90de6a-de2c-46aa-a998-0895557625f2, generation=0) 2025-04-12 15:35:09.119 12261-12261 WM-WorkerWrapper it.evenpos.kiosk D Starting work for com.amplifyframework.logging.cloudwatch.worker.CloudwatchRouterWorker 2025-04-12 15:35:09.175 12261-12333 WM-Processor it.evenpos.kiosk D Processor cancelling 3f90de6a-de2c-46aa-a998-0895557625f2 2025-04-12 15:35:09.176 12261-12333 WM-Processor it.evenpos.kiosk D WorkerWrapper interrupted for 3f90de6a-de2c-46aa-a998-0895557625f2 2025-04-12 15:35:09.178 12261-12333 WM-GreedyScheduler it.evenpos.kiosk D Cancelling work ID 3f90de6a-de2c-46aa-a998-0895557625f2 2025-04-12 15:35:09.192 12261-12333 WM-SystemJobScheduler it.evenpos.kiosk D Scheduling work ID ccb566e3-3a63-42bc-a10d-ad8e84ac4004Job ID 4779 2025-04-12 15:35:09.199 12261-12333 WM-WorkerWrapper it.evenpos.kiosk I Work [ id=3f90de6a-de2c-46aa-a998-0895557625f2, tags={ com.amplifyframework.logging.cloudwatch.worker.CloudwatchRouterWorker,CloudwatchLogsSyncWorker } ] was cancelled (Ask Gemini) androidx.work.impl.WorkerStoppedException at androidx.work.impl.WorkerWrapper.interrupt(WorkerWrapper.kt:348) at androidx.work.impl.Processor.interrupt(Processor.java:439) at androidx.work.impl.Processor.stopAndCancelWork(Processor.java:280) at androidx.work.impl.utils.CancelWorkRunnable.cancel(CancelWorkRunnable.kt:33) at androidx.work.impl.utils.CancelWorkRunnable.forNameInline$lambda$0(CancelWorkRunnable.kt:127) at androidx.work.impl.utils.CancelWorkRunnable.$r8$lambda$gmz-7SyxTGDd6CwHjvOsJ11-hcc(Unknown Source:0) at androidx.work.impl.utils.CancelWorkRunnable$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0) at androidx.room.RoomDatabase.runInTransaction(RoomDatabase.kt:585) at androidx.work.impl.utils.CancelWorkRunnable.forNameInline(CancelWorkRunnable.kt:123) at androidx.work.impl.utils.EnqueueRunnable.enqueueWorkWithPrerequisites(EnqueueRunnable.java:249) at androidx.work.impl.utils.EnqueueRunnable.enqueueContinuation(EnqueueRunnable.java:136) at androidx.work.impl.utils.EnqueueRunnable.processContinuation(EnqueueRunnable.java:129) at androidx.work.impl.utils.EnqueueRunnable.addToDatabase(EnqueueRunnable.java:93) at androidx.work.impl.utils.EnqueueRunnable.enqueue(EnqueueRunnable.java:74) at androidx.work.impl.WorkContinuationImpl.lambda$enqueue$0$androidx-work-impl-WorkContinuationImpl(WorkContinuationImpl.java:201) at androidx.work.impl.WorkContinuationImpl$$ExternalSyntheticLambda0.invoke(D8$$SyntheticClass:0) at androidx.work.OperationKt.launchOperation$lambda$2$lambda$1(Operation.kt:50) at androidx.work.OperationKt.$r8$lambda$XKAkIiEN7OgIvwuLUZRQpJhjmyE(Unknown Source:0) at androidx.work.OperationKt$$ExternalSyntheticLambda1.run(D8$$SyntheticClass:0) at androidx.work.impl.utils.SerialExecutorImpl$Task.run(SerialExecutorImpl.java:96) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644) at java.lang.Thread.run(Thread.java:1012) 2025-04-12 15:35:09.200 12261-12333 WM-WorkerWrapper it.evenpos.kiosk D Status for 3f90de6a-de2c-46aa-a998-0895557625f2 is null ; not doing any work 2025-04-12 15:35:09.201 12261-12261 WM-Processor it.evenpos.kiosk D Processor 3f90de6a-de2c-46aa-a998-0895557625f2 executed; reschedule = false 2025-04-12 15:35:09.201 12261-12261 WM-GreedyScheduler it.evenpos.kiosk D Stopping tracking for WorkGenerationalId(workSpecId=3f90de6a-de2c-46aa-a998-0895557625f2, generation=0) 2025-04-12 15:35:09.202 12261-12333 WM-StopWorkRunnable it.evenpos.kiosk D StopWorkRunnable for 3f90de6a-de2c-46aa-a998-0895557625f2; Processor.stopWork = false 2025-04-12 15:35:09.204 12261-12333 WM-GreedyScheduler it.evenpos.kiosk D Cancelling work ID 3f90de6a-de2c-46aa-a998-0895557625f2 2025-04-12 15:35:09.206 12261-12333 WM-NetworkStateTracker it.evenpos.kiosk D Unregistering network callback

val plugin = Amplify.Logging.getPlugin("awsCloudWatchLoggingPlugin") as? AWSCloudWatchLoggingPlugin

Get Plugin Logs 2025-04-12 15:36:18.353 12261-12261 AndroidRuntime it.evenpos.kiosk E FATAL EXCEPTION: main (Ask Gemini) Process: it.evenpos.kiosk, PID: 12261 java.lang.IllegalStateException: Failed to get plugin because initialization previously failed. See attached exception for details. at com.amplifyframework.core.category.Category.getPluginIfConfiguredOrThrow(Category.java:272) at com.amplifyframework.core.category.Category.getPlugin(Category.java:223) at it.evenpos.kiosk.ui.order.OrderViewModel.onEvent(OrderViewModel.kt:636) at it.evenpos.kiosk.ui.order.OrderScreenKt$OrderScreen$2$2$1.invoke$lambda$1$lambda$0(OrderScreen.kt:125) at it.evenpos.kiosk.ui.order.OrderScreenKt$OrderScreen$2$2$1.$r8$lambda$liFo_W2my-decpshWQNSwMhg2Hg(Unknown Source:0) at it.evenpos.kiosk.ui.order.OrderScreenKt$OrderScreen$2$2$1$$ExternalSyntheticLambda0.invoke(D8$$SyntheticClass:0) at it.evenpos.kiosk.ui.order.partials.OrderDetailsPanelKt.DraftOrderHeader$lambda$25$lambda$24$lambda$23(OrderDetailsPanel.kt:285) at it.evenpos.kiosk.ui.order.partials.OrderDetailsPanelKt.$r8$lambda$WLx5bywMyUvdfm1cSn0FCgk3VxE(Unknown Source:0) at it.evenpos.kiosk.ui.order.partials.OrderDetailsPanelKt$$ExternalSyntheticLambda17.invoke(D8$$SyntheticClass:0) at androidx.compose.foundation.ClickableNode$clickPointerInput$3.invoke-k-4lQ0M(Clickable.kt:639) at androidx.compose.foundation.ClickableNode$clickPointerInput$3.invoke(Clickable.kt:633) at androidx.compose.foundation.gestures.TapGestureDetectorKt$detectTapAndPress$2$1.invokeSuspend(TapGestureDetector.kt:255) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTaskKt.resume(DispatchedTask.kt:163) at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:152) at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:470) at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl$kotlinx_coroutines_core(CancellableContinuationImpl.kt:504) at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl$kotlinx_coroutines_core$default(CancellableContinuationImpl.kt:493) at kotlinx.coroutines.CancellableContinuationImpl.resumeWith(CancellableContinuationImpl.kt:359) at androidx.compose.ui.input.pointer.SuspendingPointerInputModifierNodeImpl$PointerEventHandlerCoroutine.offerPointerEvent(SuspendingPointerInputFilter.kt:719) at androidx.compose.ui.input.pointer.SuspendingPointerInputModifierNodeImpl.dispatchPointerEvent(SuspendingPointerInputFilter.kt:598) at androidx.compose.ui.input.pointer.SuspendingPointerInputModifierNodeImpl.onPointerEvent-H0pRuoY(SuspendingPointerInputFilter.kt:620) at androidx.compose.foundation.AbstractClickableNode.onPointerEvent-H0pRuoY(Clickable.kt:1044) at androidx.compose.ui.input.pointer.Node.dispatchMainEventPass(HitPathTracker.kt:387) at androidx.compose.ui.input.pointer.NodeParent.dispatchMainEventPass(HitPathTracker.kt:229) at androidx.compose.ui.input.pointer.HitPathTracker.dispatchChanges(HitPathTracker.kt:144) at androidx.compose.ui.input.pointer.PointerInputEventProcessor.process-BIzXfog(PointerInputEventProcessor.kt:120) at androidx.compose.ui.platform.AndroidComposeView.sendMotionEvent-8iAsVTc(AndroidComposeView.android.kt:1994) at androidx.compose.ui.platform.AndroidComposeView.handleMotionEvent-8iAsVTc(AndroidComposeView.android.kt:1945) at androidx.compose.ui.platform.AndroidComposeView.dispatchTouchEvent(AndroidComposeView.android.kt:1829) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802) 2025-04-12 15:36:18.355 12261-12261 AndroidRuntime it.evenpos.kiosk E at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:500) (Ask Gemini) at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1905) at android.app.Dialog.dispatchTouchEvent(Dialog.java:921) at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:458) at android.view.View.dispatchPointerEvent(View.java:15270) at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:6667) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:6467) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5913) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5970) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5936) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:6101) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5944) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:6158) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5917) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5970) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5936) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5944) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5917) at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:9009) at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:8960) at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:8928) at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:9132) at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:268) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:335) at android.os.Looper.loopOnce(Looper.java:161) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7935) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942) Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [androidx.compose.ui.platform.MotionDurationScaleImpl@7b541e0, androidx.compose.runtime.BroadcastFrameClock@57f7c99, StandaloneCoroutine{Cancelling}@694db5e, AndroidUiDispatcher@ec3b3f] Caused by: AmplifyException{message=Tried to init before category was not configured., cause=null, recoverySuggestion=Call configure() on category, first.} at com.amplifyframework.core.category.Category.initialize(Category.java:151) at com.amplifyframework.core.Amplify.lambda$beginInitialization$0(Amplify.java:224) at com.amplifyframework.core.Amplify$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644) at java.lang.Thread.run(Thread.java:1012)

Additional context
Referencing lines in Category.java#L78-L103 and LoggingCategory.java#L138-L143. The call to update the category’s state to CONFIGURED appears missing from the Logging plugin’s setup routine.

amplifyconfiguration.json

{
  "auth": {
    "user_pool_id": "eu-south-1_XXXXXXXX",
    "aws_region": "eu-south-1",
    "user_pool_client_id": "XXXXXXXX"
  },
  "version": "1.1"
}

amplifyconfiguration_logging.json

{
  "awsCloudWatchLoggingPlugin": {
    "enable": true,
    "logGroupName": "androidapp",
    "region": "eu-south-1",
    "localStoreMaxSizeInMB": 1,
    "flushIntervalInSeconds": 10,
    "loggingConstraints": {
      "defaultLogLevel": "DEBUG"
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingloggingRelated to the Logging category/plugins

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions