public async Task TagsOnSpanAsyncError() { var payloadSender = await AssertWith1TransactionAnd1ErrorAnd1SpanAsync(async t => { Func <Task> act = async() => { await t.CaptureSpan(SpanName, SpanType, async span => { await WaitHelpers.Delay2XMinimum(); span.Tags["foo"] = "bar"; if (new Random().Next(1) == 0) //avoid unreachable code warning. { throw new InvalidOperationException(ExceptionMessage); } }); }; await act.Should().ThrowAsync <InvalidOperationException>(); }); //According to the Intake API tags are stored on the Context (and not on Spans.Tags directly). payloadSender.SpansOnFirstTransaction[0].Context.Tags.Should().Contain("foo", "bar"); //Also make sure the tag is visible directly on Span.Tags. payloadSender.SpansOnFirstTransaction[0].Tags.Should().Contain("foo", "bar"); }
public async Task AsyncTaskWithReturnType_OnSubSpan() => await AssertWith1TransactionAnd1SpanAsyncOnSubSpan(async s => { var res = await s.CaptureSpan(SpanName, SpanType, async() => { await WaitHelpers.Delay2XMinimum(); return(42); }); res.Should().Be(42); });
public async Task AsyncTaskWithParameter_OnSubSpan() => await AssertWith1TransactionAnd1SpanAsyncOnSubSpan(async s => { await s.CaptureSpan(SpanName, SpanType, async s2 => { s2.Should().NotBeNull(); await WaitHelpers.Delay2XMinimum(); }); });
public async Task AsyncTaskWithReturnType() => await AssertWith1TransactionAnd1SpanAsync(async t => { var res = await t.CaptureSpan(SpanName, SpanType, async() => { await WaitHelpers.Delay2XMinimum(); return(42); }); Assert.Equal(42, res); });
public async Task AsyncTaskWithParameter() => await AssertWith1TransactionAnd1SpanAsync(async t => { await t.CaptureSpan(SpanName, SpanType, async s => { Assert.NotNull(s); await WaitHelpers.Delay2XMinimum(); }); });
public async Task AsyncTaskWithException() => await AssertWith1TransactionAnd1ErrorAnd1SpanAsync(async t => { await Assert.ThrowsAsync <InvalidOperationException>(async() => { await t.CaptureSpan(SpanName, SpanType, async() => { await WaitHelpers.Delay2XMinimum(); throw new InvalidOperationException(ExceptionMessage); }); }); });
public async Task AsyncTaskWithReturnTypeAndParameter() => await AssertWith1TransactionAnd1SpanAsync(async t => { var res = await t.CaptureSpan(SpanName, SpanType, async s => { s.Should().NotBeNull(); await WaitHelpers.Delay2XMinimum(); return(42); }); res.Should().Be(42); });
public async Task AsyncTaskWithExceptionAndParameter_OnSubSpan() => await AssertWith1TransactionAnd1ErrorAnd1SpanAsyncOnSubSpan(async s => { Func <Task> act = async() => { await s.CaptureSpan(SpanName, SpanType, async s2 => { s2.Should().NotBeNull(); await WaitHelpers.Delay2XMinimum(); throw new InvalidOperationException(ExceptionMessage); }); }; await act.Should().ThrowAsync <InvalidOperationException>(); });
public async Task AsyncTaskWithExceptionOn_SubSpan() => await AssertWith1TransactionAnd1ErrorAnd1SpanAsync(async t => { Func <Task> act = async() => { await t.CaptureSpan(SpanName, SpanType, async() => { await WaitHelpers.Delay2XMinimum(); throw new InvalidOperationException(ExceptionMessage); }); }; var should = await act.Should().ThrowAsync <InvalidOperationException>(); should.WithMessage(ExceptionMessage); });
public async Task LabelsOnSpanAsync() { var payloadSender = await AssertWith1TransactionAnd1SpanAsync( async t => { await t.CaptureSpan(SpanName, SpanType, async span => { await WaitHelpers.Delay2XMinimum(); span.SetLabel("foo", "bar"); }); }); //According to the Intake API labels are stored on the Context (and not on Spans.Labels directly). payloadSender.SpansOnFirstTransaction[0].Context.InternalLabels.Value.MergedDictionary["foo"].Value.Should().Be("bar"); }
public async Task TagsOnSpanAsync() { var payloadSender = await AssertWith1TransactionAnd1SpanAsync( async t => { await t.CaptureSpan(SpanName, SpanType, async span => { await WaitHelpers.Delay2XMinimum(); span.Tags["foo"] = "bar"; }); }); //According to the Intake API tags are stored on the Context (and not on Spans.Tags directly). payloadSender.SpansOnFirstTransaction[0].Context.Tags.Should().Contain("foo", "bar"); //Also make sure the tag is visible directly on Span.Tags. payloadSender.SpansOnFirstTransaction[0].Tags.Should().Contain("foo", "bar"); }
public async Task AsyncTaskWithReturnTypeAndException_OnSubSpan() => await AssertWith1TransactionAnd1ErrorAnd1SpanAsyncOnSubSpan(async s => { Func <Task> act = async() => { await s.CaptureSpan(SpanName, SpanType, async() => { await WaitHelpers.Delay2XMinimum(); if (new Random().Next(1) == 0) //avoid unreachable code warning. { throw new InvalidOperationException(ExceptionMessage); } return(42); }); }; await act.Should().ThrowAsync <InvalidOperationException>(); });
public async Task AsyncTaskWithReturnTypeAndException() => await AssertWith1TransactionAnd1ErrorAnd1SpanAsync(async t => { await Assert.ThrowsAsync <InvalidOperationException>(async() => { var result = await t.CaptureSpan(SpanName, SpanType, async() => { await WaitHelpers.Delay2XMinimum(); if (new Random().Next(1) == 0) //avoid unreachable code warning. { throw new InvalidOperationException(ExceptionMessage); } return(42); }); Assert.True(false); //Should not be executed because the agent isn't allowed to catch an exception. Assert.Equal(42, result); //But if it'd not throw it'd be 42. }); });
public async Task CancelledAsyncTask() { var agent = new ApmAgent(new TestAgentComponents()); var cancellationTokenSource = new CancellationTokenSource(); var token = cancellationTokenSource.Token; cancellationTokenSource.Cancel(); await agent.Tracer.CaptureTransaction(TransactionName, TransactionType, async t => { await Assert.ThrowsAsync <OperationCanceledException>(async() => { await t.CaptureSpan(SpanName, SpanType, async() => { // ReSharper disable once MethodSupportsCancellation, we want to delay before we throw the exception await WaitHelpers.Delay2XMinimum(); token.ThrowIfCancellationRequested(); }); }); }); }
public async Task LabelsOnSpanAsyncError() { var payloadSender = await AssertWith1TransactionAnd1ErrorAnd1SpanAsync(async t => { Func <Task> act = async() => { await t.CaptureSpan(SpanName, SpanType, async span => { await WaitHelpers.Delay2XMinimum(); span.SetLabel("foo", "bar"); if (new Random().Next(1) == 0) //avoid unreachable code warning. { throw new InvalidOperationException(ExceptionMessage); } }); }; await act.Should().ThrowAsync <InvalidOperationException>(); }); //According to the Intake API labels are stored on the Context (and not on Spans.Labels directly). payloadSender.SpansOnFirstTransaction[0].Context.InternalLabels.Value.MergedDictionary["foo"].Value.Should().Be("bar"); }
public async Task AsyncTask_OnSubSpan() => await AssertWith1TransactionAnd1SpanAsyncOnSubSpan(async s => { await s.CaptureSpan(SpanName, SpanType, async() => { await WaitHelpers.Delay2XMinimum(); }); });