Skip to content

Commit 0c768d2

Browse files
authored
Merge pull request #115 from bugsnag/next
Release v1.4.0
2 parents a25b3f2 + 3edbb07 commit 0c768d2

File tree

71 files changed

+758
-167
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+758
-167
lines changed

.buildkite/pipeline.full.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ aliases:
44
- &2022 "2022.3.22f1"
55

66
agents:
7-
queue: macos-12-arm-unity
7+
queue: macos-14
88

99
steps:
1010
- label: ':macos: Build macos test fixture for Unity 2020'
@@ -31,8 +31,6 @@ steps:
3131
- label: Run MacOS e2e tests for Unity 2020
3232
timeout_in_minutes: 60
3333
depends_on: build-macos-fixture-2020
34-
agents:
35-
queue: macos-12-arm-unity
3634
env:
3735
UNITY_PERFORMANCE_VERSION: *2020
3836
plugins:
@@ -71,8 +69,6 @@ steps:
7169
- label: Run MacOS e2e tests for Unity 2022
7270
timeout_in_minutes: 60
7371
depends_on: build-macos-fixture-2022
74-
agents:
75-
queue: macos-12-arm-unity
7672
env:
7773
UNITY_PERFORMANCE_VERSION: *2022
7874
plugins:
@@ -294,7 +290,7 @@ steps:
294290
key: build-ios-fixture-2020
295291
depends_on: generate-fixture-project-2020
296292
env:
297-
DEVELOPER_DIR: /Applications/Xcode14.0.app
293+
XCODE_VERSION: 15.3.0
298294
UNITY_PERFORMANCE_VERSION: *2020
299295
plugins:
300296
'artifacts#v1.9.0':
@@ -365,7 +361,7 @@ steps:
365361
key: build-ios-fixture-2022
366362
depends_on: generate-fixture-project-2022
367363
env:
368-
DEVELOPER_DIR: /Applications/Xcode14.0.app
364+
XCODE_VERSION: 15.3.0
369365
UNITY_PERFORMANCE_VERSION: *2022
370366
plugins:
371367
'artifacts#v1.9.0':

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ features/fixtures/mazerunner/mazerunner_BackUpThisFolder_ButDontShipItWithYourGa
2626
features/fixtures/minimalapp/Packages
2727
features/fixtures/minimalapp/minimal_with_xcode
2828
features/fixtures/minimalapp/minimal_without_xcode
29+
features/fixtures/mazerunner/mazerunner_macos_BackUpThisFolder_ButDontShipItWithYourGame

