Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v1.6.0 #138

Merged
merged 10 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .buildkite/pipeline.full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ steps:
- features/fixtures/mazerunner/build/Windows-2020.zip
- features/fixtures/build_windows.log
commands:
- features/scripts/import_package.sh
- features/scripts/import_package.sh --windows
- features/scripts/build_windows.sh release
retry:
automatic:
Expand Down Expand Up @@ -141,7 +141,7 @@ steps:
- features/fixtures/mazerunner/build/Windows-2022.zip
- features/fixtures/build_windows.log
commands:
- features/scripts/import_package.sh
- features/scripts/import_package.sh --windows
- features/scripts/build_windows.sh release
retry:
automatic:
Expand Down Expand Up @@ -464,7 +464,7 @@ steps:
- features/fixtures/mazerunner/build/Windows-dev-2021.zip
- features/fixtures/build_windows.log
commands:
- features/scripts/import_package.sh
- features/scripts/import_package.sh --windows
- features/scripts/build_windows.sh dev
retry:
automatic:
Expand Down
2 changes: 1 addition & 1 deletion .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ steps:
- features/fixtures/mazerunner/build/Windows-2021.zip
- features/fixtures/build_windows.log
commands:
- features/scripts/import_package.sh
- features/scripts/import_package.sh --windows
- features/scripts/build_windows.sh release
retry:
automatic:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ features/fixtures/minimalapp/minimal_with_xcode
features/fixtures/minimalapp/minimal_without_xcode
features/fixtures/mazerunner/mazerunner_macos_BackUpThisFolder_ButDontShipItWithYourGame
BugsnagPerformance/.vscode
features/fixtures/mazerunner/Assets/Bugsnag
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,32 @@ private void DrawSettingsEditorWindow()
}

EditorGUIUtility.labelWidth = 200;
EditorGUILayout.PropertyField(so.FindProperty("Endpoint"));

DrawIntPropertyWithDefault(so, "AttributeArrayLengthLimit", "AttributeArrayLengthLimit", PerformanceConfiguration.DEFAULT_ATTRIBUTE_ARRAY_LENGTH_LIMIT);
DrawIntPropertyWithDefault(so, "AttributeCountLimit", "AttributeCountLimit", PerformanceConfiguration.DEFAULT_ATTRIBUTE_COUNT_LIMIT);
DrawIntPropertyWithDefault(so, "AttributeStringValueLimit", "AttributeStringValueLimit", PerformanceConfiguration.DEFAULT_ATTRIBUTE_STRING_VALUE_LIMIT);
EditorGUILayout.PropertyField(so.FindProperty("AutoInstrumentAppStart"));
EditorGUILayout.PropertyField(so.FindProperty("Endpoint"));
EditorGUILayout.PropertyField(so.FindProperty("ServiceName"));

EditorGUILayout.PropertyField(so.FindProperty("TracePropagationUrls"));
EditorGUI.indentLevel--;
so.ApplyModifiedProperties();
EditorUtility.SetDirty(settings);
}

private void DrawIntPropertyWithDefault(SerializedObject so, string propertyName, string label, int defaultValue)
{
var property = so.FindProperty(propertyName);
var isValueSet = property.intValue > 0;
if (!isValueSet)
{
property.intValue = EditorGUILayout.IntField(label, isValueSet ? property.intValue : defaultValue);
}
else
{
EditorGUILayout.PropertyField(property);
}
}

