rudderlabs / rudder-sdk-android

Android SDK for RudderStack - the Customer Data Platform for Developers.
https://www.rudderstack.com
Other
18 stars 29 forks source link

Event is not reaching to server when config field is empty in rudder server config #429

Closed prajjwal-epifi closed 4 months ago

prajjwal-epifi commented 4 months ago

We are currently using a very old version of the Rudder SDK and would like to upgrade to a newer version. While testing newer version 1.21.3, we found that events are not reaching our backend server.

After debugging the SDK, I discovered that when server config file did not include the config field during SDK initialization, which resulted in the following error: Error: Attempt to invoke virtual method 'com.rudderstack.android.sdk.core.SourceConfiguration$Metrics com.rudderstack.android.sdk.core.SourceConfiguration$StatsCollection.getMetrics()' on a null object reference.

It seems that the issue is caused by the following line of code: https://github.com/rudderlabs/rudder-sdk-android/blob/7176a6851d5782ff15489a219f415e7236e8e086/core/src/main/java/com/rudderstack/android/sdk/core/EventRepository.java#L276

if (serverConfig.source.sourceConfiguration != null)
             enableStatsCollection(application, writeKey, serverConfig.source.sourceConfiguration.getStatsCollection());

here is my server config file

{
  "source": {
    "config": {},
    "id": "XXXXXX",
    "name": "XXX",
    "writeKey": "",
    "enabled": true,
    "sourceDefinitionId": "XXXXX",
    "deleted": false,
    "createdAt": "Sat Oct 10 2020 22:09:05 GMT+0530 (India Standard Time)",
    "updatedAt": "Sat Oct 10 2020 22:09:05 GMT+0530 (India Standard Time)",
    "sourceDefinition": {
      "id": "XXXXXXX",
      "name": "Android",
      "displayName": "Android",
      "category": null,
      "createdAt": "2019-09-02T08:08:08.373Z",
      "updatedAt": "2020-06-18T11:54:00.449Z"
    },
    "destinations": []
  },
  "metadata": {
    "version": "1.0.2"
  }
}

Please let me know if anything is needed from my side.

1abhishekpandey commented 4 months ago

Hey @prajjwal-epifi, Can you please let us know where you are getting that sourceConfig? Do you populate this config? As the required fields are already present if you use the writeKey from app.rudderstack.com.

If you're hosting this file, make sure to add these values to the config object:

"config": {
            "statsCollection": {
                "errors": {
                    "enabled": true
                },
                "metrics": {
                    "enabled": false
                }
            }
        },

You may set the both values as false.

prajjwal-epifi commented 4 months ago

Thanks @1abhishekpandey , We will add these fields to unblock ourselves. However, please consider fixing the null object reference issue.

1abhishekpandey commented 4 months ago

Hey @prajjwal-epifi, Thanks for pointing this out. I've informed the team, and we are planning to fix this soon.