Skip to content

Commit 9a8e53f

Browse files
authored
feat: sentry 4.0.0 (#6648)
1 parent f08c5c1 commit 9a8e53f

26 files changed

Lines changed: 239 additions & 289 deletions

.github/workflows/build-unitycloud.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,7 @@ jobs:
346346
PARAM_BUILD_VERSION: ${{ needs.prebuild.outputs.version }}
347347
PARAM_SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
348348
PARAM_SENTRY_ENVIRONMENT: ${{ needs.prebuild.outputs.sentry_environment }}
349-
PARAM_SENTRY_CLI_AUTH_TOKEN: ${{ secrets.SENTRY_CLI_AUTH_TOKEN }}
350349
PARAM_SENTRY_ENABLED: ${{ needs.prebuild.outputs.sentry_enabled }}
351-
PARAM_SENTRY_UPLOAD_DEBUG_SYMBOLS: ${{ needs.prebuild.outputs.sentry_upload_symbols }}
352350
PARAM_SEGMENT_WRITE_KEY: ${{ secrets.SEGMENT_WRITE_KEY }}
353351
PARAM_INSTALL_SOURCE: ${{ needs.prebuild.outputs.install_source }}
354352
PARAM_UNITY_EXTRA_PARAMS: '-disable-assembly-updater'
@@ -558,6 +556,19 @@ jobs:
558556
build/**/*_BackUpThisFolder_ButDontShipItWithYourGame
559557
build/**/*_BurstDebugInformation_DoNotShip
560558
if-no-files-found: error
559+
560+
- name: Upload debug symbols to Sentry
561+
if: ${{ needs.prebuild.outputs.sentry_enabled == 'true' }}
562+
shell: bash
563+
env:
564+
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_CLI_AUTH_TOKEN }}
565+
SENTRY_ORG: ${{ vars.SENTRY_ORG }}
566+
SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }}
567+
run: |
568+
npx --yes @sentry/cli debug-files upload \
569+
--org "$SENTRY_ORG" \
570+
--project "$SENTRY_PROJECT" \
571+
"build"
561572
562573
# Will run always (even if failing)
563574
- name: Upload cloud logs
@@ -598,4 +609,4 @@ jobs:
598609
API_KEY: ${{ secrets.UNITY_CLOUD_API_KEY }}
599610
ORG_ID: ${{ secrets.UNITY_CLOUD_ORG_ID }}
600611
PROJECT_ID: ${{ secrets.UNITY_CLOUD_PROJECT_ID }}
601-
run: python -u scripts/cloudbuild/build.py --cancel
612+
run: python -u scripts/cloudbuild/build.py --cancel

