Beispiel #1
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);

            var transactionMetadata = internalTransaction.TransactionMetadata;

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

            return(internalTransaction);
        }
        /// <summary> Set the name of the current transaction. Supports web applications only. </summary>
        ///
        /// <exception cref="ArgumentNullException"> Thrown when <paramref name="key"/> is null. </exception>
        ///
        /// <param name="category"> The category of this transaction, used to distinguish different types
        /// of transactions. Only the first 1000 characters are retained.  If null is passed, the
        /// category defaults to "Custom". </param>
        /// <param name="name">	    The name of the transaction starting with a forward slash.  example:
        /// /store/order Only the first 1000 characters are retained. </param>
        public void SetTransactionName(string category, string name)

        {
            name = name ?? throw new ArgumentNullException(nameof(name));

            using (new IgnoreWork())
            {
                // Default to "Custom" category if none provided
                if (string.IsNullOrEmpty(category?.Trim()))
                {
                    category = MetricNames.Custom;
                }

                // Get rid of any slashes
                category = category.Trim(TrimPathChar);
                name     = name.Trim(TrimPathChar);

                // Clamp the category and name to a predetermined length
                category = Clamper.ClampLength(category);
                name     = Clamper.ClampLength(name);

                var transaction = GetCurrentInternalTransaction();

                var currentTransactionName = transaction.CandidateTransactionName.CurrentTransactionName;

                var newTransactionName = currentTransactionName.IsWeb
                    ? TransactionName.ForWebTransaction(category, name)
                    : TransactionName.ForOtherTransaction(category, name);

                transaction.CandidateTransactionName.TrySet(newTransactionName, TransactionNamePriority.UserTransactionName);
            }
        }
        public void BuiltTransactionName_BuildsOtherTransactionMetricName_IfOtherTransactionName()
        {
            var transactionName = TransactionName.ForOtherTransaction("foo", "bar");

            var builtName = _transactionMetricNameMaker.GetTransactionMetricName(transactionName);

            Assert.IsFalse(builtName.ShouldIgnore);
            Assert.AreEqual("OtherTransaction/foo/bar", builtName.PrefixedName);
        }
        public static IInternalTransaction CreateDefaultTransaction(bool isWebTransaction          = true, string uri     = null,
                                                                    string guid                    = null, int?statusCode = null, int?subStatusCode = null, string referrerCrossProcessId = null,
                                                                    string transactionCategory     = "defaultTxCategory", string transactionName = "defaultTxName", bool addSegment = true,
                                                                    IEnumerable <Segment> segments = null, bool sampled = false, IConfigurationService configurationService         = null, Exception exception = null)
        {
            var name = isWebTransaction
                ? TransactionName.ForWebTransaction(transactionCategory, transactionName)
                : TransactionName.ForOtherTransaction(transactionCategory, transactionName);

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

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

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

            var configuration = configurationService?.Configuration ?? GetDefaultConfiguration();
            var errorService  = configurationService != null ? new ErrorService(configurationService) : new ErrorService(Mock.Create <IConfigurationService>());

            var internalTransaction = new Transaction(configuration, immutableTransaction.TransactionName, Mock.Create <ITimer>(), DateTime.UtcNow, Mock.Create <ICallStackManager>(),
                                                      _databaseService, priority, Mock.Create <IDatabaseStatementParser>(), Mock.Create <IDistributedTracePayloadHandler>(),
                                                      errorService, _attribDefSvc.AttributeDefs);

            if (exception != null)
            {
                internalTransaction.NoticeError(exception);
            }

            if (segments.Any())
            {
                foreach (var segment in segments)
                {
                    internalTransaction.Add(segment);
                }
            }
            else if (addSegment)
            {
                internalTransaction.Add(SimpleSegmentDataTests.createSimpleSegmentBuilder(TimeSpan.Zero, TimeSpan.Zero, 0, null, new MethodCallData("typeName", "methodName", 1), Enumerable.Empty <KeyValuePair <string, object> >(), "MyMockedRootNode", false));
            }

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

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

            PopulateTransactionMetadataBuilder(transactionMetadata, errorService, uri, statusCode, subStatusCode, referrerCrossProcessId);

            return(internalTransaction);
        }
Beispiel #5
0
        public ITransaction CreateTransaction(bool isWeb, string category, string transactionDisplayName, bool doNotTrackAsUnitOfWork, Action wrapperOnCreate)
        {
            if (transactionDisplayName == null)
            {
                throw new ArgumentNullException("transactionDisplayName");
            }

            if (category == null)
            {
                throw new ArgumentNullException("category");
            }

            var initialTransactionName = isWeb
                ? TransactionName.ForWebTransaction(category, transactionDisplayName)
                : TransactionName.ForOtherTransaction(category, transactionDisplayName);

            return(CreateTransaction(initialTransactionName, doNotTrackAsUnitOfWork, wrapperOnCreate ?? NoOpWrapperOnCreate));
        }