Skip to content

Commit a25b3f2

Browse files
authored
Merge pull request #108 from bugsnag/next
Release v1.3.4
2 parents 9b85fb3 + 7dce792 commit a25b3f2

File tree

19 files changed

+239
-41
lines changed

19 files changed

+239
-41
lines changed

.buildkite/pipeline.full.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
aliases:
22
- &2020 "2020.3.48f1"
3-
- &2021 "2021.3.27f1"
4-
- &2022 "2022.3.2f1"
3+
- &2021 "2021.3.36f1"
4+
- &2022 "2022.3.22f1"
55

66
agents:
77
queue: macos-12-arm-unity

.buildkite/pipeline.yml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
aliases:
22
- &2020 "2020.3.48f1"
3-
- &2021 "2021.3.27f1"
4-
- &2022 "2022.3.2f1"
3+
- &2021 "2021.3.36f1"
4+
- &2022 "2022.3.22f1"
55

66
agents:
7-
queue: macos-12-arm-unity
7+
queue: macos-14
8+
89
steps:
910
- label: Build released library artifact
1011
timeout_in_minutes: 30
@@ -31,8 +32,6 @@ steps:
3132
'artifacts#v1.9.0':
3233
download:
3334
- upm-package.zip
34-
agents:
35-
queue: macos-12-arm
3635
commands:
3736
features/scripts/do_size_test.sh
3837

@@ -59,8 +58,6 @@ steps:
5958
- label: Run WebGL e2e tests for Unity 2021
6059
timeout_in_minutes: 60
6160
depends_on: build-webgl-fixture-2021
62-
agents:
63-
queue: macos-12-arm-unity
6461
env:
6562
UNITY_PERFORMANCE_VERSION: *2021
6663
plugins:
@@ -143,8 +140,6 @@ steps:
143140
- label: Run MacOS e2e tests for Unity 2021
144141
timeout_in_minutes: 60
145142
depends_on: build-macos-fixture-2021
146-
agents:
147-
queue: macos-12-arm-unity
148143
env:
149144
UNITY_PERFORMANCE_VERSION: *2021
150145
plugins:
@@ -234,7 +229,6 @@ steps:
234229
key: build-ios-fixture-2021
235230
depends_on: generate-fixture-project-2021
236231
env:
237-
DEVELOPER_DIR: /Applications/Xcode14.0.app
238232
UNITY_PERFORMANCE_VERSION: *2021
239233
plugins:
240234
'artifacts#v1.9.0':
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using UnityEngine;
2+
namespace BugsnagUnityPerformance
3+
{
4+
public class BugsnagPerformanceAppLifecycleListener : MonoBehaviour
5+
{
6+
void Awake()
7+
{
8+
DontDestroyOnLoad(gameObject);
9+
}
10+
11+
void OnApplicationFocus(bool hasFocus)
12+
{
13+
if (!hasFocus)
14+
{
15+
BugsnagPerformance.AppBackgrounded();
16+
}
17+
}
18+
19+
void OnApplicationPause(bool paused)
20+
{
21+
if (paused)
22+
{
23+
BugsnagPerformance.AppBackgrounded();
24+
}
25+
}
26+
27+
}
28+
}

BugsnagPerformance/Assets/BugsnagPerformance/Scripts/Internal/BugsnagPerformanceAppLifecycleListener.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ private string ByteArrayToHex(byte[] barray)
5151

5252
internal Span StartCustomSpan(string name, SpanOptions spanOptions)
5353
{
54-
// custom spans are always first class
55-
spanOptions.IsFirstClass = true;
54+
if (spanOptions.IsFirstClass == null)
55+
{
56+
spanOptions.IsFirstClass = true;
57+
}
5658
var span = CreateSpan(name, SpanKind.SPAN_KIND_INTERNAL, spanOptions);
5759
span.SetAttribute("bugsnag.span.category", "custom");
5860
return span;

BugsnagPerformance/Assets/BugsnagPerformance/Scripts/Internal/Tracer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4+
using System.Linq;
45
using System.Threading;
56
using UnityEngine;
67

@@ -135,7 +136,7 @@ private void DeliverBatch()
135136
{
136137
return;
137138
}
138-
batch = _spanQueue;
139+
batch = _spanQueue.Where(span => !span.WasAborted).ToList();
139140
_spanQueue = new List<Span>();
140141
_lastBatchSendTime = DateTimeOffset.UtcNow;
141142
_delivery.Deliver(batch);

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.3";
6+
public const string VersionString = "1.3.4";
77
}
88
}

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

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class BugsnagPerformance
2525
private AppStartHandler _appStartHandler;
2626
private PersistentState _persistentState;
2727
private PValueUpdater _pValueUpdater;
28+
private static List<Span> _potentiallyOpenSpans = new List<Span>();
2829
private Func<BugsnagNetworkRequestInfo, BugsnagNetworkRequestInfo> _networkRequestCallback;
2930

