Skip to content

Commit

Permalink
Proper sdk name reporting for sentry event; test (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
semuserable committed Apr 16, 2021
1 parent ea7f98f commit cb9e03a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
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

0 comments on commit cb9e03a

Please sign in to comment.