private void DrawStandaloneSettings(SerializedObject so, BugsnagPerformanceSettingsObject settings)
{
EditorGUIUtility.labelWidth = 70;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ public class AppStartHandler : IPhasedStartup
private static Span _loadAssembliesSpan;
private static Span _splashScreenSpan;
private static Span _firstSceneSpan;

private PerformanceConfiguration _config;
private static bool _appStartComplete;
private static DateTimeOffset? _defaultAppStartEndTime = null;

private static AutoInstrumentAppStartSetting _appStartSetting;

private static SpanFactory _spanFactory;

internal AppStartHandler(SpanFactory spanFactory)
Expand All @@ -26,8 +24,8 @@ internal AppStartHandler(SpanFactory spanFactory)

public void Configure(PerformanceConfiguration config)
{
_appStartSetting = config.AutoInstrumentAppStart;
if (_appStartSetting == AutoInstrumentAppStartSetting.OFF)
_config = config;
if (_config.AutoInstrumentAppStart == AutoInstrumentAppStartSetting.OFF)
{
AbortAppStartSpans();
}
Expand Down Expand Up @@ -55,7 +53,7 @@ private void AbortAppStartSpans()

public void Start()
{
if (_appStartSetting == AutoInstrumentAppStartSetting.FULL)
if (_config.AutoInstrumentAppStart == AutoInstrumentAppStartSetting.FULL)
{
MainThreadDispatchBehaviour.Instance().Enqueue(CheckForAppStartCompletion());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ namespace BugsnagUnityPerformance
{
public class CacheManager : IPhasedStartup
{
private int _maxPersistedBatchAgeSeconds;
private bool _deviceAutoGenerateId;
private PerformanceConfiguration _config;
private string _cacheDirectory;
private string _deviceidFilePath;
private string _persistentStateFilePath;
Expand All @@ -32,9 +31,7 @@ public CacheManager(string basePath)

public void Configure(PerformanceConfiguration config)
{
_maxPersistedBatchAgeSeconds = config.MaxPersistedBatchAgeSeconds;
_deviceAutoGenerateId = config.GenerateAnonymousId;

_config = config;
}

public void Start()
Expand All @@ -50,7 +47,7 @@ public string GetDeviceId()
try
{
//if generateAnonymousId is true then store/report/generate else don't
if (_deviceAutoGenerateId)
if (_config.GenerateAnonymousId)
{
if (File.Exists(_deviceidFilePath))
{
Expand Down Expand Up @@ -138,7 +135,7 @@ private void RemoveExpiredPayloads()
{
var creationTime = File.GetCreationTimeUtc(path);
var timeSinceCreation = DateTimeOffset.UtcNow - creationTime;
if (timeSinceCreation.TotalSeconds > _maxPersistedBatchAgeSeconds)
if (timeSinceCreation.TotalSeconds > _config.MaxPersistedBatchAgeSeconds)
{
DeleteFile(path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ namespace BugsnagUnityPerformance

internal class Delivery : IPhasedStartup
{
private string _endpoint;
private string _apiKey;
private bool _isFixedSamplingProbability = false;
private OnProbabilityChanged _onProbabilityChanged;
private bool _flushingCache;
private ResourceModel _resourceModel;
private CacheManager _cacheManager;
private PerformanceConfiguration _config;

private enum RequestResult
{
Expand Down Expand Up @@ -57,9 +55,7 @@ public Delivery(ResourceModel resourceModel, CacheManager cacheManager, OnProbab

public void Configure(PerformanceConfiguration config)
{
_endpoint = config.GetEndpoint();
_apiKey = config.ApiKey;
_isFixedSamplingProbability = config.IsFixedSamplingProbability;
_config = config;
}

public void Start()
Expand All @@ -69,7 +65,7 @@ public void Start()

public void Deliver(List<Span> batch)
{
var payload = new TracePayload(_resourceModel, batch, _isFixedSamplingProbability);
var payload = new TracePayload(_resourceModel, batch, _config.IsFixedSamplingProbability, _config.AttributeArrayLengthLimit, _config.AttributeStringValueLimit);
MainThreadDispatchBehaviour.Instance().Enqueue(PushToServer(payload, OnTraceDeliveryCompleted));
}

Expand Down Expand Up @@ -99,7 +95,7 @@ public void DeliverPValueRequest(OnServerResponse onResponse = null)
{
onResponse = OnPValueRequestCompleted;
}
var payload = new TracePayload(_resourceModel, null, false);
var payload = TracePayload.GetTracePayloadForPValueRequest(_resourceModel);
MainThreadDispatchBehaviour.Instance().Enqueue(PushToServer(payload, onResponse));
}

Expand Down Expand Up @@ -134,13 +130,13 @@ private IEnumerator PushToServer(TracePayload payload, OnServerResponse onServer
yield break;
}

using (var req = new UnityWebRequest(_endpoint))
using (var req = new UnityWebRequest(_config.Endpoint))
{
foreach (var header in payload.Headers)
{
req.SetRequestHeader(header.Key, header.Value);
}
req.SetRequestHeader("Bugsnag-Api-Key", _apiKey);
req.SetRequestHeader("Bugsnag-Api-Key", _config.ApiKey);
req.SetRequestHeader("Content-Type", "application/json");
req.SetRequestHeader("Bugsnag-Integrity", "sha1 " + Hash(body));
req.SetRequestHeader("Bugsnag-Sent-At", DateTimeOffset.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ", CultureInfo.InvariantCulture));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ public void Enqueue(IEnumerator action)
}
}

public void LogWarning(string msg)
{
Enqueue(() =>
{
Debug.LogWarning(msg);
});
}

/// <summary>
/// Locks the queue and adds the Action to the queue
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ namespace BugsnagUnityPerformance
{
internal class PValueUpdater : IPhasedStartup
{
private PerformanceConfiguration _config;
private Delivery _delivery;
private Sampler _sampler;
private DateTime _pValueTimeout;
private float _pValueTimeoutSeconds;
private float _pValueCheckIntervalSeconds;
public bool IsConfigured { get; private set; }

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

public void Configure(PerformanceConfiguration config)
{
_pValueTimeoutSeconds = config.PValueTimeoutSeconds;
_pValueCheckIntervalSeconds = config.PValueCheckIntervalSeconds;
_config = config;
IsConfigured = true;
}

Expand All @@ -45,13 +43,13 @@ private IEnumerator CheckPValue()
_delivery.DeliverPValueRequest(OnPValueRequestCompleted);
}

yield return new WaitForSeconds(_pValueCheckIntervalSeconds);
yield return new WaitForSeconds(_config.PValueCheckIntervalSeconds);
}
}

private void markPValueUpdated()
{
_pValueTimeout = DateTime.Now.AddSeconds(_pValueTimeoutSeconds);
_pValueTimeout = DateTime.Now.AddSeconds(_config.PValueTimeoutSeconds);
}

private void OnPValueRequestCompleted(TracePayload payload, UnityWebRequest req, double newProbability)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using System.IO;
using System;
using System.IO;
using System.Threading;
using Newtonsoft.Json;
using UnityEngine;
Expand Down Expand Up @@ -94,7 +94,7 @@ private void Save()
}
catch (Exception e)
{
Debug.Log("Failed to save persistent state: " + e);
MainThreadDispatchBehaviour.Instance().LogWarning("Failed to save persistent state: " + e);
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace BugsnagUnityPerformance
{
internal class SpanFactory
internal class SpanFactory : IPhasedStartup
{

[ThreadStatic]
Expand All @@ -25,12 +25,24 @@ internal class SpanFactory

private WaitForSeconds _connectionPollRate = new WaitForSeconds(1);

private int _maxCustomAttributes = PerformanceConfiguration.DEFAULT_ATTRIBUTE_COUNT_LIMIT;

public SpanFactory(OnSpanEnd onSpanEnd)
{
_onSpanEnd = onSpanEnd;
MainThreadDispatchBehaviour.Instance().StartCoroutine(GetConnectionType());
}

public void Configure(PerformanceConfiguration config)
{
// private property used here as this factory can be accessed before configure is called
_maxCustomAttributes = config.AttributeCountLimit;
}

public void Start()
{
}

private string GetNewTraceId()
{
byte[] byteArray = new byte[16];
Expand Down Expand Up @@ -95,7 +107,7 @@ private Span CreateSpan(string name, SpanKind kind, SpanOptions spanOptions)
}
}

var newSpan = new Span(name, kind, spanId, traceId, parentSpanId, spanOptions.StartTime, spanOptions.IsFirstClass, _onSpanEnd);
var newSpan = new Span(name, kind, spanId, traceId, parentSpanId, spanOptions.StartTime, spanOptions.IsFirstClass, _onSpanEnd, _maxCustomAttributes);
if (spanOptions.MakeCurrentContext)
{
AddToContextStack(newSpan);
Expand Down Expand Up @@ -240,5 +252,7 @@ internal Span CreateAutoAppStartSpan(string name, string category)
span.IsAppStartSpan = true;
return span;
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class TracePayload

private string _jsonbody;

public TracePayload(ResourceModel resourceModel, List<Span> spans, bool isFixedSamplingProbability)
public TracePayload(ResourceModel resourceModel, List<Span> spans, bool isFixedSamplingProbability, int attributeArrayLengthLimit, int attributeStringValueLimit )
{
_resourceModel = resourceModel;
if (spans != null && spans.Count > 0)
Expand All @@ -29,7 +29,7 @@ public TracePayload(ResourceModel resourceModel, List<Span> spans, bool isFixedS
PayloadId = Guid.NewGuid().ToString();
foreach (var span in spans)
{
_spans.Add(new SpanModel(span));
_spans.Add(new SpanModel(span, attributeArrayLengthLimit, attributeStringValueLimit));
}
SamplingHistogram = CalculateSamplingHistorgram(spans);
if(!isFixedSamplingProbability)
Expand All @@ -46,6 +46,11 @@ public TracePayload(ResourceModel resourceModel, List<Span> spans, bool isFixedS
}
}

internal static TracePayload GetTracePayloadForPValueRequest(ResourceModel resourceModel)
{
return new TracePayload(resourceModel, null, false, 0, 0);
}

private TracePayload(Dictionary<string, string> headers, string cachedJson, string payloadId)
{
PayloadId = payloadId;
Expand Down
Loading