Skip to content

Commit

Permalink
remove unnecessary logging (#844)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardelms authored Oct 29, 2024
1 parent 8f02797 commit 97e40b7
Showing 1 changed file with 3 additions and 29 deletions.
32 changes: 3 additions & 29 deletions src/BugsnagUnity/PerformanceHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//#define PERFORMANCE_HELPER_LOG
using System;
using System.Linq;
using System.Reflection;
Expand All @@ -15,7 +14,7 @@ internal class PerformanceHelper
static MethodInfo _getPerformanceStateMethodInfo;
private static bool _isPerformanceLibraryAvailable = true;

[Serializable]
[Serializable]
private class PerformanceState
{
public string currentContextSpanId;
Expand All @@ -25,60 +24,41 @@ public PerformanceState(string currentContextSpanId, string currentContextTraceI
this.currentContextSpanId = currentContextSpanId;
this.currentContextTraceId = currentContextTraceId;
}
}
}

internal static Correlation GetCurrentPerformanceSpanContext()
{
Log("Entering GetCurrentPerformanceSpanContext");

if (!_isPerformanceLibraryAvailable)
{
Log("Performance library is not available");
return null;
}

try
{
Log("Initializing GetCurrentContextInternalMethod if needed");
InitializeGetCurrentContextInternalMethodIfNeeded();

Log("Invoking _getCurrentContextInternalMethod");
string result = (string)_getPerformanceStateMethodInfo?.Invoke(null, null);

Log("Result from _getCurrentContextInternalMethod: " + result);

if (string.IsNullOrEmpty(result))
{
Log("Result is null or empty");
return null;
}

Log("Parsing result to CorrelationTransfer");
var performanceState = JsonUtility.FromJson<PerformanceState>(result);

if (performanceState == null)
{
Log("Deserialization failed, CorrelationTransfer is null");
return null;
}

Log("Performance library context: traceId=" + performanceState.currentContextTraceId + ", spanId=" + performanceState.currentContextSpanId);

var correlation = new Correlation(performanceState.currentContextTraceId, performanceState.currentContextSpanId);

Log("Performance library correlation: spanId=" + correlation.SpanId + ", traceId=" + correlation.TraceId);

Log("Exiting GetCurrentPerformanceSpanContext with correlation");
return correlation;
}
catch (Exception ex)
{
Log("Exception caught: " + ex.Message);
// Silently handle case where performance library is not available or out of date
Log("Performance library is not available or out of date");
_isPerformanceLibraryAvailable = false;

Log("Exiting GetCurrentPerformanceSpanContext with null due to exception");
return null;
}
}
Expand All @@ -92,16 +72,10 @@ private static void InitializeGetCurrentContextInternalMethodIfNeeded()
.FirstOrDefault(type => type != null);

_getPerformanceStateMethodInfo = bugsnagPerformanceType?.GetMethod(
GET_PERFORMANCE_STATE_METHOD_NAME,
GET_PERFORMANCE_STATE_METHOD_NAME,
BindingFlags.NonPublic | BindingFlags.Static
);
}

private static void Log(string message)
{
#if PERFORMANCE_HELPER_LOG
UnityEngine.Debug.Log(message);
#endif
}
}
}

0 comments on commit 97e40b7

Please sign in to comment.