コード例 #1
0
        public void GetTransactionTrace_AppendsNodeToFauxTopLevelSegmentChildren()
        {
            var          transactionStartTime        = DateTime.Now;
            var          segmentStartTime            = transactionStartTime.AddSeconds(1);
            var          expectedStartTimeDifference = TimeSpan.FromSeconds(1);
            var          segmentDuration             = TimeSpan.FromSeconds(10);
            var          expectedEndTimeDifference   = expectedStartTimeDifference + segmentDuration;
            const string expectedName       = "some segment name";
            var          expectedParameters = new Dictionary <string, object> {
                { "foo", "bar" }
            };
            var expectedClassName     = "foo";
            var expectedMethodName    = "bar";
            var methodCallData        = new MethodCallData(expectedClassName, expectedMethodName, 1);
            var transaction           = BuildTestTransaction(startTime: transactionStartTime);
            var segments              = new[] { BuildNode(transaction, startTime: segmentStartTime, duration: segmentDuration, name: expectedName, parameters: expectedParameters, methodCallData: methodCallData) };
            var transactionMetricName = new TransactionMetricName("WebTransaction", "TrxName");
            var attributes            = new AttributeValueCollection(AttributeDestinations.TransactionTrace);

            var trace        = _transactionTraceMaker.GetTransactionTrace(transaction, segments, transactionMetricName, attributes);
            var realSegments = trace.TransactionTraceData.RootSegment.Children.First().Children;
            var firstSegment = realSegments.First();

            NrAssert.Multiple(
                () => Assert.AreEqual(expectedStartTimeDifference, firstSegment.TimeBetweenTransactionStartAndSegmentStart),
                () => Assert.AreEqual(expectedEndTimeDifference, firstSegment.TimeBetweenTransactionStartAndSegmentEnd),
                () => Assert.AreEqual(expectedName, firstSegment.Name),
                () => Assert.AreEqual(expectedClassName, firstSegment.ClassName),
                () => Assert.AreEqual(expectedMethodName, firstSegment.MethodName),
                () => Assert.AreEqual(0, firstSegment.Children.Count),
                () => Assert.True(expectedParameters.All(kvp => expectedParameters[kvp.Key] == firstSegment.Parameters[kvp.Key]))
                );
        }
        private static Segment GetSegment(string type, string method, double duration)
        {
            var methodCallData = new MethodCallData("foo", "bar", 1);
            var parameters     = (new Dictionary <string, object>());

            return(MethodSegmentDataTests.createMethodSegmentBuilder(new TimeSpan(), TimeSpan.FromSeconds(duration), 2, 1, methodCallData, parameters, type, method, false));
        }
コード例 #3
0
        private static Segment CreateSimpleSegment(int uniqueId, int?parentUniqueId, string name, TimeSpan startTime = new TimeSpan(), TimeSpan?duration = null, bool combinable = false)
        {
            duration = duration ?? TimeSpan.Zero;
            var methodCallData = new MethodCallData("foo", "bar", 1);

            return(SimpleSegmentDataTests.createSimpleSegmentBuilder(startTime, duration.Value, uniqueId, parentUniqueId, methodCallData, new Dictionary <string, object>(), name, combinable));
        }
        private static Segment GetSegment(string vendor, MetricNames.MessageBrokerDestinationType destinationType, string destination, MetricNames.MessageBrokerAction action, double duration)
        {
            var methodCallData = new MethodCallData("foo", "bar", 1);
            var parameters     = (new Dictionary <string, object>());

            return(MessageBrokerSegmentDataTests.createMessageBrokerSegmentBuilder(new TimeSpan(), TimeSpan.FromSeconds(duration), 2, 1, methodCallData, parameters, vendor, destination, destinationType, action, false));
        }
        private static Segment GetSegment(string name, double duration)
        {
            var methodCallData = new MethodCallData("foo", "bar", 1);
            var segment        = new Segment(TransactionSegmentStateHelpers.GetItransactionSegmentState(), methodCallData);

            segment.SetSegmentData(new CustomSegmentData(name));

            return(new Segment(new TimeSpan(), TimeSpan.FromSeconds(duration), segment, null));
        }
