예제 #1
0
        public void SpanEventWireModelTests_MultipleEvents_Serialization()
        {
            const float priority = 1.975676f;
            var         duration = TimeSpan.FromSeconds(4.81);

            var expectedSerialization = new List <Dictionary <string, object>[]>
            {
                new[] {
                    new Dictionary <string, object>
                    {
                        { "type", "Span" },
                        { "priority", priority },
                        { "traceId", "ed5bbf27f28ebef3" },
                        { "duration", duration.TotalSeconds }
                    },
                    new Dictionary <string, object>
                    {
                    },
                    new Dictionary <string, object>
                    {
                        { "http.method", "GET" }
                    }
                },
                new[] {
                    new Dictionary <string, object>
                    {
                        { "type", "Span" },
                        { "priority", priority - 1 },
                        { "traceId", "fa5bbf27f28ebef3" },
                        { "duration", duration.TotalSeconds - 1 }
                    },
                    new Dictionary <string, object>
                    {
                    },
                    new Dictionary <string, object>
                    {
                        { "http.method", "POST" }
                    }
                }
            };

            var spanEvents = new[]
            {
                CreateSpanEvent(priority, duration, "ed5bbf27f28ebef3", "GET"),
                CreateSpanEvent(priority - 1, duration.Subtract(TimeSpan.FromSeconds(1)), "fa5bbf27f28ebef3", "POST")
            };

            var serialized = JsonConvert.SerializeObject(spanEvents);

            Assert.That(serialized, Is.Not.Null);

            var deserialized = JsonConvert.DeserializeObject <List <Dictionary <string, object>[]> >(serialized);

            Assert.That(deserialized, Is.Not.Null);

            Assert.AreEqual(expectedSerialization.Count, deserialized.Count);
            AttributeComparer.CompareDictionaries(expectedSerialization[0], deserialized[0]);
            AttributeComparer.CompareDictionaries(expectedSerialization[1], deserialized[1]);
        }
