private ImmutableTransaction BuildTestTransaction(DateTime?startTime = null, TimeSpan?duration = null, TimeSpan?responseTime = null, string uri = null, string guid = null)
        {
            var transactionMetadata = new TransactionMetadata();

            if (uri != null)
            {
                transactionMetadata.SetUri(uri);
            }

            var name     = TransactionName.ForWebTransaction("foo", "bar");
            var segments = Enumerable.Empty <Segment>();
            var metadata = transactionMetadata.ConvertToImmutableMetadata();

            startTime = startTime ?? DateTime.Now;
            duration  = duration ?? TimeSpan.FromSeconds(1);
            guid      = guid ?? Guid.NewGuid().ToString();

            return(new ImmutableTransaction(name, segments, metadata, startTime.Value, duration.Value, responseTime, guid, false, false, false, 1.2f, false, string.Empty, null, _attribDefs));
        }
        private IInternalTransaction BuildTestTransaction(TimeSpan?queueTime = null, TimeSpan?applicationTime = null)
        {
            var name = TransactionName.ForWebTransaction("foo", "bar");
            var time = applicationTime ?? TimeSpan.FromSeconds(1);

            ITimer timer = Mock.Create <ITimer>();

            Mock.Arrange(() => timer.Duration).Returns(time);

            var priority = 0.5f;
            var tx       = new Transaction(_configuration, name, timer, DateTime.UtcNow, Mock.Create <ICallStackManager>(), Mock.Create <IDatabaseService>(), priority, Mock.Create <IDatabaseStatementParser>(), Mock.Create <IDistributedTracePayloadHandler>(), Mock.Create <IErrorService>(), _attribDefs);

            if (queueTime != null)
            {
                tx.TransactionMetadata.SetQueueTime(queueTime.Value);
            }

            return(tx);
        }
Ejemplo n.º 3
0
        public void OnTransactionFinalized_UpdatesTransactionPathHash()
        {
            var transaction       = BuildTestTransaction();
            var mockedTransaction = Mock.Create <IInternalTransaction>();

            Mock.Arrange(() => mockedTransaction.Finish()).Returns(true);
            Mock.Arrange(() => mockedTransaction.ConvertToImmutableTransaction()).Returns(transaction);

            var transactionName = TransactionName.ForWebTransaction("a", "b");

            Mock.Arrange(() => mockedTransaction.CandidateTransactionName.CurrentTransactionName).Returns(transactionName);
            Mock.Arrange(() => _transactionMetricNameMaker.GetTransactionMetricName(transactionName)).Returns(new TransactionMetricName("c", "d"));
            Mock.Arrange(() => mockedTransaction.TransactionMetadata.CrossApplicationReferrerPathHash).Returns("referrerPathHash");
            Mock.Arrange(() => _pathHashMaker.CalculatePathHash("c/d", "referrerPathHash")).Returns("pathHash");

            EventBus <TransactionFinalizedEvent> .Publish(new TransactionFinalizedEvent(mockedTransaction));

            Mock.Assert(() => mockedTransaction.TransactionMetadata.SetCrossApplicationPathHash("pathHash"));
        }
Ejemplo n.º 4
0
        public void multiple_sqlId_does_not_has_9_digits_number()
        {
            var transactionMetadata = new TransactionMetadata();
            var name     = TransactionName.ForWebTransaction("foo", "bar");
            var metadata = transactionMetadata.ConvertToImmutableMetadata();
            var duration = TimeSpan.FromSeconds(1);
            var guid     = Guid.NewGuid().ToString();
            var transactionMetricName = new TransactionMetricName("WebTransaction", "Name");
            var databaseService       = new DatabaseService(Mock.Create <ICacheStatsReporter>());
            var configurationService  = Mock.Create <IConfigurationService>();
            var attribDefSvc          = new AttributeDefinitionService((f) => new AttributeDefinitions(f));

            string[] queries = { Sql,                                                                                               "Select * from someTable", "Insert x into anotherTable",             "another random string",
                                 "1234567890!@#$%^&*()",                                                                            "fjdksalfjdkla;fjdla;",    "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
                                 "NNNNNNNNNNNUUUUUUUUUUUUUUUUTTTTTTTTTTTTTTTHHHHHHHHHHHHHIIIIIIIIIIIIIIIIIIIINNNNNNNNNNNNNNNNNNNN",
                                 double.MaxValue.ToString() };
            var      sqlTraceMaker = new SqlTraceMaker(configurationService, attribDefSvc, databaseService);
            var      traceDatas    = new List <SqlTraceWireModel>();

            foreach (string query in queries)
            {
                var data    = new DatastoreSegmentData(databaseService, new ParsedSqlStatement(DatastoreVendor.MSSQL, null, null), query);
                var segment = new Segment(TransactionSegmentStateHelpers.GetItransactionSegmentState(), new MethodCallData("typeName", "methodName", 1));
                segment.SetSegmentData(data);

                var segments = new List <Segment>()
                {
                    new Segment(new TimeSpan(), TotalCallTime, segment, null)
                };
                var immutableTransaction = new ImmutableTransaction(name, segments, metadata, DateTime.Now, duration, duration, guid, false, false, false, 1.2f, false, string.Empty, null, _attribDefs);

                var sqlTraceData = sqlTraceMaker.TryGetSqlTrace(immutableTransaction, transactionMetricName, immutableTransaction.Segments.FirstOrDefault());
                traceDatas.Add(sqlTraceData);
            }

            foreach (SqlTraceWireModel traceData in traceDatas)
            {
                var numberOfDigits = Math.Floor(Math.Log10(traceData.SqlId) + 1);
                Assert.IsTrue(numberOfDigits != 9);
            }
        }
