예제 #1
0
        private ITransaction TryCreateTransaction(IAgent agent, HttpContext httpContext, string requestNotification)
        {
            // MapRequestHandler is always called so if we make it past that without having already started a transaction then don't start one since we already missed too much.  This is likely to occur during startup when the transaction service spins up half way through a request.
            var earlyEnoughInTransactionLifecycleToCreate = Statics.PossibleEvents
                                                            .TakeWhile(@event => @event != "AcquireRequestState")
                                                            .Where(@event => @event == requestNotification)
                                                            .Any();

            if (!earlyEnoughInTransactionLifecycleToCreate)
            {
                return(agent.CurrentTransaction);
            }

            Action onCreate = () =>
            {
                HttpContextActions.TransactionStartup(agent, httpContext);
            };

            return(agent.CreateTransaction(
                       isWeb: true,
                       category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.ASP),
                       transactionDisplayName: "Integrated Pipeline",
                       doNotTrackAsUnitOfWork: true,
                       wrapperOnCreate: onCreate));
        }
예제 #2
0
        private void BeforeEvent(MethodCall methodCall, IAgent agent, string eventName, HttpApplication httpApplication)
        {
            if (httpApplication == null)
            {
                throw new ArgumentNullException("httpApplication");
            }

            var httpContext = httpApplication.Context;

            if (httpContext == null)
            {
                throw new NullReferenceException("httpApplication.Context");
            }

            ITransaction transaction;

            if (eventName == "BeginRequest")
            {
                Action onCreate = () =>
                {
                    HttpContextActions.TransactionStartup(agent, httpContext);
                };

                transaction = agent.CreateTransaction(
                    isWeb: true,
                    category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.ASP),
                    transactionDisplayName: "Classic Pipeline",
                    doNotTrackAsUnitOfWork: true,
                    wrapperOnCreate: onCreate);
            }
            else
            {
                transaction = agent.CurrentTransaction;
            }

            var segment = transaction.StartTransactionSegment(methodCall, eventName);

            httpContext.Items[HttpContextActions.HttpContextSegmentKey] = segment;
        }