public void Implicit_ToGuid() { var expected = SentryId.Create(); Guid actual = expected; Assert.Equal(expected.ToString(), actual.ToString("N")); }
/// <summary> /// Initializes an instance of <see cref="TransactionContext"/>. /// </summary> public TransactionContext( string name, string operation, bool?isSampled) : this(SpanId.Create(), null, SentryId.Create(), name, operation, "", null, isSampled, null) { }
public async Task Roundtrip_WithUserFeedback_Success() { // Arrange var feedback = new UserFeedback( SentryId.Create(), "Someone Nice", "*****@*****.**", "Everything is great!"); using var envelope = Envelope.FromUserFeedback(feedback); #if !NET461 && !NETCOREAPP2_1 await #endif using var stream = new MemoryStream(); // Act await envelope.SerializeAsync(stream); stream.Seek(0, SeekOrigin.Begin); using var envelopeRoundtrip = await Envelope.DeserializeAsync(stream); // Assert // Can't compare the entire object graph because output envelope contains evaluated length, // which original envelope doesn't have. envelopeRoundtrip.Header.Should().BeEquivalentTo(envelope.Header); envelopeRoundtrip.Items.Should().ContainSingle(); envelopeRoundtrip.Items[0].Payload.Should().BeOfType <JsonSerializable>() .Which.Source.Should().BeEquivalentTo(feedback); }
public async Task Roundtrip_WithUserFeedback_Success() { // Arrange var feedback = new UserFeedback( SentryId.Create(), "Donald J. Trump", "*****@*****.**", "Everything sucks" ); using var envelope = Envelope.FromUserFeedback(feedback); using var stream = new MemoryStream(); // Act await envelope.SerializeAsync(stream); stream.Seek(0, SeekOrigin.Begin); using var envelopeRoundtrip = await Envelope.DeserializeAsync(stream); // Assert // Can't compare the entire object graph because output envelope contains evaluated length, // which original envelope doesn't have. envelopeRoundtrip.Header.Should().BeEquivalentTo(envelope.Header); envelopeRoundtrip.Items.Should().ContainSingle(); var payloadContent = (envelopeRoundtrip.Items[0].Payload as JsonSerializable)?.Source; payloadContent.Should().BeEquivalentTo(feedback); }
public IHub GetSut() { Id = SentryId.Create(); var hub = Substitute.For <IHub>(); hub.IsEnabled.Returns(true); hub.CaptureEvent(Arg.Any <SentryEvent>()).Returns(Id); return(hub); }
public void SerializeObject_AllPropertiesSetToNonDefault_SerializesValidObject() { // Arrange var timestamp = DateTimeOffset.MaxValue; var context = new TransactionContext( SpanId.Create(), SpanId.Create(), SentryId.Create(), "name123", "op123", "desc", SpanStatus.AlreadyExists, null, // sampling isn't serialized and getting FluentAssertions // to ignore that on Spans and contexts isn't really straight forward true); var transaction = new TransactionTracer(DisabledHub.Instance, context) { Description = "desc123", Status = SpanStatus.Aborted, User = new User { Id = "user-id" }, Request = new Request { Method = "POST" }, Sdk = new SdkVersion { Name = "SDK-test", Version = "1.1.1" }, Environment = "environment", Level = SentryLevel.Fatal, Contexts = { ["context_key"] = "context_value", [".NET Framework"] = new Dictionary <string, string> { [".NET Framework"] = "\"v2.0.50727\", \"v3.0\", \"v3.5\"", [".NET Framework Client"] = "\"v4.8\", \"v4.0.0.0\"", [".NET Framework Full"] = "\"v4.8\"" } }, }; // Don't overwrite the contexts object as it contains trace data. // See https://github.com/getsentry/sentry-dotnet/issues/752 transaction.Sdk.AddPackage(new Package("name", "version")); transaction.AddBreadcrumb(new Breadcrumb(timestamp, "crumb")); transaction.AddBreadcrumb(new Breadcrumb( timestamp, "message", "type", new Dictionary <string, string> { { "data-key", "data-value" } }, "category", BreadcrumbLevel.Warning) ); transaction.SetExtra("extra_key", "extra_value"); transaction.Fingerprint = new[] { "fingerprint" }; transaction.SetTag("tag_key", "tag_value"); var child1 = transaction.StartChild("child_op123", "child_desc123"); child1.Status = SpanStatus.Unimplemented; child1.SetTag("q", "v"); child1.SetExtra("f", "p"); child1.Finish(SpanStatus.Unimplemented); var child2 = transaction.StartChild("child_op999", "child_desc999"); child2.Status = SpanStatus.OutOfRange; child2.SetTag("xxx", "zzz"); child2.SetExtra("f222", "p111"); child2.Finish(SpanStatus.OutOfRange); transaction.Finish(SpanStatus.Aborted); // Act var finalTransaction = new Transaction(transaction); var actualString = finalTransaction.ToJsonString(); var actual = Transaction.FromJson(Json.Parse(actualString)); // Assert actual.Should().BeEquivalentTo(finalTransaction, o => { // Timestamps lose some precision when writing to JSON o.Using <DateTimeOffset>(ctx => ctx.Subject.Should().BeCloseTo(ctx.Expectation, TimeSpan.FromMilliseconds(1)) ).WhenTypeIs <DateTimeOffset>(); return(o); }); }