Ejemplo n.º 5
0
        public int Add_Segment_When_Segment_Count_Considers_Configuration_TransactionTracerMaxSegments(int transactionTracerMaxSegmentThreashold, int segmentCount)
        {
            Mock.Arrange(() => _configuration.TransactionTracerMaxSegments).Returns(transactionTracerMaxSegmentThreashold);

            var transactionName = TransactionName.ForWebTransaction("WebTransaction", "Test");


            var transaction = new Transaction(_configuration, transactionName, Mock.Create <ITimer>(), DateTime.UtcNow, Mock.Create <ICallStackManager>(), _databaseService, Priority, Mock.Create <IDatabaseStatementParser>(), _distributedTracePayloadHandler, _errorService, _attribDefs);

            for (int i = 0; i < segmentCount; i++)
            {
                var segment = new Segment(transaction, new MethodCallData("foo" + i, "bar" + i, 1));
                segment.SetSegmentData(new ExternalSegmentData(new Uri("http://www.test.com"), "method"));

                segment.End();
            }

            var immutableTransaction = transaction.ConvertToImmutableTransaction();

            return(immutableTransaction.Segments.Count());
        }
        private IInternalTransaction BuildTestTransaction(bool isWebTransaction = true, string uri = null, string referrerUri = null, string guid = null, int?statusCode = null, int?subStatusCode = null, string referrerCrossProcessId = null, string transactionCategory = "defaultTxCategory", string transactionName = "defaultTxName", ErrorData exceptionData = null, ErrorData customErrorData = null, bool isSynthetics = true, bool isCAT = true, bool includeUserAttributes = false)
        {
            var name = isWebTransaction
                ? TransactionName.ForWebTransaction(transactionCategory, transactionName)
                : TransactionName.ForOtherTransaction(transactionCategory, transactionName);

            var segments = Enumerable.Empty <Segment>();

            var placeholderMetadataBuilder = new TransactionMetadata();
            var placeholderMetadata        = placeholderMetadataBuilder.ConvertToImmutableMetadata();

            var attribDefSvc = new AttributeDefinitionService((f) => new AttributeDefinitions(f));

            var immutableTransaction = new ImmutableTransaction(name, segments, placeholderMetadata, DateTime.Now, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10), guid, false, false, false, 0.5f, false, string.Empty, null, attribDefSvc.AttributeDefs);

            var priority            = 0.5f;
            var internalTransaction = new Transaction(Mock.Create <IConfiguration>(), immutableTransaction.TransactionName, _timerFactory.StartNewTimer(), DateTime.UtcNow, Mock.Create <ICallStackManager>(), Mock.Create <IDatabaseService>(), priority, Mock.Create <IDatabaseStatementParser>(), Mock.Create <IDistributedTracePayloadHandler>(), _errorService, _attribDefSvc.AttributeDefs);
            var transactionMetadata = internalTransaction.TransactionMetadata;

            PopulateTransactionMetadataBuilder(transactionMetadata, uri, statusCode, subStatusCode, referrerCrossProcessId, exceptionData, customErrorData, isSynthetics, isCAT, referrerUri, includeUserAttributes);

            return(internalTransaction);
        }
Ejemplo n.º 7
0
        private IInternalTransaction BuildTestTransaction(bool isWebTransaction = true, string uri = null, string referrerUri = null, string guid = null, int?statusCode = null, int?subStatusCode = null, string referrerCrossProcessId = null, string transactionCategory = "defaultTxCategory", string transactionName = "defaultTxName", ErrorData exceptionData = null, ErrorData customErrorData = null, bool isSynthetics = true, bool isCAT = true, bool includeUserAttributes = false, float priority = 0.5f, bool sampled = false, string traceId = "traceId")
        {
            var name = isWebTransaction
                ? TransactionName.ForWebTransaction(transactionCategory, transactionName)
                : TransactionName.ForOtherTransaction(transactionCategory, transactionName);

            var segments = Enumerable.Empty <Segment>();

            var placeholderMetadataBuilder = new TransactionMetadata();
            var placeholderMetadata        = placeholderMetadataBuilder.ConvertToImmutableMetadata();

            var immutableTransaction = new ImmutableTransaction(name, segments, placeholderMetadata, DateTime.UtcNow, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10), guid, false, false, false, priority, sampled, traceId, null, _attribDefs);

            var internalTransaction = new Transaction(Mock.Create <IConfiguration>(), immutableTransaction.TransactionName, _timerFactory.StartNewTimer(), DateTime.UtcNow, Mock.Create <ICallStackManager>(), Mock.Create <IDatabaseService>(), priority, Mock.Create <IDatabaseStatementParser>(), Mock.Create <IDistributedTracePayloadHandler>(), Mock.Create <IErrorService>(), _attribDefs);

            var adaptiveSampler = Mock.Create <IAdaptiveSampler>();

            Mock.Arrange(() => adaptiveSampler.ComputeSampled(ref priority)).Returns(sampled);
            internalTransaction.SetSampled(adaptiveSampler);

            PopulateTransactionMetadataBuilder(internalTransaction, uri, statusCode, subStatusCode, referrerCrossProcessId, exceptionData, customErrorData, isSynthetics, isCAT, referrerUri, includeUserAttributes);

            return(internalTransaction);
        }