From 5ebd05408689e63d79cddc0a99c257baa65a2c73 Mon Sep 17 00:00:00 2001 From: Stuart Cam Date: Fri, 6 Mar 2020 15:25:03 +1100 Subject: [PATCH] Ensure calls to Agent.Tracer use null propagation to access child objects (#59) --- src/Elastic.Apm.NLog/ApmTraceIdLayoutRenderer.cs | 4 ++-- src/Elastic.Apm.NLog/ApmTransactionIdLayoutRenderer.cs | 4 ++-- src/Elastic.Apm.SerilogEnricher/ElasticApmEnricher.cs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Elastic.Apm.NLog/ApmTraceIdLayoutRenderer.cs b/src/Elastic.Apm.NLog/ApmTraceIdLayoutRenderer.cs index 1737efb6..13d17464 100644 --- a/src/Elastic.Apm.NLog/ApmTraceIdLayoutRenderer.cs +++ b/src/Elastic.Apm.NLog/ApmTraceIdLayoutRenderer.cs @@ -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); } diff --git a/src/Elastic.Apm.NLog/ApmTransactionIdLayoutRenderer.cs b/src/Elastic.Apm.NLog/ApmTransactionIdLayoutRenderer.cs index 64504f82..66db717b 100644 --- a/src/Elastic.Apm.NLog/ApmTransactionIdLayoutRenderer.cs +++ b/src/Elastic.Apm.NLog/ApmTransactionIdLayoutRenderer.cs @@ -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); } diff --git a/src/Elastic.Apm.SerilogEnricher/ElasticApmEnricher.cs b/src/Elastic.Apm.SerilogEnricher/ElasticApmEnricher.cs index 164248bd..98fe8b5f 100644 --- a/src/Elastic.Apm.SerilogEnricher/ElasticApmEnricher.cs +++ b/src/Elastic.Apm.SerilogEnricher/ElasticApmEnricher.cs @@ -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));