Ejemplo n.º 1
0
        public static Response Handle(NancyContext ctx, Exception exception)
        {
            var returnCode = HttpStatusCode.BadRequest;

            var respModel = new DtoResponse(exception.Message)
            {
                Data       = null,
                StatusCode = 0,
                Stack      = exception.StackTrace
            };

            if (exception.GetType() == typeof(ResponseException))
            {
                var responseEx = ((ResponseException)exception);
                returnCode           = HttpStatusCode.OK;
                respModel.StatusCode = (int)responseEx.StatusCode;

                // Por padrão pega a mensagem via StatusCode Description, do contrário usa a customizada
                if (exception.Message == "")
                {
                    respModel.Message = responseEx.StatusCode.GetDescription();
                }
            }

            if (exception.GetType() == typeof(AcademicoException))
            {
                returnCode           = HttpStatusCode.OK;
                respModel.StatusCode = 100;
            }

            var resp = new JsonResponse <DtoResponse>(respModel, new DefaultJsonSerializer())
            {
                StatusCode = returnCode
            };

            // Todas as rotas que retornam - Tentando mapear todas as transações que não possuem status de erro
            if (returnCode == HttpStatusCode.OK)
            {
                var routeDescription = ctx.ResolvedRoute.Description;
                NewRelicAgent.SetTransactionName("Custom", $"Trilhas Exception {routeDescription.Method} {routeDescription.Path}");
            }

            // Faz com que o new relic mostre mais informações sobre a pessoa que causou o erro
            if (ctx.CurrentUser != null)
            {
                var currentUser = (UserIdentity)ctx.CurrentUser;
                NewRelicAgent.AddCustomParameter("JWT_TOKEN", currentUser.JwtToken);
                NewRelicAgent.AddCustomParameter("CPF", currentUser.UserName);
                NewRelicAgent.AddCustomParameter("Nome", currentUser.Usuario.Nome);
                NewRelicAgent.AddCustomParameter("Trilha ID", $"{currentUser.Nivel.ID}");
                NewRelicAgent.AddCustomParameter("Trilha Nome", $"{currentUser.Nivel.Nome}");
            }
            NewRelicAgent.AddCustomParameter("Stack Trace", exception.StackTrace);

            resp.Headers.Add("Access-Control-Allow-Origin", "*");
            resp.Headers.Add("Access-Control-Allow-Methods", "POST,GET,PUT,DELETE");
            resp.Headers.Add("Access-Control-Allow-Headers", "Accept, Origin, Content-type, Authorization");

            return(resp);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Para que seja possível acompanhar as requisições feitas de forma separada
        /// via new relic esse método deve ser chamado a cada requisição
        /// dessa forma todos os módulos devem herdar essa classe
        /// </summary>
        public void TrackNewRelic()
        {
            Before += ctx =>
            {
                var routeDescription = ctx.ResolvedRoute.Description;
                NewRelicAgent.SetTransactionName("Custom", $"Trilhas {routeDescription.Method} {routeDescription.Path}");

                return(null);
            };
        }
        protected BaseModule(string modulePath) : base(modulePath)
        {
            TraceID = Guid.NewGuid();

            OnError += new ErrorHandler(TraceID).OnError;

            Before += ctx =>
            {
                var routeDescription = ctx.ResolvedRoute.Description;
                NewRelicAgent.SetTransactionName("Custom/Endpoint", string.Format("{0} {1}", routeDescription.Method, routeDescription.Path));

                return(null);
            };
        }
        static void app_PostMapRequestHandler(object sender, EventArgs e)
        {
            var ctx = ((HttpApplication)sender).Context;

            var handler = ctx.CurrentHandler as Page;

            if (handler == null)
            {
                return;
            }

            handler.Load += (o, args) =>
            {
                var c1Page = PageRenderer.CurrentPage;
                if (c1Page != null)
                {
                    var template = PageTemplateFacade.GetPageTemplate(c1Page.TemplateId);
                    var title    = template.Title;

                    NewRelicAgent.SetTransactionName("C1 Page", title);
                }
                else
                {
                    var adminPath   = UrlUtils.AdminRootPath;
                    var requestPath = ctx.Request.Url.LocalPath;

                    if (!requestPath.StartsWith(adminPath, StringComparison.OrdinalIgnoreCase))
                    {
                        return;
                    }

                    var newRelic = handler.Request.QueryString["newrelic"];
                    if (newRelic == null || !newRelic.Equals("true"))
                    {
                        NewRelicAgent.DisableBrowserMonitoring(true);
                    }
                }
            };
        }