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

Proper sdk name reporting for sentry event; test #111

Merged
merged 3 commits into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

### Features

- Strip zeroes for ill2cpp builds(#108)
- Strip zeroes for ill2cpp builds (#108)
- Proper sdk name reporting for sentry event (#111)

## 0.0.6

Expand Down
26 changes: 14 additions & 12 deletions src/Sentry.Unity/UnityEventProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Sentry.Extensibility;
using Sentry.Protocol;
using UnityEngine;
using DeviceOrientation = Sentry.Protocol.DeviceOrientation;

namespace Sentry.Unity
{
internal static class UnitySdkInfo
{
public static string Version { get; } = typeof(UnitySdkInfo).Assembly.GetName().Version.ToString();


public const string Name = "sentry.dotnet.unity";
public const string PackageName = "upm:sentry.unity";
}

internal class UnityEventProcessor : ISentryEventProcessor
{
public SentryEvent? Process(SentryEvent @event)
public SentryEvent Process(SentryEvent @event)
{
if (@event is null)
{
return null;
}
// Add some Unity specific context:

var version = "0.0.1-alpha";
// TODO Sdk shouldn't be marked as nullable
@event.Sdk!.AddPackage("github:sentry.unity", version);
@event.Sdk.Name = "sentry.unity";
@event.Sdk.Version = version;
@event.Sdk.AddPackage(UnitySdkInfo.PackageName, UnitySdkInfo.Version);
@event.Sdk.Name = UnitySdkInfo.Name;
@event.Sdk.Version = UnitySdkInfo.Version;

@event.Contexts.OperatingSystem.Name = SystemInfo.operatingSystem;

Expand Down
22 changes: 22 additions & 0 deletions src/test/Sentry.Unity.Tests/PlayModeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,28 @@ public IEnumerator UnityEventExceptionProcessor_ILL2CPPStackTraceFilenameWithZer
Assert.AreEqual(string.Empty, sentryExceptionFirstFrame.FileName);
}

[UnityTest]
public IEnumerator UnityEventProcessor_SdkInfo_Correct()
{
yield return SetupSceneCoroutine("BugFarmScene");

// arrange
var unityEventProcessor = new UnityEventProcessor();
var sentryEvent = new SentryEvent();

// act
unityEventProcessor.Process(sentryEvent);

// assert
Assert.AreEqual(UnitySdkInfo.Name, sentryEvent.Sdk.Name);
Assert.AreEqual(UnitySdkInfo.Version, sentryEvent.Sdk.Version);

var package = sentryEvent.Sdk.Packages.FirstOrDefault();
Assert.IsNotNull(package);
Assert.AreEqual(UnitySdkInfo.PackageName, package!.Name);
Assert.AreEqual(UnitySdkInfo.Version, package!.Version);
}

private static IEnumerator SetupSceneCoroutine(string sceneName)
{
// load scene with initialized Sentry, SceneManager.LoadSceneAsync(sceneName);
Expand Down