Example #1
0
        private void AfterEvent(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");
            }

            var segment = agent.CastAsSegment(httpContext.Items[HttpContextActions.HttpContextSegmentKey]);

            httpContext.Items[HttpContextActions.HttpContextSegmentKey] = null;
            segment.End();

            if (eventName == "EndRequest")
            {
                HttpContextActions.TransactionShutdown(agent, httpContext);
                agent.CurrentTransaction.End();
            }
        }
Example #2
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));
        }
Example #3
0
        public AfterWrappedMethodDelegate BeforeWrappedMethod(InstrumentedMethodCall instrumentedMethodCall, IAgent agent, ITransaction transaction)
        {
            if (!HttpRuntime.UsingIntegratedPipeline)
            {
                return(Delegates.NoOp);
            }

            var httpContext = instrumentedMethodCall.MethodCall.MethodArguments.ExtractNotNullAs <HttpContext>(0);

            HttpContextActions.TransactionShutdown(agent, httpContext);

            var segment = agent.CastAsSegment(httpContext.Items[HttpContextActions.HttpContextSegmentKey] as ISegment);

            httpContext.Items[HttpContextActions.HttpContextSegmentKey]     = null;
            httpContext.Items[HttpContextActions.HttpContextSegmentTypeKey] = null;
            segment.End();
            agent.CurrentTransaction.End();

            return(Delegates.NoOp);
        }
Example #4
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;
        }