BugsnagPerformance/Assets/BugsnagPerformance/Scripts/Internal/CacheManager.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace BugsnagUnityPerformance
88
public class CacheManager : IPhasedStartup
99
{
1010
private int _maxPersistedBatchAgeSeconds;
11+
private bool _deviceAutoGenerateId;
1112
private string _cacheDirectory;
1213
private string _deviceidFilePath;
1314
private string _persistentStateFilePath;
@@ -32,6 +33,8 @@ public CacheManager(string basePath)
3233
public void Configure(PerformanceConfiguration config)
3334
{
3435
_maxPersistedBatchAgeSeconds = config.MaxPersistedBatchAgeSeconds;
36+
_deviceAutoGenerateId = config.GenerateAnonymousId;
37+
3538
}
3639

3740
public void Start()
@@ -46,16 +49,24 @@ public string GetDeviceId()
4649
{
4750
try
4851
{
49-
if (File.Exists(_deviceidFilePath))
52+
//if generateAnonymousId is true then store/report/generate else don't
53+
if (_deviceAutoGenerateId)
5054
{
51-
// return existing cached device id
52-
return File.ReadAllText(_deviceidFilePath);
55+
if (File.Exists(_deviceidFilePath))
56+
{
57+
// return existing cached device id
58+
return File.ReadAllText(_deviceidFilePath);
59+
}
60+
61+
// create and cache new random device id
62+
var newDeviceId = Guid.NewGuid().ToString();
63+
WriteFile(_deviceidFilePath, _deviceidFilePath);
64+
return newDeviceId;
65+
}
66+
else
67+
{
68+
return string.Empty;
5369
}
54-
55-
// create and cache new random device id
56-
var newDeviceId = Guid.NewGuid().ToString();
57-
WriteFile(_deviceidFilePath, _deviceidFilePath);
58-
return newDeviceId;
5970
}
6071
catch
6172
{

BugsnagPerformance/Assets/BugsnagPerformance/Scripts/Internal/Sampler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ public void Start()
4343
}
4444
}
4545

46-
public bool Sampled(Span span)
46+
public bool Sampled(Span span, bool shouldAddAttribute = true)
4747
{
4848
var p = Probability;
4949
var isSampled = IsSampled(span, GetUpperBound(p));
5050
#if BUGSNAG_DEBUG
5151
Logger.I(string.Format("Span {0} is sampled: {1} with p value: {2}",span.Name,isSampled,p));
5252
#endif
53-
if (isSampled)
53+
if (isSampled && shouldAddAttribute)
5454
{
5555
span.UpdateSamplingProbability(p);
5656
span.SetAttribute("bugsnag.sampling.p", p);

BugsnagPerformance/Assets/BugsnagPerformance/Scripts/Internal/SpanFactory.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private Span CreateSpan(string name, SpanKind kind, SpanOptions spanOptions)
8989
{
9090
AddToContextStack(newSpan);
9191
}
92-
92+
newSpan.SetAttribute("net.host.connection.type", GetConnectionType());
9393
return newSpan;
9494
}
9595

@@ -105,7 +105,6 @@ internal Span CreateAutomaticNetworkSpan(BugsnagUnityWebRequest request,string u
105105
span.SetAttribute("bugsnag.span.category", "network");
106106
span.SetAttribute("http.url", url);
107107
span.SetAttribute("http.method", verb);
108-
span.SetAttribute("net.host.connection.type", GetConnectionType());
109108
return span;
110109
}
111110

@@ -126,7 +125,6 @@ internal Span CreateManualNetworkSpan(string url, HttpVerb httpVerb, SpanOptions
126125
span.SetAttribute("bugsnag.span.category", "network");
127126
span.SetAttribute("http.url", url);
128127
span.SetAttribute("http.method", httpVerb.ToString());
129-
span.SetAttribute("net.host.connection.type", GetConnectionType());
130128
return span;
131129
}
132130

@@ -171,7 +169,7 @@ internal Span CreateManualSceneLoadSpan(string sceneName, SpanOptions spanOption
171169
return span;
172170
}
173171

174-
private ISpanContext GetCurrentContext()
172+
internal ISpanContext GetCurrentContext()
175173
{
176174
if (_contextStack == null || _contextStack.Count == 0)
177175
{

BugsnagPerformance/Assets/BugsnagPerformance/Scripts/Internal/Version.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
internal static class Version
44
{
55
//TODO set this using sed or something in the release automation task
6-
public const string VersionString = "1.3.4";
6+
public const string VersionString = "1.4.0";
77
}
88
}

BugsnagPerformance/Assets/BugsnagPerformance/Scripts/Public/BugsnagPerformance.cs

Lines changed: 100 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
5+
using System.Text.RegularExpressions;
56
using BugsnagNetworking;
67
using UnityEngine;
78
using UnityEngine.SceneManagement;
9+
using UnityEngine.Scripting;
810

911
namespace BugsnagUnityPerformance
1012
{
@@ -27,6 +29,7 @@ public class BugsnagPerformance
2729
private PValueUpdater _pValueUpdater;
2830
private static List<Span> _potentiallyOpenSpans = new List<Span>();
2931
private Func<BugsnagNetworkRequestInfo, BugsnagNetworkRequestInfo> _networkRequestCallback;
32+
private static string[] _tracePropagationUrlMatchPatterns;
3033

3134
public static void Start(PerformanceConfiguration configuration)
3235
{
@@ -42,6 +45,10 @@ public static void Start(PerformanceConfiguration configuration)
4245
}
4346
IsStarted = true;
4447
}
48+
if (configuration.TracePropagationUrlMatchPatterns != null)
49+
{
50+
_tracePropagationUrlMatchPatterns = configuration.TracePropagationUrlMatchPatterns.ToArray();
51+
}
4552
ValidateApiKey(configuration.ApiKey);
4653
if (ReleaseStageEnabled(configuration))
4754
{
@@ -241,24 +248,80 @@ private void SetupNetworkListener()
241248
private void OnRequestSend(BugsnagUnityWebRequest request)
242249
{
243250
var url = request.url;
251+
bool shouldCreateSpan = true;
244252
if (_networkRequestCallback != null)
245253
{
246254
var callbackResult = _networkRequestCallback.Invoke(new BugsnagNetworkRequestInfo(url));
247255
if (callbackResult == null || string.IsNullOrEmpty(callbackResult.Url))
248256
{
249-
return;
257+
shouldCreateSpan = false;
250258
}
251259

252260
url = callbackResult.Url;
253261
}
254-
var span = _spanFactory.CreateAutomaticNetworkSpan(request, url);
255-
lock (_networkSpansLock)
262+
263+
Span networkSpan = null;
264+
265+
if (shouldCreateSpan)
266+
{
267+
networkSpan = _spanFactory.CreateAutomaticNetworkSpan(request, url);
268+
lock (_networkSpansLock)
269+
{
270+
_networkSpans[request] = networkSpan;
271+
}
272+
}
273+
274+
if (ShouldAddTraceParentHeader(request.url))
275+
{
276+
string parentId = "";
277+
string traceId = "";
278+
bool sampled = false;
279+
280+
if (networkSpan != null)
281+
{
282+
parentId = networkSpan.SpanId;
283+
traceId = networkSpan.TraceId;
284+
sampled = _sampler.Sampled(networkSpan,false);
285+
}
286+
else
287+
{
288+
ISpanContext currentContext = _spanFactory.GetCurrentContext();
289+
if (currentContext != null)
290+
{
291+
parentId = currentContext.SpanId;
292+
traceId = currentContext.TraceId;
293+
}
294+
}
295+
if (string.IsNullOrEmpty(parentId))
296+
{
297+
return;
298+
}
299+
request.SetRequestHeader("traceparent", BuildTraceParentHeader(traceId,parentId,sampled));
300+
}
301+
}
302+
303+
private static bool ShouldAddTraceParentHeader(string url)
304+
{
305+
if (_tracePropagationUrlMatchPatterns == null || _tracePropagationUrlMatchPatterns.Length == 0)
306+
{
307+
return true;
308+
}
309+
foreach (var pattern in _tracePropagationUrlMatchPatterns)
256310
{
257-
_networkSpans[request] = span;
311+
if (Regex.IsMatch(url, pattern))
312+
{
313+
return true;
314+
}
258315
}
316+
return false;
317+
}
318+
319+
private static string BuildTraceParentHeader(string traceId, string parentSpanId, bool sampled)
320+
{
321+
return $"00-{traceId}-{parentSpanId}-{(sampled ? "01" : "00")}";
259322
}
260323

261-
324+
262325

263326
private void OnRequestAbort(BugsnagUnityWebRequest request)
264327
{
@@ -299,6 +362,11 @@ private Span StartSpanInternal(string name, SpanOptions spanOptions)
299362
}
300363
}
301364

365+
public static ISpanContext GetCurrentSpanContext()
366+
{
367+
return _sharedInstance._spanFactory.GetCurrentContext();
368+
}
369+
302370
public static void ReportAppStarted()
303371
{
304372
AppStartHandler.ReportAppStarted();
@@ -320,5 +388,32 @@ private static void CancelAllOpenSpans()
320388
}
321389
}
322390

391+
[Serializable]
392+
private class PerformanceState
393+
{
394+
public string currentContextSpanId;
395+
public string currentContextTraceId;
396+
public PerformanceState(string currentContextSpanId, string currentContextTraceId)
397+
{
398+
this.currentContextSpanId = currentContextSpanId;
399+
this.currentContextTraceId = currentContextTraceId;
400+
}
401+
}
402+
403+
[Preserve]
404+
internal static string GetPerformanceState()
405+
{
406+
var context = GetCurrentSpanContext();
407+
if (context != null)
408+
{
409+
var performanceState = new PerformanceState(context.SpanId, context.TraceId);
410+
var json = JsonUtility.ToJson(performanceState);
411+
return json;
412+
}
413+
return string.Empty;
414+
}
415+
416+
417+
323418
}
324419
}

