Skip to content

Commit 5ebd054

Browse files
authored
Ensure calls to Agent.Tracer use null propagation to access child objects (#59)
1 parent 877b05f commit 5ebd054

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/Elastic.Apm.NLog/ApmTraceIdLayoutRenderer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public class ApmTraceIdLayoutRenderer : LayoutRenderer
1717

1818
protected override void Append(StringBuilder builder, LogEventInfo logEvent)
1919
{
20-
if (!Agent.IsConfigured || Agent.Tracer?.CurrentTransaction == null)
21-
return;
20+
if (!Agent.IsConfigured) return;
21+
if (Agent.Tracer?.CurrentTransaction == null) return;
2222

2323
builder.Append(Agent.Tracer.CurrentTransaction.TraceId);
2424
}

src/Elastic.Apm.NLog/ApmTransactionIdLayoutRenderer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public class ApmTransactionIdLayoutRenderer : LayoutRenderer
1717

1818
protected override void Append(StringBuilder builder, LogEventInfo logEvent)
1919
{
20-
if (!Agent.IsConfigured || Agent.Tracer?.CurrentTransaction == null)
21-
return;
20+
if (!Agent.IsConfigured) return;
21+
if (Agent.Tracer?.CurrentTransaction == null) return;
2222

2323
builder.Append(Agent.Tracer.CurrentTransaction.Id);
2424
}

src/Elastic.Apm.SerilogEnricher/ElasticApmEnricher.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public sealed class ElasticApmEnricher : ILogEventEnricher
1515
{
1616
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
1717
{
18-
if (!Agent.IsConfigured || Agent.Tracer.CurrentTransaction == null)
19-
return;
18+
if (!Agent.IsConfigured) return;
19+
if (Agent.Tracer?.CurrentTransaction == null) return;
2020

2121
logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(
2222
"ElasticApmTransactionId", Agent.Tracer.CurrentTransaction.Id));

0 commit comments

Comments
 (0)