예제 #2
0
        public void All_attribute_value_types_in_an_event_do_serialize_correctly()
        {
            var attribValues = new AttributeValueCollection(AttributeDestinations.ErrorEvent);


            // ARRANGE
            var userAttributes = new ReadOnlyDictionary <string, object>(new Dictionary <string, object>
            {
                { "identity.user", "samw" },
                { "identity.product", "product" }
            });

            _attribDefs.GetCustomAttributeForError("identity.user").TrySetValue(attribValues, "samw");
            _attribDefs.GetCustomAttributeForError("identity.product").TrySetValue(attribValues, "product");

            var agentAttributes = new ReadOnlyDictionary <string, object>(new Dictionary <string, object>
            {
                { "queue_wait_time_ms", "2000" },
                { "original_url", "www.test.com" },
            });

            _attribDefs.QueueWaitTime.TrySetValue(attribValues, TimeSpan.FromSeconds(2));
            _attribDefs.OriginalUrl.TrySetValue(attribValues, "www.test.com");

            var intrinsicAttributes = new ReadOnlyDictionary <string, object>(new Dictionary <string, object>
            {
                { "databaseCallCount", 10d },
                { "error.message", "This is the error message" },
                { "nr.referringTransactionGuid", "DCBA43211234ABCD" },
            });

            _attribDefs.DatabaseCallCount.TrySetValue(attribValues, 10);
            _attribDefs.ErrorDotMessage.TrySetValue(attribValues, "This is the error message");
            _attribDefs.CatNrPathHash.TrySetValue(attribValues, "DCBA4321");
            _attribDefs.CatReferringPathHash.TrySetValue(attribValues, "1234ABCD");
            _attribDefs.CatReferringTransactionGuidForEvents.TrySetValue(attribValues, "DCBA43211234ABCD");
            _attribDefs.CatAlternativePathHashes.TrySetValue(attribValues, new[] { "55f97a7f", "6fc8d18f", "72827114", "9a3ed934", "a1744603", "a7d2798f", "be1039f5", "ccadfd2c", "da7edf2e", "eaca716b" });

            var isSyntheticsEvent = false;

            // ACT
            float priority            = 0.5f;
            var   errorEventWireModel = new ErrorEventWireModel(attribValues, isSyntheticsEvent, priority);
            var   serialized          = JsonConvert.SerializeObject(errorEventWireModel);
            var   deserialized        = JsonConvert.DeserializeObject <IDictionary <string, object>[]>(serialized);

            // ASSERT
            var expected = new IDictionary <string, object>[3] {
                intrinsicAttributes,
                userAttributes,
                agentAttributes
            };

            AttributeComparer.CompareDictionaries(expected, deserialized);
        }
        public void CustomEvents_MultipleEvents_Serialization()
        {
            const int countEvents = 2;

            var customEvents           = new CustomEventWireModel[countEvents];
            var expectedSerializations = new List <Dictionary <string, object>[]>();

            for (var i = 0; i < countEvents; i++)
            {
                var timestampVal  = DateTime.UtcNow;
                var typeVal       = $"CustomEvent{i}";
                var userAttribKey = $"foo{i}";
                var userAttribVal = $"bar{i}";


                var expectedSerialization = new Dictionary <string, object>[]
                {
                    new Dictionary <string, object>()
                    {
                        { _attribDefs.CustomEventType.Name, typeVal },
                        { _attribDefs.Timestamp.Name, timestampVal.ToUnixTimeMilliseconds() }
                    },

                    new Dictionary <string, object>()
                    {
                        { userAttribKey, userAttribVal }
                    },

                    new Dictionary <string, object>()
                };

                var attribVals = new AttributeValueCollection(AttributeDestinations.CustomEvent);

                _attribDefs.Timestamp.TrySetValue(attribVals, timestampVal);
                _attribDefs.CustomEventType.TrySetValue(attribVals, typeVal);
                _attribDefs.GetCustomAttributeForCustomEvent(userAttribKey).TrySetValue(attribVals, userAttribVal);

                var customEvent = new CustomEventWireModel(.5f, attribVals);

                customEvents[i] = customEvent;
                expectedSerializations.Add(expectedSerialization);
            }

            var serialized = JsonConvert.SerializeObject(customEvents);

            Assert.That(serialized, Is.Not.Null);

            var deserialized = JsonConvert.DeserializeObject <List <Dictionary <string, object>[]> >(serialized);

            Assert.That(deserialized, Is.Not.Null);

            Assert.AreEqual(customEvents.Length, deserialized.Count);
            AttributeComparer.CompareDictionaries(expectedSerializations[0], deserialized[0]);
            AttributeComparer.CompareDictionaries(expectedSerializations[1], deserialized[1]);
        }
            public void all_fields_serializes_correctly()
            {
                var attribValues = new AttributeValueCollection(AttributeDestinations.TransactionEvent);

                // ARRANGE
                var userAttributes = new Dictionary <string, object>
                {
                    { "identity.user", "user" },
                    { "identity.product", "product" },
                };

                _attribDefs.GetCustomAttributeForTransaction("identity.user").TrySetValue(attribValues, "user");
                _attribDefs.GetCustomAttributeForTransaction("identity.product").TrySetValue(attribValues, "product");

                var agentAttributes = new Dictionary <string, object>
                {
                    { "request.uri", "www.test.com" },
                };

                _attribDefs.RequestUri.TrySetValue(attribValues, "www.test.com");

                var intrinsicAttributes = new Dictionary <string, object>
                {
                    { "nr.tripId", "1234ABCD1234ABCD" },
                    { "nr.pathHash", "DCBA4321" },
                    { "nr.referringPathHash", "1234ABCD" },
                    { "nr.referringTransactionGuid", "DCBA43211234ABCD" },
                    { "nr.alternatePathHashes", "55f97a7f,6fc8d18f,72827114,9a3ed934,a1744603,a7d2798f,be1039f5,ccadfd2c,da7edf2e,eaca716b" },
                };

                _attribDefs.CatNrTripId.TrySetValue(attribValues, "1234ABCD1234ABCD");
                _attribDefs.CatNrPathHash.TrySetValue(attribValues, "DCBA4321");
                _attribDefs.CatReferringPathHash.TrySetValue(attribValues, "1234ABCD");
                _attribDefs.CatReferringTransactionGuidForEvents.TrySetValue(attribValues, "DCBA43211234ABCD");
                _attribDefs.CatAlternativePathHashes.TrySetValue(attribValues, new[] { "55f97a7f", "6fc8d18f", "72827114", "9a3ed934", "a1744603", "a7d2798f", "be1039f5", "ccadfd2c", "da7edf2e", "eaca716b" });

                var isSytheticsEvent = false;

                var expectedDictionaries = new Dictionary <string, object>[]
                {
                    intrinsicAttributes,
                    userAttributes,
                    agentAttributes
                };

                // ACT
                float priority = 0.5f;
                var   transactionEventWireModel = new TransactionEventWireModel(attribValues, isSytheticsEvent, priority);
                var   actualResult = JsonConvert.SerializeObject(transactionEventWireModel);
                var   deserialized = JsonConvert.DeserializeObject <Dictionary <string, object>[]>(actualResult);

                // ASSERT
                AttributeComparer.CompareDictionaries(expectedDictionaries, deserialized);
            }
