internal SpanData CreateTestSpan(
            bool setAttributes = true,
            bool addEvents     = true,
            bool addLinks      = true)
        {
            var startTimestamp = DateTime.UtcNow;
            var endTimestamp   = startTimestamp.AddSeconds(60);
            var eventTimestamp = DateTime.UtcNow;
            var traceId        = ActivityTraceId.CreateFromString("e8ea7e9ac72de94e91fabc613f9686b2".AsSpan());

            var parentSpanId = ActivitySpanId.CreateFromBytes(new byte[] { 12, 23, 34, 45, 56, 67, 78, 89 });
            var attributes   = new Dictionary <string, object>
            {
                { "stringKey", "value" },
                { "longKey", 1L },
                { "longKey2", 1 },
                { "doubleKey", 1D },
                { "doubleKey2", 1F },
                { "boolKey", true },
            };
            var events = new List <Event>
            {
                new Event(
                    "Event1",
                    eventTimestamp,
                    new Dictionary <string, object>
                {
                    { "key", "value" },
                }
                    ),
                new Event(
                    "Event2",
                    eventTimestamp,
                    new Dictionary <string, object>
                {
                    { "key", "value" },
                }
                    ),
            };

            var linkedSpanId = ActivitySpanId.CreateFromString("888915b6286b9c41".AsSpan());

            var span = SpanDataHelper.CreateSpanData(
                "Name",
                new SpanContext(traceId, parentSpanId, ActivityTraceFlags.Recorded),
                SpanKind.Client,
                startTimestamp,
                addLinks ? new[] { new Link(new SpanContext(
                                                traceId,
                                                linkedSpanId,
                                                ActivityTraceFlags.Recorded)), } : Enumerable.Empty <Link>(),
                setAttributes ? attributes : new Dictionary <string, object>(),
                addEvents ? events : Enumerable.Empty <Event>(),
                Status.Ok,
                endTimestamp);

            return(span);
        }
Ejemplo n.º 2
0
        private SpanData CreateTestSpan()
        {
            var startTimestamp = new DateTimeOffset(2019, 1, 1, 0, 0, 0, TimeSpan.Zero);
            var endTimestamp   = startTimestamp.AddSeconds(60);
            var eventTimestamp = new DateTimeOffset(2019, 1, 1, 0, 0, 0, TimeSpan.Zero);

            var traceId      = ActivityTraceId.CreateFromString("e8ea7e9ac72de94e91fabc613f9686b2".AsSpan());
            var parentSpanId = ActivitySpanId.CreateFromBytes(new byte[] { 12, 23, 34, 45, 56, 67, 78, 89 });
            var attributes   = new Dictionary <string, object>
            {
                { "stringKey", "value" },
                { "longKey", 1L },
                { "longKey2", 1 },
                { "doubleKey", 1D },
                { "doubleKey2", 1F },
                { "boolKey", true },
            };
            var events = new List <Event>
            {
                new Event(
                    "Event1",
                    eventTimestamp,
                    new Dictionary <string, object>
                {
                    { "key", "value" },
                }
                    ),
                new Event(
                    "Event2",
                    eventTimestamp,
                    new Dictionary <string, object>
                {
                    { "key", "value" },
                }
                    ),
            };

            var linkedSpanId = ActivitySpanId.CreateFromString("888915b6286b9c41".AsSpan());

            var link = new Link(new SpanContext(
                                    traceId,
                                    linkedSpanId,
                                    ActivityTraceFlags.Recorded));

            return(SpanDataHelper.CreateSpanData(
                       "Name",
                       new SpanContext(traceId, parentSpanId, ActivityTraceFlags.Recorded),
                       SpanKind.Client,
                       startTimestamp,
                       new[] { link },
                       attributes,
                       events,
                       Status.Ok,
                       endTimestamp));
        }