コード例 #6
0
        private Segment GetSegment(DatastoreVendor vendor, string operation, string model, double duration, CrossApplicationResponseData catResponseData = null, string host = null, string portPathOrId = null)
        {
            var methodCallData = new MethodCallData("foo", "bar", 1);
            var data           = new DatastoreSegmentData(_databaseService, new ParsedSqlStatement(vendor, model, operation), null, new ConnectionInfo(host, portPathOrId, null));
            var segment        = new Segment(TransactionSegmentStateHelpers.GetItransactionSegmentState(), methodCallData);

            segment.SetSegmentData(data);

            return(segment.CreateSimilar(new TimeSpan(), TimeSpan.FromSeconds(duration), null));
        }
コード例 #7
0
        private Segment CreateCustomSegmentBuilder(MethodCallData methodCallData, string name, bool combinable)
        {
            var customSegmentData = new CustomSegmentData(name);
            var segment           = new Segment(_transactionSegmentState, methodCallData);

            segment.Combinable = combinable;
            segment.SetSegmentData(customSegmentData);

            return(segment);
        }
コード例 #8
0
        private static ImmutableSegmentTreeNode BuildNode(TimeSpan relativeStart = new TimeSpan(), TimeSpan?duration = null)
        {
            var methodCallData = new MethodCallData("typeName", "methodName", 1);
            var segment        = new Segment(TransactionSegmentStateHelpers.GetItransactionSegmentState(), methodCallData);

            segment.SetSegmentData(new SimpleSegmentData(""));

            return(new SegmentTreeNodeBuilder(
                       new Segment(relativeStart, duration ?? TimeSpan.Zero, segment, null))
                   .Build());
        }
        private static Segment GetSegment(string uri, string method, double duration, CrossApplicationResponseData catResponseData = null)
        {
            var methodCallData = new MethodCallData("foo", "bar", 1);

            var data    = new ExternalSegmentData(new Uri(uri), method, catResponseData);
            var segment = new Segment(TransactionSegmentStateHelpers.GetItransactionSegmentState(), methodCallData);

            segment.SetSegmentData(data);

            return(new Segment(new TimeSpan(), TimeSpan.FromSeconds(duration), segment, null));
        }
コード例 #10
0
 public Segment(ITransactionSegmentState transactionSegmentState, MethodCallData methodCallData)
 {
     ThreadId                 = transactionSegmentState.CurrentManagedThreadId;
     RelativeStartTime        = transactionSegmentState.GetRelativeTime();
     _transactionSegmentState = transactionSegmentState;
     ParentUniqueId           = transactionSegmentState.ParentSegmentId();
     UniqueId                 = transactionSegmentState.CallStackPush(this);
     MethodCallData           = methodCallData;
     Data = new MethodSegmentData(methodCallData.TypeName, methodCallData.MethodName);
     Data.AttachSegmentDataState(this);
     Combinable = false;
     IsLeaf     = false;
 }
コード例 #11
0
        public bool IsCombinableWith(Segment otherSegment)
        {
            if (!Combinable || !otherSegment.Combinable)
            {
                return(false);
            }

            if (!MethodCallData.Equals(otherSegment.MethodCallData))
            {
                return(false);
            }

            return(Data.IsCombinableWith(otherSegment.Data));
        }
コード例 #12
0
        private static ImmutableSegmentTreeNode BuildNode(ImmutableTransaction transaction = null, DateTime?startTime = null, TimeSpan?duration = null, string name = "", MethodCallData methodCallData = null, IEnumerable <KeyValuePair <string, object> > parameters = null)
        {
            startTime = startTime ?? DateTime.Now;
            var relativeStart = startTime.Value - (transaction?.StartTime ?? startTime.Value);

            methodCallData = methodCallData ?? new MethodCallData("typeName", "methodName", 1);
            return(new SegmentTreeNodeBuilder(SimpleSegmentDataTests.createSimpleSegmentBuilder(relativeStart, duration ?? TimeSpan.Zero, 2, 1, methodCallData, parameters ?? new Dictionary <string, object>(), name, false))
                   .Build());
        }
コード例 #13
0
        public static Segment createSimpleSegmentBuilder(TimeSpan start, TimeSpan duration, int uniqueId, int?parentId, MethodCallData methodCallData, IEnumerable <KeyValuePair <string, object> > parameters, string name, bool combinable, int managedThreadId = 1)
        {
            var segmentState = createTransactionSegmentState(uniqueId, parentId, managedThreadId);
            var segment      = new Segment(segmentState, methodCallData);

            segment.SetSegmentData(new SimpleSegmentData(name));
            segment.Combinable = combinable;

            return(segment.CreateSimilar(start, duration, parameters));
        }
