in src/Elastic.Apm/Libraries/Ben.Demystifier/EnhancedStackTrace.Frames.cs [562:674]
private static bool ShowInStackTrace(MethodBase method)
{
// Since .NET 5:
// https://github.com/dotnet/runtime/blob/7c18d4d6488dab82124d475d1199def01d1d252c/src/libraries/System.Private.CoreLib/src/System/Diagnostics/StackTrace.cs#L348-L361
if ((method.MethodImplementationFlags & MethodImplAttributes.AggressiveInlining) != 0)
{
// Aggressive Inlines won't normally show in the StackTrace; however for Tier0 Jit and
// cross-assembly AoT/R2R these inlines will be blocked until Tier1 Jit re-Jits
// them when they will inline. We don't show them in the StackTrace to bring consistency
// between this first-pass asm and fully optimized asm.
return false;
}
// Since .NET Core 2:
if (StackTraceHiddenAttributeType != null)
{
// Don't show any methods marked with the StackTraceHiddenAttribute
// https://github.com/dotnet/coreclr/pull/14652
if (IsStackTraceHidden(method)) return false;
}
var type = method.DeclaringType;
if (type == null) return true;
// Since .NET Core 2:
if (StackTraceHiddenAttributeType != null)
{
// Don't show any methods marked with the StackTraceHiddenAttribute
// https://github.com/dotnet/coreclr/pull/14652
if (IsStackTraceHidden(type)) return false;
}
if (type == typeof(Task<>) && method.Name == "InnerInvoke") return false;
if (type == typeof(ValueTask<>) && method.Name == "get_Result") return false;
if (method.Name.StartsWith("System.Threading.Tasks.Sources.IValueTaskSource") && method.Name.EndsWith(".GetResult")) return false;
if (type == typeof(Task) || type.DeclaringType == typeof(Task))
{
if (method.Name.Contains(".cctor")) return false;
switch (method.Name)
{
case "ExecuteWithThreadLocal":
case "Execute":
case "ExecutionContextCallback":
case "ExecuteEntry":
case "InnerInvoke":
case "ExecuteEntryUnsafe":
case "ExecuteFromThreadPool":
return false;
}
}
if (type == typeof(ExecutionContext))
{
if (method.Name.Contains(".cctor")) return false;
switch (method.Name)
{
case "RunInternal":
case "Run":
case "RunFromThreadPoolDispatchLoop":
return false;
}
}
if (type.Namespace == "Microsoft.FSharp.Control")
{
switch (type.Name)
{
case "AsyncPrimitives":
case "Trampoline":
return false;
case var typeName when type.IsGenericType:
{
if (typeName == "AsyncResult`1") return false;
else break;
}
}
}
if (type.Namespace == "Ply")
{
if (type.DeclaringType?.Name == "TplPrimitives") return false;
}
// Fallbacks for runtime pre-StackTraceHiddenAttribute
if (type == typeof(ExceptionDispatchInfo) && method.Name == "Throw") return false;
if (type == typeof(TaskAwaiter) ||
type == typeof(TaskAwaiter<>) ||
type == typeof(ValueTaskAwaiter) ||
type == typeof(ValueTaskAwaiter<>) ||
type == typeof(ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter) ||
type == typeof(ConfiguredValueTaskAwaitable<>.ConfiguredValueTaskAwaiter) ||
type == typeof(ConfiguredTaskAwaitable.ConfiguredTaskAwaiter) ||
type == typeof(ConfiguredTaskAwaitable<>.ConfiguredTaskAwaiter))
{
switch (method.Name)
{
case "HandleNonSuccessAndDebuggerNotification":
case "ThrowForNonSuccess":
case "ValidateEnd":
case "GetResult":
return false;
}
}
else if (type.FullName == "System.ThrowHelper") return false;
return true;
}