-
Notifications
You must be signed in to change notification settings - Fork 205
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
Fix nullref in Elastic.Apm.Extensions.Logging #1311
Fix nullref in Elastic.Apm.Extensions.Logging #1311
Conversation
@@ -42,7 +42,7 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except | |||
|
|||
if (_agent is ApmAgent apmAgent && exception != null) | |||
{ | |||
errorLog.StackTrace = StacktraceHelper.GenerateApmStackTrace(exception, null, "CaptureErrorLogsAsApmError", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the problem 🤦
💔 Tests Failed
Expand to view the summary
Build stats
Test stats 🧪
Trends 🧪Test errors
Expand to view the tests failures
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
The null conditional operator on logger
inside GenerateApmStackTrace
look unnecessary. Removing them would avoid performing a null check on each logger invocation.
@@ -48,7 +48,7 @@ internal static class StacktraceHelper | |||
var len = stackTraceLimit == -1 ? frames.Length : Math.Min(frames.Length, stackTraceLimit); | |||
var retVal = new List<CapturedStackFrame>(len); | |||
|
|||
logger.Trace()?.Log("transform stack frames"); | |||
logger?.Trace()?.Log("transform stack frames"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The null conditional operator on logger
looks unneccessary. StacktraceHelper
is internal and GenerateApmStackTrace
is called only by agent code where the logger should never be null (if it is null, it's a bug).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, there were some calls on logger
with .?
and some without it - I removed it from all of them.
@@ -64,7 +64,7 @@ internal static class StacktraceHelper | |||
|
|||
var fileName = frame?.GetFileName(); | |||
|
|||
logger.Trace()?.Log("{MethodName}, {lineNo}", functionName, frame?.GetFileLineNumber()); | |||
logger?.Trace()?.Log("{MethodName}, {lineNo}", functionName, frame?.GetFileLineNumber()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The null conditional operator on logger
looks unneccessary. StacktraceHelper
is internal and GenerateApmStackTrace
is called only by agent code where the logger should never be null (if it is null, it's a bug).
@@ -42,7 +42,7 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except | |||
|
|||
if (_agent is ApmAgent apmAgent && exception != null) | |||
{ | |||
errorLog.StackTrace = StacktraceHelper.GenerateApmStackTrace(exception, null, "CaptureErrorLogsAsApmError", | |||
errorLog.StackTrace = StacktraceHelper.GenerateApmStackTrace(exception, _agent.Logger, "CaptureErrorLogsAsApmError", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor nitpick:
errorLog.StackTrace = StacktraceHelper.GenerateApmStackTrace(exception, _agent.Logger, "CaptureErrorLogsAsApmError", | |
errorLog.StackTrace = StacktraceHelper.GenerateApmStackTrace(exception, apmAgent.Logger, "CaptureErrorLogsAsApmError", |
It makes no difference either way, but reads more intuitively to me, since the other passed values come from apmAgent
…u-20 * upstream/master: (21 commits) Prefer W3C traceparent over elastic-apm-traceparent (elastic#1302) fix spacing and cross references in docs (elastic#1328) Update README (elastic#1325) Mark MicrosoftAzureBlobStorageTracer internal (elastic#1326) Update docs (elastic#1327) Update context.destination.address (elastic#1324) synchronize json schema specs (elastic#1320) Don't package Elastic.Apm.Specification (elastic#1316) Update setup.asciidoc (elastic#1318) Prepare release v.1.10.0 (elastic#1314) Fix nullref in Elastic.Apm.Extensions.Logging (elastic#1311) Capture errors with startup hook auto instrumentation (elastic#1298) Use Logger to log exception in AgentComponents initialization (elastic#1305) fix: use .NET native SDK for build and test (elastic#1301) Skip running Elasticsearch docker test when docker not available (elastic#1312) Use TraceLogger as default logger in ASP.NET Full Framework (elastic#1288) Create receive messaging span when inside transaction (elastic#1308) Fix SanitizeFieldNamesTests (elastic#1299) Do not capture HTTP child spans for Elasticsearch (elastic#1306) Use storage account in destination.service.resource (elastic#1284) ...
Fixes #1309
Also extended the test to cover the case where the nullref happened.