コード例 #14
0
        public static Segment createExternalSegmentBuilder(TimeSpan relativeStart, TimeSpan duration, int uniqueId, int?parentId, MethodCallData methodCallData, IEnumerable <KeyValuePair <string, object> > parameters, Uri uri, string method, CrossApplicationResponseData crossApplicationResponseData, bool combinable)
        {
            var data    = new ExternalSegmentData(uri, method, crossApplicationResponseData);
            var segment = new Segment(SimpleSegmentDataTests.createTransactionSegmentState(uniqueId, parentId), methodCallData);

            segment.SetSegmentData(data);
            segment.Combinable = combinable;

            return(segment);
        }
コード例 #15
0
 private static SegmentTreeNodeBuilder GetNodeBuilder(TimeSpan startTime = new TimeSpan(), TimeSpan?duration = null, string name = "", MethodCallData methodCallData = null, IEnumerable <KeyValuePair <string, object> > parameters = null)
 {
     methodCallData = methodCallData ?? new MethodCallData("typeName", "methodName", 1);
     return(new SegmentTreeNodeBuilder(SimpleSegmentDataTests.createSimpleSegmentBuilder(startTime, duration ?? TimeSpan.Zero, 2, 1, methodCallData, parameters ?? new Dictionary <string, object>(), name, false)));
 }
コード例 #16
0
        private ImmutableSegmentTreeNode BuildDataStoreSegmentNodeWithInstanceData(TimeSpan startTime = new TimeSpan(), TimeSpan?duration = null, string name = "", MethodCallData methodCallData = null, IEnumerable <KeyValuePair <string, object> > parameters = null)
        {
            methodCallData = methodCallData ?? new MethodCallData("typeName", "methodName", 1);

            var data = new DatastoreSegmentData(_databaseService, new ParsedSqlStatement(DatastoreVendor.MSSQL, "test_table", "SELECT"),
                                                "SELECT * FROM test_table",
                                                new ConnectionInfo("My Host", "My Port", "My Database"));

            var segment = new Segment(TransactionSegmentStateHelpers.GetItransactionSegmentState(), methodCallData);

            segment.SetSegmentData(data);

            return(new SegmentTreeNodeBuilder(new Segment(startTime, duration ?? TimeSpan.Zero, segment, null))
                   .Build());
        }
コード例 #17
0
        public static Segment BuildSegment(ITransactionSegmentState txSegmentState, DatastoreVendor vendor, string model, string commandText, TimeSpan startTime = new TimeSpan(), TimeSpan?duration = null, string name = "", MethodCallData methodCallData = null, IEnumerable <KeyValuePair <string, object> > parameters = null, string host = null, string portPathOrId = null, string databaseName = null)
        {
            if (txSegmentState == null)
            {
                txSegmentState = TransactionSegmentStateHelpers.GetItransactionSegmentState();
            }

            methodCallData = methodCallData ?? new MethodCallData("typeName", "methodName", 1);
            var data    = new DatastoreSegmentData(_databaseService, new ParsedSqlStatement(vendor, model, null), commandText, new ConnectionInfo(host, portPathOrId, databaseName));
            var segment = new Segment(txSegmentState, methodCallData);

            segment.SetSegmentData(data);

            return(new Segment(startTime, duration, segment, parameters));
        }
コード例 #18
0
        public static Segment createMessageBrokerSegmentBuilder(TimeSpan start, TimeSpan duration, int uniqueId, int?parentId, MethodCallData methodCallData, IEnumerable <KeyValuePair <string, object> > enumerable, string vendor, string queue, MetricNames.MessageBrokerDestinationType type, MetricNames.MessageBrokerAction action, bool combinable)
        {
            var segment = new Segment(SimpleSegmentDataTests.createTransactionSegmentState(uniqueId, parentId), methodCallData);

            segment.SetSegmentData(new MessageBrokerSegmentData(vendor, queue, type, action));
            segment.Combinable = combinable;

            return(new Segment(start, duration, segment, null));
        }
コード例 #19
0
        public static Segment createMethodSegmentBuilder(TimeSpan start, TimeSpan duration, int uniqueId, int?parentId, MethodCallData methodCallData, IEnumerable <KeyValuePair <string, object> > enumerable, string type, string method, bool combinable)
        {
            var segment = new Segment(SimpleSegmentDataTests.createTransactionSegmentState(uniqueId, parentId), methodCallData);

            segment.SetSegmentData(new MethodSegmentData(type, method));
            segment.Combinable = combinable;

            return(new Segment(start, duration, segment, null));
        }