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

Fixed Exception StackTrace formatting to handle missing StackFrames #117

Merged
merged 3 commits into from
Nov 24, 2020
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
2 changes: 1 addition & 1 deletion src/Elastic.Apm.NLog/Elastic.Apm.NLog.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
<Title>Elastic APM NLog Layout Renderers</Title>
<Description>Enrich NLog log messages with APM TraceId and TransactionId.</Description>
<IsPackable>True</IsPackable>
Expand Down
16 changes: 10 additions & 6 deletions src/Elastic.CommonSchema.NLog/EcsLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using NLog;
using NLog.Config;
Expand Down Expand Up @@ -193,8 +191,11 @@ private static string CatchError(Exception error)
fullText.WriteLine($"Source: {error.TargetSite?.DeclaringType?.AssemblyQualifiedName}");
fullText.WriteLine($"Message: {error.Message}");
fullText.WriteLine($"Trace: {error.StackTrace}");
fullText.WriteLine($"Location: {frame.GetFileName()}");
fullText.WriteLine($"Method: {frame.GetMethod()} ({frame.GetFileLineNumber()}, {frame.GetFileColumnNumber()})");
if (frame != null)
{
fullText.WriteLine($"Location: {frame.GetFileName()}");
fullText.WriteLine($"Method: {frame.GetMethod()} ({frame.GetFileLineNumber()}, {frame.GetFileColumnNumber()})");
}

var exception = error.InnerException;
while (exception != null)
Expand All @@ -205,8 +206,11 @@ private static string CatchError(Exception error)
fullText.WriteLine($"\tSource: {exception.TargetSite?.DeclaringType?.AssemblyQualifiedName}");
fullText.WriteLine($"\tMessage: {exception.Message}");
fullText.WriteLine($"\tTrace: {exception.StackTrace}");
fullText.WriteLine($"\tLocation: {frame.GetFileName()}");
fullText.WriteLine($"\tMethod: {frame.GetMethod()} ({frame.GetFileLineNumber()}, {frame.GetFileColumnNumber()})");
if (frame != null)
{
fullText.WriteLine($"\tLocation: {frame.GetFileName()}");
fullText.WriteLine($"\tMethod: {frame.GetMethod()} ({frame.GetFileLineNumber()}, {frame.GetFileColumnNumber()})");
}

exception = exception.InnerException;
}
Expand Down
54 changes: 53 additions & 1 deletion src/Elastic.CommonSchema.NLog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ filesystem target and [Elastic Filebeat](https://www.elastic.co/downloads/beats/
</extensions>
<targets>
<target name="console" type="console">
<layout xsi:type="EcsLayout" />
<layout xsi:type="EcsLayout">
<metadata name="MyProperty" layout="MyPropertyValue" /> <!-- repeated, optional -->
<label name="MyLabel" layout="MyLabelValue" /> <!-- repeated, optional -->
<tag layout="MyTagValue" /> <!-- repeated, optional -->
</layout>
</target>
</targets>
<rules>
Expand All @@ -41,6 +45,54 @@ filesystem target and [Elastic Filebeat](https://www.elastic.co/downloads/beats/
</nlog>
```

## EcsLayout Parameter Options
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding this!


* **Metadata Options**
- _IncludeAllProperties_ - Include LogEvent properties as metadata. Default: `true`
- _IncludeMdlc_ - Include NLog Scope Context Properties as metadata. Default: `false`
- _ExcludeProperties_ - Comma separated string with names which properties to exclude.

* **Event Options**
- _EventAction_ -
- _EventCategory_ -
- _EventId_ -
- _EventKind_ -
- _EventSeverity_ -

* **Agent Options**
- _AgentId_ -
- _AgentName_ -
- _AgentType_ -
- _AgentVersion_ -

* **Process Options**
- _ProcessExecutable_ - Default: `${processname:FullName=true}`
- _ProcessId_ - Default: `${processid}`
- _ProcessName_ - Default: `${processname:FullName=false}`
- _ProcessThreadId_ - Default: `${threadid}`
- _ProcessTitle_ - Default: `${processinfo:MainWindowTitle}`

* **Server Options**
- _ServerAddress_ -
- _ServerIp_ -
- _ServerUser_ - Default: `${environment-user}`

* **Host Options**
- _HostId_ -
- _HostIp_ - Default: `${local-ip:cachedSeconds=60}`
- _HostName_ - Default: `${machinename}`

* **Log Origin Options**
- _LogOriginCallSiteMethod_ - Default: `${exception:format=method}`
- _LogOriginCallSiteFile_ - Default: `${exception:format=source}`
- _LogOriginCallSiteLine_ -

* **Trace Options**
- _ApmTraceId_ - Default: `${ElasticApmTraceId}`

* **Transaction Options**
- _ApmTransactionId_ - Default: `${ElasticApmTransactionId}`

## Example output from EcsLayout
An example of the output is given below:

Expand Down
16 changes: 10 additions & 6 deletions src/Elastic.CommonSchema.Serilog/LogEventConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,11 @@ private static string CatchErrors(IReadOnlyCollection<Exception> errors)
fullText.WriteLine($"Source: {error.TargetSite?.DeclaringType?.AssemblyQualifiedName}");
fullText.WriteLine($"Message: {error.Message}");
fullText.WriteLine($"Trace: {error.StackTrace}");
fullText.WriteLine($"Location: {frame.GetFileName()}");
fullText.WriteLine(
$"Method: {frame.GetMethod()} ({frame.GetFileLineNumber()}, {frame.GetFileColumnNumber()})");
if (frame != null)
{
fullText.WriteLine($"Location: {frame.GetFileName()}");
fullText.WriteLine($"Method: {frame.GetMethod()} ({frame.GetFileLineNumber()}, {frame.GetFileColumnNumber()})");
}

var exception = error.InnerException;
while (exception != null)
Expand All @@ -350,9 +352,11 @@ private static string CatchErrors(IReadOnlyCollection<Exception> errors)
fullText.WriteLine($"\tSource: {exception.TargetSite?.DeclaringType?.AssemblyQualifiedName}");
fullText.WriteLine($"\tMessage: {exception.Message}");
fullText.WriteLine($"\tTrace: {exception.StackTrace}");
fullText.WriteLine($"\tLocation: {frame.GetFileName()}");
fullText.WriteLine(
$"\tMethod: {frame.GetMethod()} ({frame.GetFileLineNumber()}, {frame.GetFileColumnNumber()})");
if (frame != null)
{
fullText.WriteLine($"\tLocation: {frame.GetFileName()}");
fullText.WriteLine($"\tMethod: {frame.GetMethod()} ({frame.GetFileLineNumber()}, {frame.GetFileColumnNumber()})");
}

exception = exception.InnerException;
}
Expand Down