Skip to content

Commit d51d4d4

Browse files
authored
Merge pull request #138 from bugsnag/next
Release v1.6.0
2 parents 245c17c + 53d2017 commit d51d4d4

35 files changed

+745
-207
lines changed

.buildkite/pipeline.full.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ steps:
9999
- features/fixtures/mazerunner/build/Windows-2020.zip
100100
- features/fixtures/build_windows.log
101101
commands:
102-
- features/scripts/import_package.sh
102+
- features/scripts/import_package.sh --windows
103103
- features/scripts/build_windows.sh release
104104
retry:
105105
automatic:
@@ -141,7 +141,7 @@ steps:
141141
- features/fixtures/mazerunner/build/Windows-2022.zip
142142
- features/fixtures/build_windows.log
143143
commands:
144-
- features/scripts/import_package.sh
144+
- features/scripts/import_package.sh --windows
145145
- features/scripts/build_windows.sh release
146146
retry:
147147
automatic:
@@ -464,7 +464,7 @@ steps:
464464
- features/fixtures/mazerunner/build/Windows-dev-2021.zip
465465
- features/fixtures/build_windows.log
466466
commands:
467-
- features/scripts/import_package.sh
467+
- features/scripts/import_package.sh --windows
468468
- features/scripts/build_windows.sh dev
469469
retry:
470470
automatic:

.buildkite/pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ steps:
8989
- features/fixtures/mazerunner/build/Windows-2021.zip
9090
- features/fixtures/build_windows.log
9191
commands:
92-
- features/scripts/import_package.sh
92+
- features/scripts/import_package.sh --windows
9393
- features/scripts/build_windows.sh release
9494
retry:
9595
automatic:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ features/fixtures/minimalapp/minimal_with_xcode
2828
features/fixtures/minimalapp/minimal_without_xcode
2929
features/fixtures/mazerunner/mazerunner_macos_BackUpThisFolder_ButDontShipItWithYourGame
3030
BugsnagPerformance/.vscode
31+
features/fixtures/mazerunner/Assets/Bugsnag

BugsnagPerformance/Assets/BugsnagPerformance/Editor/BugsnagPerformanceEditor.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,32 @@ private void DrawSettingsEditorWindow()
100100
}
101101

102102
EditorGUIUtility.labelWidth = 200;
103-
EditorGUILayout.PropertyField(so.FindProperty("Endpoint"));
104-
103+
DrawIntPropertyWithDefault(so, "AttributeArrayLengthLimit", "AttributeArrayLengthLimit", PerformanceConfiguration.DEFAULT_ATTRIBUTE_ARRAY_LENGTH_LIMIT);
104+
DrawIntPropertyWithDefault(so, "AttributeCountLimit", "AttributeCountLimit", PerformanceConfiguration.DEFAULT_ATTRIBUTE_COUNT_LIMIT);
105+
DrawIntPropertyWithDefault(so, "AttributeStringValueLimit", "AttributeStringValueLimit", PerformanceConfiguration.DEFAULT_ATTRIBUTE_STRING_VALUE_LIMIT);
105106
EditorGUILayout.PropertyField(so.FindProperty("AutoInstrumentAppStart"));
107+
EditorGUILayout.PropertyField(so.FindProperty("Endpoint"));
106108
EditorGUILayout.PropertyField(so.FindProperty("ServiceName"));
107-
109+
EditorGUILayout.PropertyField(so.FindProperty("TracePropagationUrls"));
108110
EditorGUI.indentLevel--;
109111
so.ApplyModifiedProperties();
110112
EditorUtility.SetDirty(settings);
111113
}
112114

