Cysharp / MagicOnion

Unified Realtime/API framework for .NET platform and Unity.
MIT License
3.8k stars 424 forks source link

[Preview] Introduce IStreamingHubDiagnosticHandler #746

Closed mayuki closed 6 months ago

mayuki commented 6 months ago

This PR introduces an API for diagnosing and tracing the communication of StreamingHub. The API is in preview and may be subject to change in the future.

This API only supports the Source Generator at this moment and you need to set the EnableStreamingHubDiagnosticHandler option to true in the generation options. By setting this option, the StreamingHubDiagnosticHandler property will be added to the generated class, allowing you to set a handler.

namespace MagicOnion.Client;

/// <summary>
/// [Preview] The interface of the handler for StreamingHub diagnostics. This API may change in the future.
/// </summary>
public interface IStreamingHubDiagnosticHandler
{
    /// <summary>
    /// The callback method at the beginning of a Hub method request. This API may change in the future.
    /// </summary>
    void OnRequestBegin<THub, TRequest>(THub hubInstance, Guid requestId, string methodName, TRequest request, bool isFireAndForget);

    /// <summary>
    /// [Preview] The callback method at the end of a Hub method request. This API may change in the future.
    /// </summary>
    void OnRequestEnd<THub, TResponse>(THub hubInstance, Guid requestId, string methodName, TResponse response);

    /// <summary>
    /// [Preview] The callback method when a method of HubReceiver is invoked. This API may change in the future.
    /// </summary>
    void OnBroadcastEvent<THub, T>(THub hubInstance, string methodName, T value);
}