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(); }
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(); }
public void Serialization_Session_Success() { // Arrange var session = new Session( SentryId.Parse("75302ac48a024bde9a3b3734a82e36c8"), "bar", DateTimeOffset.Parse("2020-01-01T00:00:00+00:00", CultureInfo.InvariantCulture), "release123", "env123", "192.168.0.1", "Google Chrome" ); session.ReportError(); session.ReportError(); session.ReportError(); var sessionUpdate = new SessionUpdate( session, true, DateTimeOffset.Parse("2020-01-02T00:00:00+00:00", CultureInfo.InvariantCulture), 5, SessionEndStatus.Crashed ); // Act var json = sessionUpdate.ToJsonString(); // Assert json.Should().Be( "{" + "\"sid\":\"75302ac48a024bde9a3b3734a82e36c8\"," + "\"did\":\"bar\"," + "\"init\":true," + "\"started\":\"2020-01-01T00:00:00+00:00\"," + "\"timestamp\":\"2020-01-02T00:00:00+00:00\"," + "\"seq\":5," + "\"duration\":86400," + "\"errors\":3," + "\"status\":\"crashed\"," + "\"attrs\":{" + "\"release\":\"release123\"," + "\"environment\":\"env123\"," + "\"ip_address\":\"192.168.0.1\"," + "\"user_agent\":\"Google Chrome\"" + "}" + "}" ); }
public void CreateUpdate_IncrementsSequenceNumber() { // Arrange var session = new Session( SentryId.Parse("75302ac48a024bde9a3b3734a82e36c8"), "bar", DateTimeOffset.Parse("2020-01-01T00:00:00+00:00", CultureInfo.InvariantCulture), "release123", "env123", "192.168.0.1", "Google Chrome"); // Act var sessionUpdate1 = session.CreateUpdate(true, DateTimeOffset.Now); var sessionUpdate2 = session.CreateUpdate(false, DateTimeOffset.Now); var sessionUpdate3 = session.CreateUpdate(false, DateTimeOffset.Now); // Assert sessionUpdate1.SequenceNumber.Should().Be(0); sessionUpdate2.SequenceNumber.Should().Be(1); sessionUpdate3.SequenceNumber.Should().Be(2); }
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); }
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 )); }