Debugging

Debug Message Sending

To debug various flows inside the SDK, you can pass your own ChatClientDebugger implementation:

val client = ChatClient.Builder("apiKey", context)
    .clientDebugger(CustomChatClientDebugger())
    .build()

ChatClientDebugger might be useful in investigation of issues happening on users side.

For example, to debug a message sending flow you can override ChatClientDebugger.debugSendMessage function and provide your own SendMessageDebugger implementation:

import io.getstream.result.Error

class CustomChatClientDebugger : ChatClientDebugger {

    override fun onNonFatalErrorOccurred(
        tag: String,
        src: String,
        desc: String,
        error: Error,
    ) {
        // TODO: Implement your custom logic here
    }

    override fun debugSendMessage(
        channelType: String,
        channelId: String,
        message: Message,
        isRetrying: Boolean,
    ): SendMessageDebugger {
        return CustomSendMessageDebugger(
            channelType,
            channelId,
            message,
            isRetrying
        )
    }
}

Then in you custom SendMessageDebugger implementation you will be able to handle the entire message sending flow:

class CustomSendMessageDebugger(
    private val channelType: String,
    private val channelId: String,
    private val message: Message,
    private val isRetrying: Boolean,
) : SendMessageDebugger {

    override fun onStart(message: Message) {
        // Called when the message sending flow starts.
    }

    override fun onInterceptionStart(message: Message) {
        // Called when the message interception before sending it to the API starts.
        // Reasons for interception might be:
        //   - message attachment uploading
        //   - message enriching by all required information
    }

    override fun onInterceptionUpdate(message: Message) {
        // Called when there are intermediate message data updates.
    }

    override fun onInterceptionStop(result: Result<Message>, message: Message) {
        // Called when the message interception before sending it to the API stops.
    }

    override fun onSendStart(message: Message) {
        // Called when the message sending to the API starts.
    }

    override fun onSendStop(result: Result<Message>, message: Message) {
        // Called when the message sending to the API stops.
    }

    override fun onStop(result: Result<Message>, message: Message) {
        // Called when the message sending flow stops.
    }
}

Debug Requests

The SDK includes a tool to debug requests and help the user to understand how and when the backend is being requested.

ApiRequestsAnalyser

The ApiRequestsAnalyser can be called at any time to print out all the requests that were made with their information.

Enable it using:

ChatClient.Builder(apiKey, context)
    .debugRequests(true)
    .build()

Then you can request the information for the requests used ApiRequestsAnalyser.dumpRequestByName or ApiRequestsAnalyser.dumpAll.

To clear the information of the analyser to focus on some information, it is possible to clear the data using ApiRequestsAnalyser.clearRequestContaining or ApiRequestsAnalyse.clearAll.

© Getstream.io, Inc. All Rights Reserved.