115+
private void DrawIntPropertyWithDefault(SerializedObject so, string propertyName, string label, int defaultValue)
116+
{
117+
var property = so.FindProperty(propertyName);
118+
var isValueSet = property.intValue > 0;
119+
if (!isValueSet)
120+
{
121+
property.intValue = EditorGUILayout.IntField(label, isValueSet ? property.intValue : defaultValue);
122+
}
123+
else
124+
{
125+
EditorGUILayout.PropertyField(property);
126+
}
127+
}
128+
113129
private void DrawStandaloneSettings(SerializedObject so, BugsnagPerformanceSettingsObject settings)
114130
{
115131
EditorGUIUtility.labelWidth = 70;

BugsnagPerformance/Assets/BugsnagPerformance/Scripts/Internal/AppStartHandler.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ public class AppStartHandler : IPhasedStartup
1111
private static Span _loadAssembliesSpan;
1212
private static Span _splashScreenSpan;
1313
private static Span _firstSceneSpan;
14-
14+
private PerformanceConfiguration _config;
1515
private static bool _appStartComplete;
1616
private static DateTimeOffset? _defaultAppStartEndTime = null;
1717

18-
private static AutoInstrumentAppStartSetting _appStartSetting;
19-
2018
private static SpanFactory _spanFactory;
2119

2220
internal AppStartHandler(SpanFactory spanFactory)
@@ -26,8 +24,8 @@ internal AppStartHandler(SpanFactory spanFactory)
2624

2725
public void Configure(PerformanceConfiguration config)
2826
{
29-
_appStartSetting = config.AutoInstrumentAppStart;
30-
if (_appStartSetting == AutoInstrumentAppStartSetting.OFF)
27+
_config = config;
28+
if (_config.AutoInstrumentAppStart == AutoInstrumentAppStartSetting.OFF)
3129
{
3230
AbortAppStartSpans();
3331
}
@@ -55,7 +53,7 @@ private void AbortAppStartSpans()
5553

5654
public void Start()
5755
{
58-
if (_appStartSetting == AutoInstrumentAppStartSetting.FULL)
56+
if (_config.AutoInstrumentAppStart == AutoInstrumentAppStartSetting.FULL)
5957
{
6058
MainThreadDispatchBehaviour.Instance().Enqueue(CheckForAppStartCompletion());
6159
}

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ namespace BugsnagUnityPerformance
77
{
88
public class CacheManager : IPhasedStartup
99
{
10-
private int _maxPersistedBatchAgeSeconds;
11-
private bool _deviceAutoGenerateId;
10+
private PerformanceConfiguration _config;
1211
private string _cacheDirectory;
1312
private string _deviceidFilePath;
1413
private string _persistentStateFilePath;
@@ -32,9 +31,7 @@ public CacheManager(string basePath)
3231

3332
public void Configure(PerformanceConfiguration config)
3433
{
35-
_maxPersistedBatchAgeSeconds = config.MaxPersistedBatchAgeSeconds;
36-
_deviceAutoGenerateId = config.GenerateAnonymousId;
37-
34+
_config = config;
3835
}
3936

4037
public void Start()
@@ -50,7 +47,7 @@ public string GetDeviceId()
5047
try
5148
{
5249
//if generateAnonymousId is true then store/report/generate else don't
53-
if (_deviceAutoGenerateId)
50+
if (_config.GenerateAnonymousId)
5451
{
5552
if (File.Exists(_deviceidFilePath))
5653
{
@@ -138,7 +135,7 @@ private void RemoveExpiredPayloads()
138135
{
139136
var creationTime = File.GetCreationTimeUtc(path);
140137
var timeSinceCreation = DateTimeOffset.UtcNow - creationTime;
141-
if (timeSinceCreation.TotalSeconds > _maxPersistedBatchAgeSeconds)
138+
if (timeSinceCreation.TotalSeconds > _config.MaxPersistedBatchAgeSeconds)
142139
{
143140
DeleteFile(path);
144141
}

BugsnagPerformance/Assets/BugsnagPerformance/Scripts/Internal/Delivery.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ namespace BugsnagUnityPerformance
1414

1515
internal class Delivery : IPhasedStartup
1616
{
17-
private string _endpoint;
18-
private string _apiKey;
19-
private bool _isFixedSamplingProbability = false;
2017
private OnProbabilityChanged _onProbabilityChanged;
2118
private bool _flushingCache;
2219
private ResourceModel _resourceModel;
2320
private CacheManager _cacheManager;
21+
private PerformanceConfiguration _config;
2422

2523
private enum RequestResult
2624
{
@@ -57,9 +55,7 @@ public Delivery(ResourceModel resourceModel, CacheManager cacheManager, OnProbab
5755

5856
public void Configure(PerformanceConfiguration config)
5957
{
60-
_endpoint = config.GetEndpoint();
61-
_apiKey = config.ApiKey;
62-
_isFixedSamplingProbability = config.IsFixedSamplingProbability;
58+
_config = config;
6359
}
6460

6561
public void Start()
@@ -69,7 +65,7 @@ public void Start()
6965

7066
public void Deliver(List<Span> batch)
7167
{
72-
var payload = new TracePayload(_resourceModel, batch, _isFixedSamplingProbability);
68+
var payload = new TracePayload(_resourceModel, batch, _config.IsFixedSamplingProbability, _config.AttributeArrayLengthLimit, _config.AttributeStringValueLimit);
7369
MainThreadDispatchBehaviour.Instance().Enqueue(PushToServer(payload, OnTraceDeliveryCompleted));
7470
}
7571

@@ -99,7 +95,7 @@ public void DeliverPValueRequest(OnServerResponse onResponse = null)
9995
{
10096
onResponse = OnPValueRequestCompleted;
10197
}
102-
var payload = new TracePayload(_resourceModel, null, false);
98+
var payload = TracePayload.GetTracePayloadForPValueRequest(_resourceModel);
10399
MainThreadDispatchBehaviour.Instance().Enqueue(PushToServer(payload, onResponse));
104100
}
105101

@@ -134,13 +130,13 @@ private IEnumerator PushToServer(TracePayload payload, OnServerResponse onServer
134130
yield break;
135131
}
136132

137-
using (var req = new UnityWebRequest(_endpoint))
133+
using (var req = new UnityWebRequest(_config.Endpoint))
138134
{
139135
foreach (var header in payload.Headers)
140136
{
141137
req.SetRequestHeader(header.Key, header.Value);
142138
}
143-
req.SetRequestHeader("Bugsnag-Api-Key", _apiKey);
139+
req.SetRequestHeader("Bugsnag-Api-Key", _config.ApiKey);
144140
req.SetRequestHeader("Content-Type", "application/json");
145141
req.SetRequestHeader("Bugsnag-Integrity", "sha1 " + Hash(body));
146142
req.SetRequestHeader("Bugsnag-Sent-At", DateTimeOffset.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ", CultureInfo.InvariantCulture));

BugsnagPerformance/Assets/BugsnagPerformance/Scripts/Internal/MainThreadDispatchBehaviour.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ public void Enqueue(IEnumerator action)
7272
}
7373
}
7474

75+
public void LogWarning(string msg)
76+
{
77+
Enqueue(() =>
78+
{
79+
Debug.LogWarning(msg);
80+
});
81+
}
82+
7583
/// <summary>
7684
/// Locks the queue and adds the Action to the queue
7785
/// </summary>

BugsnagPerformance/Assets/BugsnagPerformance/Scripts/Internal/PValueUpdater.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ namespace BugsnagUnityPerformance
77
{
88
internal class PValueUpdater : IPhasedStartup
99
{
10+
private PerformanceConfiguration _config;
1011
private Delivery _delivery;
1112
private Sampler _sampler;
1213
private DateTime _pValueTimeout;
13-
private float _pValueTimeoutSeconds;
14-
private float _pValueCheckIntervalSeconds;
1514
public bool IsConfigured { get; private set; }
1615

1716
public PValueUpdater(Delivery delivery, Sampler sampler)
@@ -23,8 +22,7 @@ public PValueUpdater(Delivery delivery, Sampler sampler)
2322

2423
public void Configure(PerformanceConfiguration config)
2524
{
26-
_pValueTimeoutSeconds = config.PValueTimeoutSeconds;
27-
_pValueCheckIntervalSeconds = config.PValueCheckIntervalSeconds;
25+
_config = config;
2826
IsConfigured = true;
2927
}
3028

@@ -45,13 +43,13 @@ private IEnumerator CheckPValue()
4543
_delivery.DeliverPValueRequest(OnPValueRequestCompleted);
4644
}
4745

48-
yield return new WaitForSeconds(_pValueCheckIntervalSeconds);
46+
yield return new WaitForSeconds(_config.PValueCheckIntervalSeconds);
4947
}
5048
}
5149

5250
private void markPValueUpdated()
5351
{
54-
_pValueTimeout = DateTime.Now.AddSeconds(_pValueTimeoutSeconds);
52+
_pValueTimeout = DateTime.Now.AddSeconds(_config.PValueTimeoutSeconds);
5553
}
5654

5755
private void OnPValueRequestCompleted(TracePayload payload, UnityWebRequest req, double newProbability)

BugsnagPerformance/Assets/BugsnagPerformance/Scripts/Internal/PersistentState.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using System;
2-
using System.IO;
1+
using System;
2+
using System.IO;
33
using System.Threading;
44
using Newtonsoft.Json;
55
using UnityEngine;
@@ -94,7 +94,7 @@ private void Save()
9494
}
9595
catch (Exception e)
9696
{
97-
Debug.Log("Failed to save persistent state: " + e);
97+
MainThreadDispatchBehaviour.Instance().LogWarning("Failed to save persistent state: " + e);
9898
}
9999
finally
100100
{

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace BugsnagUnityPerformance
99
{
10-
internal class SpanFactory
10+
internal class SpanFactory : IPhasedStartup
1111
{
1212

1313
[ThreadStatic]
@@ -25,12 +25,24 @@ internal class SpanFactory
2525

2626
private WaitForSeconds _connectionPollRate = new WaitForSeconds(1);
2727

28+
private int _maxCustomAttributes = PerformanceConfiguration.DEFAULT_ATTRIBUTE_COUNT_LIMIT;
29+
2830
public SpanFactory(OnSpanEnd onSpanEnd)
2931
{
3032
_onSpanEnd = onSpanEnd;
3133
MainThreadDispatchBehaviour.Instance().StartCoroutine(GetConnectionType());
3234
}
3335

36+
public void Configure(PerformanceConfiguration config)
37+
{
38+
// private property used here as this factory can be accessed before configure is called
39+
_maxCustomAttributes = config.AttributeCountLimit;
40+
}
41+
42+
public void Start()
43+
{
44+
}
45+
3446
private string GetNewTraceId()
3547
{
3648
byte[] byteArray = new byte[16];
@@ -95,7 +107,7 @@ private Span CreateSpan(string name, SpanKind kind, SpanOptions spanOptions)
95107
}
96108
}
97109

98-
var newSpan = new Span(name, kind, spanId, traceId, parentSpanId, spanOptions.StartTime, spanOptions.IsFirstClass, _onSpanEnd);
110+
var newSpan = new Span(name, kind, spanId, traceId, parentSpanId, spanOptions.StartTime, spanOptions.IsFirstClass, _onSpanEnd, _maxCustomAttributes);
99111
if (spanOptions.MakeCurrentContext)
100112
{
101113
AddToContextStack(newSpan);
@@ -240,5 +252,7 @@ internal Span CreateAutoAppStartSpan(string name, string category)
240252
span.IsAppStartSpan = true;
241253
return span;
242254
}
255+
256+
243257
}
244258
}

BugsnagPerformance/Assets/BugsnagPerformance/Scripts/Internal/TracePayload.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class TracePayload
2020

2121
private string _jsonbody;
2222

23-
public TracePayload(ResourceModel resourceModel, List<Span> spans, bool isFixedSamplingProbability)
23+
public TracePayload(ResourceModel resourceModel, List<Span> spans, bool isFixedSamplingProbability, int attributeArrayLengthLimit, int attributeStringValueLimit )
2424
{
2525
_resourceModel = resourceModel;
2626
if (spans != null && spans.Count > 0)
@@ -29,7 +29,7 @@ public TracePayload(ResourceModel resourceModel, List<Span> spans, bool isFixedS
2929
PayloadId = Guid.NewGuid().ToString();
3030
foreach (var span in spans)
3131
{
32-
_spans.Add(new SpanModel(span));
32+
_spans.Add(new SpanModel(span, attributeArrayLengthLimit, attributeStringValueLimit));
3333
}
3434
SamplingHistogram = CalculateSamplingHistorgram(spans);
3535
if(!isFixedSamplingProbability)
@@ -46,6 +46,11 @@ public TracePayload(ResourceModel resourceModel, List<Span> spans, bool isFixedS
4646
}
4747
}
4848

49+
internal static TracePayload GetTracePayloadForPValueRequest(ResourceModel resourceModel)
50+
{
51+
return new TracePayload(resourceModel, null, false, 0, 0);
52+
}
53+
4954
private TracePayload(Dictionary<string, string> headers, string cachedJson, string payloadId)
5055
{
5156
PayloadId = payloadId;

0 commit comments

Comments
 (0)