Skip to content

Commit

Permalink
Ensure calls to Agent.Tracer use null propagation to access child obj…
Browse files Browse the repository at this point in the history
…ects (#59)
  • Loading branch information
codebrain authored Mar 6, 2020
1 parent 877b05f commit 5ebd054
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Elastic.Apm.NLog/ApmTraceIdLayoutRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class ApmTraceIdLayoutRenderer : LayoutRenderer

protected override void Append(StringBuilder builder, LogEventInfo logEvent)
{
if (!Agent.IsConfigured || Agent.Tracer?.CurrentTransaction == null)
return;
if (!Agent.IsConfigured) return;
if (Agent.Tracer?.CurrentTransaction == null) return;

builder.Append(Agent.Tracer.CurrentTransaction.TraceId);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Elastic.Apm.NLog/ApmTransactionIdLayoutRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class ApmTransactionIdLayoutRenderer : LayoutRenderer

protected override void Append(StringBuilder builder, LogEventInfo logEvent)
{
if (!Agent.IsConfigured || Agent.Tracer?.CurrentTransaction == null)
return;
if (!Agent.IsConfigured) return;
if (Agent.Tracer?.CurrentTransaction == null) return;

builder.Append(Agent.Tracer.CurrentTransaction.Id);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Elastic.Apm.SerilogEnricher/ElasticApmEnricher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public sealed class ElasticApmEnricher : ILogEventEnricher
{
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
if (!Agent.IsConfigured || Agent.Tracer.CurrentTransaction == null)
return;
if (!Agent.IsConfigured) return;
if (Agent.Tracer?.CurrentTransaction == null) return;

logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(
"ElasticApmTransactionId", Agent.Tracer.CurrentTransaction.Id));
Expand Down

0 comments on commit 5ebd054

Please sign in to comment.