BugsnagPerformance/Assets/BugsnagPerformance/Scripts/Public/BugsnagPerformanceSettingsObject.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public class BugsnagPerformanceSettingsObject : ScriptableObject
2626
public int VersionCode = -1;
2727
public string BundleVersion;
2828

29+
public bool GenerateAnonymousId = true;
30+
2931
public static PerformanceConfiguration LoadConfiguration()
3032
{
3133
var settings = Resources.Load<BugsnagPerformanceSettingsObject>("Bugsnag/BugsnagPerformanceSettingsObject");
@@ -56,6 +58,8 @@ internal PerformanceConfiguration GetConfig()
5658
config.AutoInstrumentAppStart = AutoInstrumentAppStart;
5759

5860
config.Endpoint = Endpoint;
61+
62+
config.GenerateAnonymousId = GenerateAnonymousId;
5963

6064
return config;
6165
}
@@ -78,6 +82,7 @@ private PerformanceConfiguration GetStandaloneConfig()
7882
config.AppVersion = AppVersion;
7983
config.BundleVersion = BundleVersion;
8084
config.VersionCode = VersionCode;
85+
config.GenerateAnonymousId = GenerateAnonymousId;
8186

8287
return config;
8388
}
@@ -107,6 +112,8 @@ private PerformanceConfiguration GetSettingsFromNotifier(out bool autoStart)
107112
config.AppVersion = (string)GetValueFromNotifer(notifierSettings, "AppVersion");
108113
config.BundleVersion = (string)GetValueFromNotifer(notifierSettings, "BundleVersion");
109114
config.VersionCode = (int)GetValueFromNotifer(notifierSettings, "VersionCode");
115+
config.GenerateAnonymousId = (bool)GetValueFromNotifer(notifierSettings, "GenerateAnonymousId");
116+
110117

111118
autoStart = (bool)GetValueFromNotifer(notifierSettings, "StartAutomaticallyAtLaunch");
112119

0 commit comments

Comments
 (0)