Skip to content

Commit

Permalink
Prototype source with event
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-garcia committed Jun 25, 2018
1 parent b0f9b85 commit 518ab64
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 29 deletions.
7 changes: 7 additions & 0 deletions NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="aspnetcore-dev" value="https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json" />
</packageSources>
</configuration>
7 changes: 4 additions & 3 deletions Sentry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sentry.Tests", "test\Sentry
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "1 - Solution Items", "1 - Solution Items", "{9D7E2F87-D6F4-4BBB-8980-87D0A8344C74}"
ProjectSection(SolutionItems) = preProject
.appveyor.yml = .appveyor.yml
.editorconfig = .editorconfig
.gitattributes = .gitattributes
.gitignore = .gitignore
.travis.yml = .travis.yml
after.Sentry.sln.targets = after.Sentry.sln.targets
build.ps1 = build.ps1
build.sh = build.sh
Directory.Build.props = Directory.Build.props
Directory.Build.targets = Directory.Build.targets
global.json = global.json
NuGet.Config = NuGet.Config
README.md = README.md
.appveyor.yml = .appveyor.yml
.travis.yml = .travis.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{77454495-55EE-4B40-A089-71B9E8F82E89}"
Expand Down Expand Up @@ -63,7 +64,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sentry.AspNetCore.Tests", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sentry.Extensions.Logging.Tests", "test\Sentry.Extensions.Logging.Tests\Sentry.Extensions.Logging.Tests.csproj", "{32B17E4A-8C30-44CC-B1D3-093CF284B1C3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Testing", "test\Sentry.Testing\Sentry.Testing.csproj", "{20602A5A-B413-4E48-9AC9-00A7155774BD}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sentry.Testing", "test\Sentry.Testing\Sentry.Testing.csproj", "{20602A5A-B413-4E48-9AC9-00A7155774BD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
73 changes: 47 additions & 26 deletions src/Sentry/Protocol/SentryEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.StackTrace.Sources;
using Sentry.Infrastructure;
using Sentry.Protocol;

Expand Down Expand Up @@ -135,6 +138,11 @@ public SentryEvent(Exception exception)
}
}


// TODO: This is a hack to test this stuff
private static IFileProvider Provider = new CompositeFileProvider(new EmbeddedFileProvider(Assembly.GetEntryAssembly()));
private static ExceptionDetailsProvider DetailsProvider = new ExceptionDetailsProvider(Provider, 10);

private void Populate(Exception exception)
{
// TODO: should this be dotnet instead?
Expand All @@ -157,7 +165,6 @@ private void Populate(Exception exception)
}

InternalModules = builder.ToImmutable();

if (exception != null)
{
var sentryExceptions = CreateSentryException(exception)
Expand All @@ -173,6 +180,7 @@ private static IEnumerable<SentryException> CreateSentryException(Exception exce
{
Debug.Assert(exception != null);

// TODO: Replace it with: ExceptionDetailsProvider.FlattenAndReverseExceptionTree
if (exception is AggregateException ae)
{
foreach (var inner in ae.InnerExceptions.SelectMany(CreateSentryException))
Expand All @@ -197,14 +205,12 @@ private static IEnumerable<SentryException> CreateSentryException(Exception exce
Mechanism = GetMechanism(exception)
};


var stackTrace = new StackTrace(exception, true);

// Sentry expects the frames to be sent in reversed order
var frames = stackTrace.GetFrames()
var frames = StackTraceHelper.GetFrames(exception)
// Sentry expects the frames to be sent in reversed order
?.Reverse()
.Select(CreateSentryStackFrame)
.ToList();
.ToArray();


if (frames != null)
{
Expand Down Expand Up @@ -247,47 +253,62 @@ public static Mechanism GetMechanism(Exception exception)
return mechanism;
}

public static SentryStackFrame CreateSentryStackFrame(StackFrame stackFrame)
internal static SentryStackFrame CreateSentryStackFrame(StackFrameInfo frameInfo)
{
const string unknownRequiredField = "(unknown)";

var frame = new SentryStackFrame();
var sentryFrame = new SentryStackFrame();

if (stackFrame.HasMethod())
var frame = frameInfo.StackFrame;
if (frame.HasMethod())
{
var method = stackFrame.GetMethod();
var method = frame.GetMethod();

// TODO: SentryStackFrame.TryParse and skip frame instead of these unknown values:
frame.Module = method.DeclaringType?.FullName ?? unknownRequiredField;
frame.Package = method.DeclaringType?.Assembly.FullName;
frame.Function = method.Name;
frame.ContextLine = method.ToString();
sentryFrame.Module = method.DeclaringType?.FullName ?? unknownRequiredField;
sentryFrame.Package = method.DeclaringType?.Assembly.FullName;
sentryFrame.Function = frameInfo.MethodDisplayInfo.ToString();
sentryFrame.ContextLine = method.ToString();
}

frame.InApp = !IsSystemModuleName(frame.Module);
frame.FileName = stackFrame.GetFileName();
sentryFrame.InApp = !IsSystemModuleName(sentryFrame.Module);
sentryFrame.AbsolutePath = frame.GetFileName();

if (stackFrame.HasILOffset())
if (frame.HasILOffset())
{
frame.InstructionOffset = stackFrame.GetILOffset();
sentryFrame.InstructionOffset = frame.GetILOffset();
}
var lineNo = stackFrame.GetFileLineNumber();
var lineNo = frame.GetFileLineNumber();
if (lineNo != 0)
{
frame.LineNumber = lineNo;
sentryFrame.LineNumber = lineNo;
}

var colNo = stackFrame.GetFileColumnNumber();
var colNo = frame.GetFileColumnNumber();
if (lineNo != 0)
{
frame.ColumnNumber = colNo;
sentryFrame.ColumnNumber = colNo;
}

var sourceInfo = DetailsProvider.GetStackFrameSourceCodeInfo(
sentryFrame.Function,
sentryFrame.AbsolutePath,
sentryFrame.LineNumber ?? 0);

var contextLines = sourceInfo.ContextCode.ToList();
if (contextLines.Count > 0)
{
sentryFrame.ContextLine = string.Join("\n", contextLines);
sentryFrame.PreContext = sourceInfo.PreContextCode.ToList();
sentryFrame.PostContext = sourceInfo.PostContextCode.ToList();
}

// TODO: Consider Ben.Demystifier (not on netcoreapp2.1+ which has by default)
DemangleAsyncFunctionName(frame);
DemangleAnonymousFunction(frame);
DemangleAsyncFunctionName(sentryFrame);
DemangleAnonymousFunction(sentryFrame);

return frame;
// TODO: Consider Ben.Demystifier (not on netcoreapp2.1+ which has by default)
return sentryFrame;

// TODO: make this extensible
bool IsSystemModuleName(string moduleName)
Expand Down
10 changes: 10 additions & 0 deletions src/Sentry/Sentry.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,14 @@
<PackageReference Include="System.Collections.Immutable" Version="1.5.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Reflection.Metadata" Version="1.6.0" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Composite" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Abstractions" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.StackTrace.Sources" Version="2.2.0-*" PrivateAssets="All" />
<PackageReference Include="Microsoft.Extensions.TypeNameHelper.Sources" Version="2.2.0-*" PrivateAssets="All" />
</ItemGroup>

</Project>

0 comments on commit 518ab64

Please sign in to comment.