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

Feature/conviva/error details #39

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.theoplayer.android.connector.analytics.conviva.utils.calculateBufferL
import com.theoplayer.android.connector.analytics.conviva.utils.calculateConvivaOptions
import com.theoplayer.android.connector.analytics.conviva.utils.collectContentMetadata
import com.theoplayer.android.connector.analytics.conviva.utils.collectPlayerInfo
import com.theoplayer.android.connector.analytics.conviva.utils.flattenErrorObject
import java.lang.Double.isFinite

private const val TAG = "ConvivaHandler"
Expand Down Expand Up @@ -138,9 +139,17 @@ class ConvivaHandler(
if (BuildConfig.DEBUG) {
Log.d(TAG, "onError: ${event.errorObject.message}")
}

val error = event.errorObject
// Report error details in a separate event, which should be passed a flat <String, String> map.
val errorDetails = flattenErrorObject(error)
if (errorDetails.isNotEmpty()) {
convivaVideoAnalytics.reportPlaybackEvent("ErrorDetailsEvent", errorDetails)
}

// Report error and cleanup immediately.
// The contentInfo provides metadata for the failed video.
reportPlaybackFailed(event.errorObject.message ?: "Fatal error occurred")
reportPlaybackFailed(error.message ?: "Fatal error occurred")
}

onSegmentNotFound = EventListener<SegmentNotFoundEvent> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.conviva.sdk.ConvivaSdkConstants
import com.theoplayer.android.api.THEOplayerGlobal
import com.theoplayer.android.api.ads.AdBreak
import com.theoplayer.android.api.ads.GoogleImaAd
import com.theoplayer.android.api.error.THEOplayerException
import com.theoplayer.android.api.player.Player
import com.theoplayer.android.connector.analytics.conviva.ConvivaConfiguration
import com.theoplayer.android.connector.analytics.conviva.ConvivaMetadata
Expand Down Expand Up @@ -158,4 +159,13 @@ fun calculateBufferLength(player: Player): Long {
}
}
return (1e3 * bufferLength).toLong()
}
}

fun flattenErrorObject(error: THEOplayerException): Map<String, String> {
return mapOf(
"code" to error.code.name,
"category" to error.category.name,
"stack" to (error.cause?.stackTraceToString() ?: ""),
"message" to (error.cause?.message ?: "")
).filterValues { it != "" } // Remove entries with empty values
}