예제 #1
0
        private void HandleHostError(Microsoft.Azure.WebJobs.Extensions.TraceFilter traceFilter)
        {
            foreach (TraceEvent traceEvent in traceFilter.Events)
            {
                if (traceEvent.Exception is FunctionInvocationException)
                {
                    // For all function invocation events, we notify the invoker so it can
                    // log the error as needed to its function specific logs.
                    FunctionInvocationException invocationException = traceEvent.Exception as FunctionInvocationException;
                    NotifyInvoker(invocationException.MethodName, invocationException);
                }
                else if (traceEvent.Exception is FunctionIndexingException)
                {
                    // For all startup time indexing errors, we accumulate them per function
                    FunctionIndexingException indexingException = traceEvent.Exception as FunctionIndexingException;
                    string formattedError = Utility.FlattenException(indexingException);
                    AddFunctionError(indexingException.MethodName, formattedError);

                    // Also notify the invoker so the error can also be written to the function
                    // log file
                    NotifyInvoker(indexingException.MethodName, indexingException);

                    // Mark the error as handled so indexing will continue
                    indexingException.Handled = true;
                }
            }
        }
예제 #2
0
 private void HandleHostError(Microsoft.Azure.WebJobs.Extensions.TraceFilter traceFilter)
 {
     foreach (TraceEvent traceEvent in traceFilter.Events)
     {
         HandleHostError(traceEvent.Exception);
     }
 }
        private void HandleHostError(Microsoft.Azure.WebJobs.Extensions.TraceFilter traceFilter)
        {
            // TODO: figure out why sometimes we get null events
            var events = traceFilter.Events.Where(p => p != null).ToArray();

            foreach (TraceEvent traceEvent in events)
            {
                var exception = traceEvent.Exception ?? new InvalidOperationException(traceEvent.Message);
                HandleHostError(exception);
            }
        }
        /// <summary>
        /// Add the specified filter function to this <see cref="TraceMonitor"/>.
        /// </summary>
        /// <param name="predicate">The filter predicate.</param>
        /// <param name="message">The optional subscription notification message to use.</param>
        /// <returns>This <see cref="TraceMonitor"/> instance.</returns>
        public TraceMonitor Filter(Func <TraceEvent, bool> predicate, string message = null)
        {
            if (predicate == null)
            {
                throw new ArgumentNullException("predicate");
            }

            Filters.Add(TraceFilter.Create(predicate, message));

            return(this);
        }
        /// <summary>
        /// Send an email notification using SendGrid.
        /// </summary>
        /// <param name="filter">The <see cref="TraceFilter"/> that triggered the notification.</param>
        public void EmailNotify(TraceFilter filter)
        {
            SendGridMessage message = new SendGridMessage()
            {
                From = _sendGridConfig.FromAddress,
                Subject = "WebJob Error Notification",
                Text = filter.GetDetailedMessage(5)
            };
            message.AddTo(_sendGridConfig.ToAddress);

            _sendGrid.DeliverAsync(message);
        }
        /// <summary>
        /// Notify all subscribers that the specified filter has has triggered
        /// a notification.
        /// </summary>
        protected virtual void Notify(TraceFilter filter)
        {
            // Throttle notifications if requested
            bool shouldNotify = NotificationThrottle == null ||
                                (DateTime.Now - _lastNotification) > NotificationThrottle;

            if (shouldNotify)
            {
                foreach (var subscription in Subscriptions)
                {
                    subscription(filter);
                }
                _lastNotification = DateTime.Now;
            }
        }
        /// <summary>
        /// Send a WebHook request to an IFTTT WebHook event that can be configured
        /// to send an SMS message, etc.
        /// </summary>
        /// <remarks>
        /// Using IFTTT is free, and by sending a WebHook request on an event,
        /// you can use any of the many other notification mechanisms they support
        /// (email, SMS, etc.) See IFTTT Maker Channel documentation here: http://ifttt.com/maker.
        /// </remarks>
        /// <param name="filter">The <see cref="TraceFilter"/> that triggered the notification.</param>
        public void WebNotify(TraceFilter filter)
        {
            if (string.IsNullOrEmpty(_webNotificationUri))
            {
                return;
            }

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, _webNotificationUri);

            // Send some event detail data along to the IFTTT recipe.
            string json = string.Format("{{ \"value1\": \"{0}\" }}", filter.Message);
            request.Content = new StringContent(json);
            request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            _httpClient.SendAsync(request).Wait();
        }