Skip to content

Commit 4878968

Browse files
committed
test, tracing disabled exception. remove verification on capturemode because is always false
1 parent dcc3705 commit 4878968

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

libraries/src/AWS.Lambda.Powertools.Tracing/Internal/TracingAspect.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,6 @@ private bool TracingDisabled()
242242
/// <returns><c>true</c> if tracing should capture responses, <c>false</c> otherwise.</returns>
243243
private bool CaptureResponse()
244244
{
245-
if(TracingDisabled())
246-
return false;
247-
248245
switch (_captureMode)
249246
{
250247
case TracingCaptureMode.EnvironmentVariable:

libraries/tests/AWS.Lambda.Powertools.Tracing.Tests/TracingAttributeTest.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,29 @@ public void OnException_WhenTracerCaptureModeIsError_CapturesError_Inner_Excepti
542542
Assert.NotNull(exception.InnerException);
543543
Assert.Equal("Inner Exception!!",exception.InnerException.Message);
544544
}
545+
546+
[Fact]
547+
public void OnException_When_Tracing_Disabled_Does_Not_CapturesError()
548+
{
549+
// Arrange
550+
Environment.SetEnvironmentVariable("LAMBDA_TASK_ROOT", "AWS");
551+
Environment.SetEnvironmentVariable("POWERTOOLS_SERVICE_NAME", "POWERTOOLS");
552+
Environment.SetEnvironmentVariable("POWERTOOLS_TRACE_DISABLED", "true");
553+
554+
// Act
555+
var segment = AWSXRayRecorder.Instance.TraceContext.GetEntity();
556+
557+
var exception = Record.Exception(() =>
558+
{
559+
_handler.HandleWithCaptureModeError(true);
560+
});
561+
562+
// Assert
563+
Assert.NotNull(exception);
564+
Assert.False(segment.IsSubsegmentsAdded);
565+
Assert.Empty(segment.Subsegments);
566+
Assert.False(segment.IsMetadataAdded);
567+
}
545568

546569
[Fact]
547570
public void OnException_WhenTracerCaptureModeIsResponseAndError_CapturesError()

0 commit comments

Comments
 (0)