/// <summary> /// Submits an exception as a fault to the ESB Exception database /// </summary> /// <remarks> /// The majority of the properties populated in the fault are needed for the WCF-generated /// fault to look the same as an ESB-generated fault, as null values are allowed in the /// database, but will prevent records showing in the ESB management portal. /// </remarks> /// <param name="serviceProviderName">Name of the service provider</param> /// <param name="serviceName">Name of the service submitting the fault</param> /// <param name="faultDescription">Description or fault/error message</param> /// <param name="severity">Severity of fault</param> /// <param name="ex">Exception that was caught</param> public static void SubmitFault(string serviceProviderName, string serviceName, string faultDescription, FaultSeverity severity, Exception ex) { DateTime now = DateTime.Now; //populate the header: FaultMessageHeader header = new FaultMessageHeader(); header.DateTime = now.ToString(); header.MachineName = Environment.MachineName; header.Application = ServiceProviderErrorHandlerConfiguration.Current.BizTalkApplication; header.ServiceName = string.Format("{0}.{1}", serviceProviderName, serviceName); header.ErrorType = ServiceProviderErrorHandlerConfiguration.Current.ErrorType; header.FailureCategory = ServiceProviderErrorHandlerConfiguration.Current.FailureCategory; header.FaultCode = ServiceProviderErrorHandlerConfiguration.Current.FaultCode; header.FaultSeverity = (int)severity; header.FaultDescription = faultDescription; header.FaultGenerator = ServiceProviderErrorHandlerConfiguration.Current.FaultGeneratorName; header.Description = string.Format("Fault occurred in provider: {0}, processing service: {1}", serviceProviderName, serviceName); header.MessageID = GetDeterministicGuid("{0}_{1}_{2}", serviceProviderName, serviceName, now.Ticks).ToString(); header.ActivityIdentity = GetDeterministicGuid("{0}_{1}", serviceProviderName, serviceName).ToString(); header.ServiceInstanceID = GetDeterministicGuid(serviceProviderName).ToString(); //OperationContext is thread static, no may be null if call from child threads: if (OperationContext.Current == null) { header.Scope = "Worker thread"; } else { header.Scope = OperationContext.Current.EndpointDispatcher.EndpointAddress.Uri.AbsoluteUri; } //populate exception details: FaultMessageExceptionObject faultException = new FaultMessageExceptionObject(); faultException.Source = ex.Source; faultException.StackTrace = ex.StackTrace; faultException.Message = ex.Message; faultException.Type = ex.GetType().FullName; if (ex.TargetSite != null) { faultException.TargetSite = ex.TargetSite.ToString(); } if (ex.InnerException != null) { faultException.InnerExceptionMessage = ex.InnerException.Message; } else { //ESB uses the fault code here: faultException.InnerExceptionMessage = ServiceProviderErrorHandlerConfiguration.Current.FaultCode; } FaultMessage message = new FaultMessage(); message.Header = header; message.ExceptionObject = faultException; SubmitFault(message); }
/// <summary> /// Create a FaultEvent. /// The pattern: /// 1. FEvent = new FaultEvent(...) /// 2. tsession.PostEvent(FEvent) //posts the event to Watson and AI /// External users should call the TelemetrySession extension methods "PostFault" (which calls PostEvent) /// It becomes more useful when correlated with <see cref="T:Coding4Fun.VisualStudio.Telemetry.UserTaskEvent" /> or <see cref="T:Coding4Fun.VisualStudio.Telemetry.OperationEvent" /> which may have led to the fault occurence. /// </summary> /// <param name="eventName"> /// An event name following data model schema. /// It requires that event name is a unique, not null or empty string. /// It consists of 3 parts and must follows pattern [product]/[featureName]/[entityName]. FeatureName could be a one-level feature or feature hierarchy delimited by "/". /// For examples, /// vs/platform/opensolution; /// vs/platform/editor/lightbulb/fixerror; /// </param> /// <param name="description"></param> /// <param name="faultSeverity">The severity of the fault, used to identify actionable or important faults in divisional tools and reporting.</param> /// <param name="exceptionObject"></param> /// <param name="gatherEventDetails">This delegate is called to gather expensive details (like jscript call stacks) only when not sampled. /// The callback parameter can be cast to to a FaultEvent or (IVsFaultEvent in native) which inherits from TelemetryEvent (IVsTelemetryEvent in native) /// <seealso cref="T:Coding4Fun.VisualStudio.Telemetry.IFaultUtility" /> /// </param> public FaultEvent(string eventName, string description, FaultSeverity faultSeverity, Exception exceptionObject = null, Func <IFaultUtility, int> gatherEventDetails = null) : base(eventName, TelemetrySeverity.High, DataModelEventType.Fault) { Description = (description ?? string.Empty); ExceptionObject = exceptionObject; GatherEventDetails = gatherEventDetails; FaultSeverity = faultSeverity; UserOptInToWatson = FaultEventWatsonOptIn.Unspecified; DataModelEventNameHelper.SetProductFeatureEntityName(this); }
public TelemetryEventCorrelation PostFault(string eventName, string description, FaultSeverity faultSeverity, Exception exceptionObject) { #if DEBUG _ = WriteLineToOutputWindowAsync($"Exception: '{eventName}'"); _ = WriteLineToOutputWindowAsync($" {description}"); _ = WriteLineToOutputWindowAsync($" {Enum.GetName(typeof(FaultSeverity), faultSeverity)}"); _ = WriteLineToOutputWindowAsync($" {exceptionObject}"); #endif return(_session.PostFault(eventName, description, faultSeverity, exceptionObject)); }
/// <summary> /// Post a fault event with an exception object and a callback. The callback can be used to calculate expensive data to be sent /// to the Watson back end, such as JScript callstacks, etc /// It becomes more useful when correlated with <see cref="T:Coding4Fun.VisualStudio.Telemetry.UserTaskEvent" /> or <see cref="T:Coding4Fun.VisualStudio.Telemetry.OperationEvent" /> which may have led to the fault occurence. /// </summary> /// <param name="telemetrySession"></param> /// <param name="eventName"> /// An event name following data model schema. /// It requires that event name is a unique, not null or empty string. /// It consists of 3 parts and must follows pattern [product]/[featureName]/[entityName]. FeatureName could be a one-level feature or feature hierarchy delimited by "/". /// For examples, /// vs/platform/opensolution; /// vs/platform/editor/lightbulb/fixerror; /// </param> /// <param name="description"></param> /// <param name="faultSeverity">The severity of the fault, used to identify actionable or important faults in divisional tools and reporting.</param> /// <param name="exceptionObject">can be null</param> /// <param name="gatherEventDetails">Allows the user to provide code to execute synchronously to gather computationally expensive info about the event</param> /// <param name="correlatedWith"> /// Specify which events to correlate by using property <see cref="P:Coding4Fun.VisualStudio.Telemetry.TelemetryEvent.Correlation" /> /// Good candidates to correlate with <see cref="T:Coding4Fun.VisualStudio.Telemetry.FaultEvent" /> are, /// <see cref="T:Coding4Fun.VisualStudio.Telemetry.UserTaskEvent" /> /// <see cref="T:Coding4Fun.VisualStudio.Telemetry.OperationEvent" /> /// </param> /// <returns>The fault correlation.</returns> public static TelemetryEventCorrelation PostFault(this TelemetrySession telemetrySession, string eventName, string description, FaultSeverity faultSeverity, Exception exceptionObject, Func <IFaultUtility, int> gatherEventDetails, TelemetryEventCorrelation[] correlatedWith) { FaultEvent faultEvent = new FaultEvent(eventName, description, faultSeverity, exceptionObject, gatherEventDetails); faultEvent.Correlate(correlatedWith); telemetrySession.PostEvent(faultEvent); return(faultEvent.Correlation); }
/// <summary> /// Post a fault event with an exception object and a callback. The callback can be used to calculate expensive data to be sent /// to the Watson back end, such as JScript callstacks, etc /// It becomes more useful when correlated with <see cref="T:Coding4Fun.VisualStudio.Telemetry.UserTaskEvent" /> or <see cref="T:Coding4Fun.VisualStudio.Telemetry.OperationEvent" /> which may have led to the fault occurence. /// </summary> /// <param name="telemetrySession"></param> /// <param name="eventName"> /// An event name following data model schema. /// It requires that event name is a unique, not null or empty string. /// It consists of 3 parts and must follows pattern [product]/[featureName]/[entityName]. FeatureName could be a one-level feature or feature hierarchy delimited by "/". /// For examples, /// vs/platform/opensolution; /// vs/platform/editor/lightbulb/fixerror; /// </param> /// <param name="description"></param> /// <param name="faultSeverity">The severity of the fault, used to identify actionable or important faults in divisional tools and reporting.</param> /// <param name="exceptionObject">can be null</param> /// <param name="gatherEventDetails">Allows the user to provide code to execute synchronously to gather computationally expensive info about the event</param> /// <returns>The fault correlation.</returns> public static TelemetryEventCorrelation PostFault(this TelemetrySession telemetrySession, string eventName, string description, FaultSeverity faultSeverity, Exception exceptionObject, Func <IFaultUtility, int> gatherEventDetails) { return(telemetrySession.PostFault(eventName, description, faultSeverity, exceptionObject, gatherEventDetails, null)); }
/// <summary> /// Post a Fault Event with a managed Exception object. The bucket parameters are created from the exception object. /// It becomes more useful when correlated with <see cref="T:Coding4Fun.VisualStudio.Telemetry.UserTaskEvent" /> or <see cref="T:Coding4Fun.VisualStudio.Telemetry.OperationEvent" /> which may have led to the fault occurence. /// </summary> /// <param name="telemetrySession"></param> /// <param name="eventName"> /// An event name following data model schema. /// It requires that event name is a unique, not null or empty string. /// It consists of 3 parts and must follows pattern [product]/[featureName]/[entityName]. FeatureName could be a one-level feature or feature hierarchy delimited by "/". /// For examples, /// vs/platform/opensolution; /// vs/platform/editor/lightbulb/fixerror; /// </param> /// <param name="description"></param> /// <param name="faultSeverity">The severity of the fault, used to identify actionable or important faults in divisional tools and reporting.</param> /// <param name="exceptionObject"></param> /// <returns>The fault event correlation.</returns> public static TelemetryEventCorrelation PostFault(this TelemetrySession telemetrySession, string eventName, string description, FaultSeverity faultSeverity, Exception exceptionObject) { return(telemetrySession.PostFault(eventName, description, faultSeverity, exceptionObject, null)); }