Explorer/Assets/DCL/Infrastructure/ECS/StreamableLoading/AssetBundles/AssetBundleManifestFallbackHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ private static async UniTask CheckAssetBundleManifestFallbackInternalAsync(World
3939
await UniTask.SwitchToMainThread();
4040

4141
// Log breadcrumb and report exception disabled while we have separate flows for backpack and emotes. They need to be re-enabled once we unify the flows with the trimmed version.
42-
//SentrySdk.AddBreadcrumb($"AB manifest version missing for entity: {entityDefinition.id}");
42+
//Sentry.Unity.SentrySdk.AddBreadcrumb($"AB manifest version missing for entity: {entityDefinition.id}");
4343
//ReportHub.LogException(new Exception("AssetBundleManifestFallbackHelper: AB Manifest Fallback requested"), ReportCategory.ASSET_BUNDLES);
4444

4545
var promise = AssetBundleManifestPromise.Create(world,

Explorer/Assets/DCL/Infrastructure/Global/Dynamic/BootstrapContainer.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,10 @@ private static (IVerifiedEthereumApi web3VerifiedAuthenticator, IWeb3VerifiedAut
247247

248248
private static IReportsHandlingSettings ProvideReportHandlingSettingsAsync(BootstrapSettings settings, IAppArgs applicationParametersParser)
249249
{
250-
ReportsHandlingSettings baseSettings =
251250
#if (DEVELOPMENT_BUILD || UNITY_EDITOR) && !ENABLE_PROFILING
252-
settings.ReportHandlingSettingsDevelopment;
251+
ReportsHandlingSettings baseSettings = settings.ReportHandlingSettingsDevelopment;
253252
#else
254-
settings.ReportHandlingSettingsProduction;
253+
ReportsHandlingSettings baseSettings = settings.ReportHandlingSettingsProduction;
255254
#endif
256255

257256
IReportsHandlingSettings finalSettings = baseSettings;

Explorer/Assets/DCL/PerformanceAndDiagnostics/Diagnostics/DiagnosticInfoUtils.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ public static void LogWebSocketException(Exception exception, string category)
8181
// InnerException is wrapped by the RPC tool (InvalidOperationException)
8282
if (exception.InnerException is WebSocketException webSocketException)
8383
{
84-
SentrySdk.AddBreadcrumb($"WebSocketException reason was WebSocketErrorCode: {webSocketException.WebSocketErrorCode.ToString()} "
85-
+ $"ErrorCode: {webSocketException.ErrorCode.ToString()}", category, level: BreadcrumbLevel.Info);
84+
global::Sentry.Unity.SentrySdk.AddBreadcrumb($"WebSocketException reason was WebSocketErrorCode: {webSocketException.WebSocketErrorCode.ToString()} "
85+
+ $"ErrorCode: {webSocketException.ErrorCode.ToString()}", category, level: BreadcrumbLevel.Info);
8686
}
8787

8888
ReportHub.LogException(exception, new ReportData(category));

Explorer/Assets/DCL/PerformanceAndDiagnostics/Diagnostics/ReportsHandling/Sentry/Editor.meta

Lines changed: 0 additions & 8 deletions
This file was deleted.

Explorer/Assets/DCL/PerformanceAndDiagnostics/Diagnostics/ReportsHandling/Sentry/Editor/Sentry.Editor.asmref

Lines changed: 0 additions & 3 deletions
This file was deleted.

Explorer/Assets/DCL/PerformanceAndDiagnostics/Diagnostics/ReportsHandling/Sentry/Editor/Sentry.Editor.asmref.meta

Lines changed: 0 additions & 7 deletions
This file was deleted.

Explorer/Assets/DCL/PerformanceAndDiagnostics/Diagnostics/ReportsHandling/Sentry/Editor/SentryBuildTimeConfiguration.cs

Lines changed: 0 additions & 113 deletions
This file was deleted.
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
using Sentry;
2+
using Sentry.Unity;
3+
using System;
4+
using UnityEngine;
5+
#if UNITY_EDITOR
6+
using UnityEditor;
7+
using System.IO;
8+
using Newtonsoft.Json;
9+
#endif
10+
11+
namespace DCL.Diagnostics.Sentry
12+
{
13+
[CreateAssetMenu(fileName = "SentryBuildTimeConfiguration.asset", menuName = "DCL/Diagnostics/Sentry Build Time Configuration")]
14+
public class SentryBuildTimeConfiguration : SentryOptionsConfiguration
15+
{
16+
// This file should be never committed since it may contain secrets
17+
[SerializeField] private string configJsonFilePath = "./.sentryconfig.json";
18+
19+
/// Called during app build. Changes made here will affect build-time processing, symbol upload, etc.
20+
/// Additionally, because iOS, macOS and Android native error handling is configured at build time,
21+
/// you can make changes to these options here.
22+
/// Learn more at https://docs.sentry.io/platforms/unity/configuration/options/#programmatic-configuration
23+
public override void Configure(SentryUnityOptions options)
24+
{
25+
options.SetBeforeSend(AddUnspecifiedCategory);
26+
27+
#if UNITY_EDITOR
28+
bool isDirty = false;
29+
30+
string? version = Application.version ?? options.Release;
31+
32+
if (options.Release != version)
33+
{
34+
options.Release = Application.version ?? options.Release;
35+
isDirty = true;
36+
}
37+
38+
try { isDirty |= ApplyFromEnvironmentVars(options); }
39+
catch (Exception e) { Debug.LogException(e); }
40+
41+
try { isDirty |= ApplyFromJsonFile(options); }
42+
catch (Exception e) { Debug.LogException(e); }
43+
44+
try { isDirty |= ApplyFromProgramArgs(options); }
45+
catch (Exception e) { Debug.LogException(e); }
46+
47+
if (isDirty)
48+
{
49+
try
50+
{
51+
// SentryOptions.asset must be modified so the app is built with the expected information
52+
PersistIntoAssetFile(GetAssetPath("SentryOptions"), options);
53+
}
54+
catch (Exception e) { Debug.LogException(e); }
55+
}
56+
#endif
57+
}
58+
59+
private SentryEvent AddUnspecifiedCategory(SentryEvent @event)
60+
{
61+
if (!@event.Tags.ContainsKey("category"))
62+
@event.SetTag("category", "UNSPECIFIED");
63+
64+
return @event;
65+
}
66+
67+
#if UNITY_EDITOR
68+
private static bool ApplyFromEnvironmentVars(SentryUnityOptions options)
69+
{
70+
var enabledExists = bool.TryParse(Environment.GetEnvironmentVariable("SENTRY_ENABLED"), out bool isEnabled);
71+
string? env = Environment.GetEnvironmentVariable("SENTRY_ENVIRONMENT") ?? options.Environment;
72+
string? dsn = Environment.GetEnvironmentVariable("SENTRY_DSN") ?? options.Dsn;
73+
string? release = Environment.GetEnvironmentVariable("SENTRY_RELEASE") ?? options.Release;
74+
bool isDirty = env != options.Environment || dsn != options.Dsn || release != options.Release;
75+
76+
options.Environment = env;
77+
options.Dsn = dsn;
78+
options.Release = release;
79+
80+
if (enabledExists)
81+
{
82+
if (options.Enabled != isEnabled)
83+
{
84+
isDirty = true;
85+
options.Enabled = isEnabled;
86+
}
87+
}
88+
89+
return isDirty;
90+
}
91+
92+
private static bool ApplyFromProgramArgs(SentryUnityOptions options)
93+
{
94+
var isDirty = false;
95+
string[] args = Environment.GetCommandLineArgs();
96+
97+
for (var i = 0; i < args.Length; i++)
98+
{
99+
string arg = args[i];
100+
101+
switch (arg)
102+
{
103+
case "-sentryEnvironment":
104+
string env = args[i + 1];
105+
106+
if (options.Environment != env)
107+
{
108+
options.Environment = env;
109+
isDirty = true;
110+
}
111+
112+
break;
113+
case "-sentryDsn":
114+
string dsn = args[i + 1];
115+
116+
if (options.Dsn != dsn)
117+
{
118+
options.Dsn = dsn;
119+
isDirty = true;
120+
}
121+
122+
break;
123+
case "-sentryRelease":
124+
string release = args[i + 1];
125+
126+
if (options.Release != release)
127+
{
128+
options.Release = release;
129+
isDirty = true;
130+
}
131+
132+
break;
133+
}
134+
}
135+
136+
if (isDirty)
137+
options.Enabled = true;
138+
139+
return isDirty;
140+
}
141+
142+
private bool ApplyFromJsonFile(SentryUnityOptions options)
143+
{
144+
if (!File.Exists(configJsonFilePath)) return false;
145+
146+
string fileContent = File.ReadAllText(configJsonFilePath);
147+
JsonConfigFileScheme scheme = JsonConvert.DeserializeObject<JsonConfigFileScheme>(fileContent);
148+
149+
string? env = string.IsNullOrEmpty(scheme.environment) ? options.Environment : scheme.environment;
150+
string? dsn = string.IsNullOrEmpty(scheme.dsn) ? options.Dsn : scheme.dsn;
151+
string? release = string.IsNullOrEmpty(scheme.release) ? options.Release : scheme.release;
152+
153+
bool isDirty = env != options.Environment || dsn != options.Dsn || release != options.Release;
154+
155+
options.Environment = env;
156+
options.Dsn = dsn;
157+
options.Release = release;
158+
159+
if (isDirty)
160+
options.Enabled = true;
161+
162+
return isDirty;
163+
}
164+
165+
private void PersistIntoAssetFile(string path, SentryUnityOptions options)
166+
{
167+
ScriptableSentryUnityOptions asset = AssetDatabase.LoadAssetAtPath<ScriptableSentryUnityOptions>(path);
168+
if (asset == null) return;
169+
asset.ReleaseOverride = options.Release;
170+
asset.Dsn = options.Dsn;
171+
asset.EnvironmentOverride = options.Environment;
172+
EditorUtility.SetDirty(asset);
173+
}
174+
175+
[Serializable]
176+
private struct JsonConfigFileScheme
177+
{
178+
public string environment;
179+
public string dsn;
180+
public string release;
181+
}
182+
#endif
183+
}
184+
}

Explorer/Assets/DCL/PerformanceAndDiagnostics/Diagnostics/ReportsHandling/Sentry/Editor/SentryBuildTimeConfiguration.cs.meta renamed to Explorer/Assets/DCL/PerformanceAndDiagnostics/Diagnostics/ReportsHandling/Sentry/SentryBuildTimeConfiguration.cs.meta

File renamed without changes.

0 commit comments

Comments
 (0)