예제 #5
0
        public void SpanEventWireModelTests_Serialization()
        {
            const float priority = 1.975676f;
            var         duration = TimeSpan.FromSeconds(4.81);

            var expectedSerialization = new Dictionary <string, object>[3]
            {
                new Dictionary <string, object>
                {
                    { "type", "Span" },
                    { "priority", priority },
                    { "traceId", "ed5bbf27f28ebef3" },
                    { "duration", duration.TotalSeconds }
                },
                new Dictionary <string, object>
                {
                },
                new Dictionary <string, object>
                {
                    { "http.method", "GET" }
                }
            };

            var spanEventWireModel = new SpanAttributeValueCollection();

            spanEventWireModel.Priority = priority;
            _attribDefs.GetTypeAttribute(TypeAttributeValue.Span).TrySetDefault(spanEventWireModel);
            _attribDefs.Priority.TrySetValue(spanEventWireModel, priority);
            _attribDefs.Duration.TrySetValue(spanEventWireModel, duration);
            _attribDefs.DistributedTraceId.TrySetValue(spanEventWireModel, "ed5bbf27f28ebef3");
            _attribDefs.HttpMethod.TrySetValue(spanEventWireModel, "GET");

            var serialized = JsonConvert.SerializeObject(spanEventWireModel);

            Assert.That(serialized, Is.Not.Null);

            var deserialized = JsonConvert.DeserializeObject <Dictionary <string, object>[]>(serialized);

            Assert.That(deserialized, Is.Not.Null);

            AttributeComparer.CompareDictionaries(expectedSerialization, deserialized);
        }
            public void only_required_fields_serialize_correctly()
            {
                // Arrange
                var attribValues = new AttributeValueCollection(AttributeDestinations.ErrorEvent);

                var isSytheticsEvent = false;

                var expectedDictionaries = new IDictionary <string, object>[]
                {
                    new Dictionary <string, object>(),
                    new Dictionary <string, object>(),
                    new Dictionary <string, object>()
                };

                // Act
                float priority = 0.5f;
                var   transactionEventWireModel = new TransactionEventWireModel(attribValues, isSytheticsEvent, priority);
                var   actualResult = JsonConvert.SerializeObject(transactionEventWireModel);
                var   deserialized = JsonConvert.DeserializeObject <Dictionary <string, object>[]>(actualResult);

                // Assert
                AttributeComparer.CompareDictionaries(expectedDictionaries, deserialized);
            }