3031
public static void Start(PerformanceConfiguration configuration)
@@ -44,8 +45,8 @@ public static void Start(PerformanceConfiguration configuration)
4445
ValidateApiKey(configuration.ApiKey);
4546
if (ReleaseStageEnabled(configuration))
4647
{
47-
// init main thread dispatcher on main thread
48-
MainThreadDispatchBehaviour.Instance();
48+
// init main thread dispatcher and create app lifecycle listener on main thread
49+
MainThreadDispatchBehaviour.Instance().Enqueue(()=> { CreateAppLifecycleListener(); });
4950
_sharedInstance.Configure(configuration);
5051
_sharedInstance.Start();
5152
#if BUGSNAG_DEBUG
@@ -54,6 +55,11 @@ public static void Start(PerformanceConfiguration configuration)
5455
}
5556
}
5657

58+
private static void CreateAppLifecycleListener()
59+
{
60+
new GameObject("Bugsnag performance app lifecycle listener").AddComponent<BugsnagPerformanceAppLifecycleListener>();
61+
}
62+
5763
private static void ValidateApiKey(string apiKey)
5864
{
5965
if (!System.Text.RegularExpressions.Regex.IsMatch(apiKey, @"\A\b[0-9a-fA-F]+\b\Z") ||
@@ -152,7 +158,11 @@ private void Start()
152158

153159
private void OnSpanEnd(Span span)
154160
{
155-
_tracer.OnSpanEnd(span);
161+
_potentiallyOpenSpans.Remove(span);
162+
if (!span.WasAborted)
163+
{
164+
_tracer.OnSpanEnd(span);
165+
}
156166
}
157167

158168
private void OnProbabilityChanged(double newProbability)
@@ -283,7 +293,9 @@ private Span StartSpanInternal(string name, SpanOptions spanOptions)
283293
{
284294
lock (_startSpanLock)
285295
{
286-
return _spanFactory.StartCustomSpan(name, spanOptions);
296+
var span = _spanFactory.StartCustomSpan(name, spanOptions);
297+
_potentiallyOpenSpans.Add(span);
298+
return span;
287299
}
288300
}
289301

@@ -292,5 +304,21 @@ public static void ReportAppStarted()
292304
AppStartHandler.ReportAppStarted();
293305
}
294306

307+
internal static void AppBackgrounded()
308+
{
309+
CancelAllOpenSpans();
310+
}
311+
312+
private static void CancelAllOpenSpans()
313+
{
314+
foreach (var span in _potentiallyOpenSpans.ToArray())
315+
{
316+
if (!span.Ended)
317+
{
318+
span.Abort();
319+
}
320+
}
321+
}
322+
295323
}
296324
}

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

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class Span : ISpanContext
2222
private object _endLock = new object();
2323
private OnSpanEnd _onSpanEnd;
2424
internal bool IsAppStartSpan;
25+
internal bool WasAborted;
2526

2627
public Span(string name, SpanKind kind, string id, string traceId, string parentSpanId, DateTimeOffset startTime, bool? isFirstClass, OnSpanEnd onSpanEnd)
2728
{
@@ -39,21 +40,7 @@ public Span(string name, SpanKind kind, string id, string traceId, string parent
3940
_onSpanEnd = onSpanEnd;
4041
}
4142

42-
public void End()
43-
{
44-
lock (_endLock)
45-
{
46-
if (Ended)
47-
{
48-
return;
49-
}
50-
Ended = true;
51-
}
52-
EndTime = DateTimeOffset.UtcNow;
53-
_onSpanEnd(this);
54-
}
55-
56-
internal void End(DateTimeOffset? endTime)
43+
public void End(DateTimeOffset? endTime = null)
5744
{
5845
lock (_endLock)
5946
{
@@ -75,7 +62,9 @@ internal void Abort()
7562
{
7663
return;
7764
}
65+
WasAborted = true;
7866
Ended = true;
67+
_onSpanEnd(this);
7968
}
8069
}
8170

@@ -107,7 +96,7 @@ internal void EndNetworkSpan(BugsnagUnityWebRequest request)
10796
_onSpanEnd(this);
10897
}
10998

110-
public void EndNetworkSpan(int statusCode = -1, int requestContentLength = -1, int responseContentLength = -1)
99+
public void EndNetworkSpan(int statusCode = -1, int requestContentLength = -1, int responseContentLength = -1, DateTimeOffset? endTime = null)
111100
{
112101
lock (_endLock)
113102
{
@@ -118,7 +107,7 @@ public void EndNetworkSpan(int statusCode = -1, int requestContentLength = -1, i
118107
Ended = true;
119108
}
120109

121-
EndTime = DateTimeOffset.UtcNow;
110+
EndTime = endTime == null ? DateTimeOffset.UtcNow : endTime.Value;
122111

123112
if (statusCode > -1)
124113
{

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## v1.3.4 (2024-04-29)
4+
5+
### Bug Fixes
6+
7+
- Fixed issue where spans could not be ended with a custom end time. [#106](https://github.com/bugsnag/bugsnag-unity-performance/pull/106)
8+
9+
- Fixed issue where custom spans with the SpanOption IsFirstClass set to false still had it reported as true. [#107](https://github.com/bugsnag/bugsnag-unity-performance/pull/107)
10+
11+
312
## v1.3.3 (2024-03-07)
413

514
### Bug Fixes

0 commit comments

Comments
 (0)