Ejemplo n.º 1
0
 /// <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)
 {
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes an instance of <see cref="TransactionContext"/>.
 /// </summary>
 public TransactionContext(
     SpanId?parentSpanId,
     SentryId traceId,
     string name,
     string operation,
     bool?isParentSampled)
     : this(SpanId.Create(), parentSpanId, traceId, name, operation, "", null, isParentSampled, isParentSampled)
 {
 }
Ejemplo n.º 3
0
        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);
            });
        }