Snowplow Micro not receiving events from Android SDK

I am trying to get the Android SDK to point to Snowplow Micro, but having no luck.

Following the guide here:

I am setting up using the following:

export MICRO_IGLU_API_KEY=<mykey>
export MICRO_IGLU_REGISTRY_URL=<my_url>

docker run -p 9090:9090 \
 -e MICRO_IGLU_REGISTRY_URL \
 -e MICRO_IGLU_API_KEY \
 snowplow/snowplow-micro:2.1.0

Which runs fine and I can see the UI (e.g. http://localhost:9090/micro/ui)

My Snowplow SDK setup is as follows (note: I have tried with http and https)

    private fun initSnowPlow() {
        val emitter =
            Emitter.EmitterBuilder("localhost:9090", applicationContext)
            .security(RequestSecurity.HTTPS)
            .build()

        val subject =
            Subject.SubjectBuilder()
            .context(appContext)
            .build()

        Tracker.init(
            Tracker.TrackerBuilder(
                emitter,
                getString(R.string.app_name),
                appContext?.getAppVersion(),
                appContext
            )
                .level(DEBUG)
                .lifecycleEvents(true)
                .base64(false)
                .subject(subject)
                .sessionContext(true)
                .mobileContext(true)
                .geoLocationContext(false)
                .applicationCrash(true)
                .sessionCheckInterval(10)
                .foregroundTimeout(300)
                .backgroundTimeout(120)
                .build()
        )
    }

I can see in the App logs (logcat) I am getting the following errors


pool-32-thread-2|Ensure collector path is valid: https://localhost:9090/com.snowplowanalytics.snowplow/tp2
pool-32-thread-2|Emitter loop stopping: failures.
pool-32-thread-1|Added event to database: 8
pool-32-thread-1|Tracker connection online: true
pool-32-thread-1|Request Futures: 1
pool-32-thread-2|Request sending failed: java.net.ConnectException: Failed to connect to localhost/127.0.0.1:9090
pool-32-thread-1|Request sending failed but we will retry later.

Does anyone know what may be going on here?

:wave: I don’t know much about how the emulator works but I suspect it’s because localhost is a relative term, and within the emulator it means a different address to your machine’s localhost.

I think this might be helpful - seems like there are ways to get the emulator to speak to your machine’s network.

Hope that’s helpful!

3 Likes

Thanks for this quick response.

Indeed that was it! I also needed to ensure the port matched what I was setting up the server with.

1 Like

Another option to avoid any confusion when using emulators with Micro is to try Ngrok, which lets you expose Micro with a public IP. You can check out more details here: Connecting remote sites and apps | Snowplow Documentation.