Beispiel #1
0
    public void SerializeObject_AllPropertiesSetToNonDefault_SerializesValidObject()
    {
        // Arrange
        var trace = new Trace
        {
            Operation    = "op123",
            Status       = SpanStatus.Aborted,
            IsSampled    = false,
            ParentSpanId = SpanId.Parse("1000000000000000"),
            SpanId       = SpanId.Parse("2000000000000000"),
            TraceId      = SentryId.Parse("75302ac48a024bde9a3b3734a82e36c8")
        };

        // Act
        var actual = trace.ToJsonString();

        // Assert
        Assert.Equal(
            "{" +
            "\"type\":\"trace\"," +
            "\"span_id\":\"2000000000000000\"," +
            "\"parent_span_id\":\"1000000000000000\"," +
            "\"trace_id\":\"75302ac48a024bde9a3b3734a82e36c8\"," +
            "\"op\":\"op123\"," +
            "\"status\":\"aborted\"" +
            "}",
            actual);
    }
        public async Task Transaction_is_started_automatically_from_incoming_trace_header()
        {
            // Arrange
            ITransactionData transaction = null;

            var sentryClient = Substitute.For <ISentryClient>();

            var hub = new Internal.Hub(sentryClient, new SentryOptions
            {
                Dsn = DsnSamples.ValidDsnWithoutSecret,
                TracesSampleRate = 1
            });

            var server = new TestServer(new WebHostBuilder()
                                        .UseDefaultServiceProvider(di => di.EnableValidation())
                                        .UseSentry()
                                        .ConfigureServices(services =>
            {
                services.AddRouting();

                services.RemoveAll(typeof(Func <IHub>));
                services.AddSingleton <Func <IHub> >(() => hub);
            })
                                        .Configure(app =>
            {
                app.UseRouting();
                app.UseSentryTracing();

                app.UseEndpoints(routes =>
                {
                    routes.Map("/person/{id}", _ =>
                    {
                        transaction = hub.GetSpan() as ITransactionData;
                        return(Task.CompletedTask);
                    });
                });
            })
                                        );

            var client = server.CreateClient();

            // Act
            using var request = new HttpRequestMessage(HttpMethod.Get, "/person/13")
                  {
                      Headers = { { "sentry-trace", "75302ac48a024bde9a3b3734a82e36c8-1000000000000000-0" } }
                  };

            await client.SendAsync(request);

            // Assert
            transaction.Should().NotBeNull();
            transaction?.Name.Should().Be("GET /person/{id}");
            transaction.TraceId.Should().Be(SentryId.Parse("75302ac48a024bde9a3b3734a82e36c8"));
            transaction.ParentSpanId.Should().Be(SpanId.Parse("1000000000000000"));
            transaction.IsSampled.Should().BeFalse();
        }
Beispiel #3
0
        public void Parse_WithoutSampled_Works()
        {
            // Arrange
            const string headerValue = "75302ac48a024bde9a3b3734a82e36c8-1000000000000000";

            // Act
            var header = SentryTraceHeader.Parse(headerValue);

            // Assert
            header.TraceId.Should().Be(SentryId.Parse("75302ac48a024bde9a3b3734a82e36c8"));
            header.SpanId.Should().Be(SpanId.Parse("1000000000000000"));
            header.IsSampled.Should().BeNull();
        }
Beispiel #4
0
    public void Clone_CopyValues()
    {
        // Arrange
        var trace = new Trace
        {
            Operation    = "op123",
            Status       = SpanStatus.Aborted,
            IsSampled    = false,
            ParentSpanId = SpanId.Parse("1000000000000000"),
            SpanId       = SpanId.Parse("2000000000000000"),
            TraceId      = SentryId.Parse("75302ac48a024bde9a3b3734a82e36c8")
        };

        // Act
        var clone = trace.Clone();

        // Assert
        Assert.Equal(trace.Operation, clone.Operation);
        Assert.Equal(trace.Status, clone.Status);
        Assert.Equal(trace.IsSampled, clone.IsSampled);
        Assert.Equal(trace.ParentSpanId, clone.ParentSpanId);
        Assert.Equal(trace.SpanId, clone.SpanId);
        Assert.Equal(trace.TraceId, clone.TraceId);
    }
Beispiel #5
0
        public async Task Transaction_is_started_automatically_from_incoming_trace_header()
        {
            // Arrange
            var sentryClient = Substitute.For <ISentryClient>();

            var hub = new Internal.Hub(new SentryOptions
            {
                Dsn = DsnSamples.ValidDsnWithoutSecret,
                TracesSampleRate = 1
            }, sentryClient);

            var server = new TestServer(new WebHostBuilder()
                                        .UseDefaultServiceProvider(di => di.EnableValidation())
                                        .UseSentry()
                                        .ConfigureServices(services =>
            {
                services.AddRouting();

                services.RemoveAll(typeof(Func <IHub>));
                services.AddSingleton <Func <IHub> >(() => hub);
            })
                                        .Configure(app =>
            {
                app.UseRouting();
                app.UseSentryTracing();

                app.UseEndpoints(routes =>
                {
                    routes.Map("/person/{id}", _ => Task.CompletedTask);
                });
            })
                                        );

            var client = server.CreateClient();

            // Act
            using var request = new HttpRequestMessage(HttpMethod.Get, "/person/13")
                  {
                      Headers = { { "sentry-trace", "75302ac48a024bde9a3b3734a82e36c8-1000000000000000-0" } }
                  };

            await client.SendAsync(request);

            // Assert
            sentryClient.Received(1).CaptureTransaction(Arg.Is <Transaction>(t =>
                                                                             t.Name == "GET /person/{id}" &&
                                                                             t.TraceId == SentryId.Parse("75302ac48a024bde9a3b3734a82e36c8") &&
                                                                             t.ParentSpanId == SpanId.Parse("1000000000000000") &&
                                                                             t.IsSampled == false
                                                                             ));
        }