Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.

Conversation

uskey512
Copy link
Contributor

@uskey512 uskey512 commented Jan 1, 2021

Changed the return value of the following methods from void to Coroutine.

public static void CaptureMessage(string message);
public static void CaptureEvent(SentryEvent @event);
private void DoCaptureMessage(string message);
private void DoCaptureEvent(SentryEvent @event);

By returning the executed ContinueSendingEvent as a Coroutine, the SDK user can process its state.

As an example, by modifying SentryTest.cs as follows, it can assure that a program running on a mobile platform will exit after the process of sending to Sentry is completed.
(Note that it uses UniRx.)

using UnityEngine.Assertions;
using UnityEngine;
using System;
using Sentry;
using UniRx;

public class SentryTest : MonoBehaviour {
    private int _counter = 0;

    private void Update() {
        _counter++;
        if (_counter % 100 == 0) // every 100 frames
        {
            SentrySdk.AddBreadcrumb("Frame number: " + _counter);
        }
    }

    private new void SendMessage(string message) {
        if (message == "exception") {
            throw new DivideByZeroException();
        } else if (message == "assert") {
            Assert.AreEqual(message, "not equal");
        } else if (message == "message") {
            QuitWithSentry("this is a message");
        } else if (message == "event") {
            var @event = new SentryEvent("Event message") {
                level = "debug"
            };

            SentrySdk.CaptureEvent(@event);
        }
    }

    private async void QuitWithSentry(string message) {
        await SentrySdk.CaptureMessage(message);
        Application.Quit();
    }
}

@uskey512 uskey512 requested a review from bruno-garcia as a code owner January 1, 2021 11:47
@uskey512
Copy link
Contributor Author

uskey512 commented Jan 1, 2021

This Pull Request is related to the #5 .

@bruno-garcia bruno-garcia merged commit b7150f0 into getsentry:main Jan 5, 2021
@bruno-garcia
Copy link
Member

Thanks @uskey512

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants