public void report(Exception e) { // Create the report and execute the request. var reporter = ReportErrorsServiceClient.Create(); // Get the project ID from the json file using (StreamReader r = new StreamReader("../../../S2TPrivateKey.json")) { string json = r.ReadToEnd(); project_id = Newtonsoft.Json.Linq.JObject.Parse(json)["project_id"].ToString(); } var projectName = new ProjectName(project_id);//construct the ProjectName object // Add a service context to the report. For more details see: // https://cloud.google.com/error-reporting/reference/rest/v1beta1/projects.events#ServiceContext ServiceContext serviceContext = new ServiceContext() { Service = "SpeechToText", Version = "0.1", }; ReportedErrorEvent errorEvent = new ReportedErrorEvent() { Message = e.ToString(), ServiceContext = serviceContext, }; reporter.ReportErrorEvent(projectName, errorEvent); }
public StackdriverUtilClass(string api) { this.api = api; this.metrics = new Dictionary <string, long>(); this.success = false; this.err_client = ReportErrorsServiceClient.Create(); }
public void ReportErrorEvent() { string projectId = _fixture.ProjectId; // Sample: ReportErrorEvent // Additional: ReportErrorEvent(*,*,*) ReportErrorsServiceClient client = ReportErrorsServiceClient.Create(); ProjectName projectName = new ProjectName(projectId); ReportedErrorEvent error = new ReportedErrorEvent { Context = new ErrorContext { ReportLocation = new SourceLocation { FilePath = "SampleApp.BusinessLogic/ComplexLogic.cs", FunctionName = "ComputeTrickyAnswer", LineNumber = 100 }, User = "******" }, // If this is a stack trace, the service will parse it. Message = "Computation failed", EventTime = Timestamp.FromDateTime(DateTime.UtcNow), ServiceContext = new ServiceContext { Service = "SampleApp", Version = "1.0.0" } }; client.ReportErrorEvent(projectName, error); // End sample }
/// <summary> /// Creates a new <see cref="EventTarget"/> instance that will report to the Stackdriver Error Reporting API. /// To use this option you must enable the Stackdriver Error Reporting API /// (https://console.cloud.google.com/apis/api/clouderrorreporting.googleapis.com/overview). /// </summary> /// <param name="errorReportingClient">The error reporting client.</param> public static EventTarget ForErrorReporting(ReportErrorsServiceClient errorReportingClient = null) { return(new EventTarget { Kind = EventTargetKind.ErrorReporting, ErrorReportingClient = errorReportingClient ?? ReportErrorsServiceClient.Create(), }); }
/// <summary> /// Creates a new <see cref="EventTarget"/> instance that will report to the Stackdriver Error Reporting API. /// To use this option you must enable the Stackdriver Error Reporting API /// (https://console.cloud.google.com/apis/api/clouderrorreporting.googleapis.com/overview). /// </summary> /// <param name="projectId">Optional if running on Google App Engine or Google Compute Engine. /// The Google Cloud Platform project ID. If running on GAE or GCE the project ID will be /// detected from the platform.</param> /// <param name="errorReportingClient">The error reporting client.</param> public static EventTarget ForErrorReporting(string projectId = null, ReportErrorsServiceClient errorReportingClient = null) { return(new EventTarget { ProjectId = CommonUtils.GetAndCheckProjectId(projectId), Kind = EventTargetKind.ErrorReporting, ErrorReportingClient = errorReportingClient ?? ReportErrorsServiceClient.Create(), }); }
/// <summary>Snippet for ReportErrorEvent</summary> public void ReportErrorEventResourceNames() { // Snippet: ReportErrorEvent(ProjectName, ReportedErrorEvent, CallSettings) // Create client ReportErrorsServiceClient reportErrorsServiceClient = ReportErrorsServiceClient.Create(); // Initialize request argument(s) ProjectName projectName = ProjectName.FromProject("[PROJECT]"); ReportedErrorEvent @event = new ReportedErrorEvent(); // Make the request ReportErrorEventResponse response = reportErrorsServiceClient.ReportErrorEvent(projectName, @event); // End snippet }
/// <summary>Snippet for ReportErrorEvent</summary> public void ReportErrorEvent() { // Snippet: ReportErrorEvent(string, ReportedErrorEvent, CallSettings) // Create client ReportErrorsServiceClient reportErrorsServiceClient = ReportErrorsServiceClient.Create(); // Initialize request argument(s) string projectName = "projects/[PROJECT]"; ReportedErrorEvent @event = new ReportedErrorEvent(); // Make the request ReportErrorEventResponse response = reportErrorsServiceClient.ReportErrorEvent(projectName, @event); // End snippet }
public async Task ReportErrorEventAsync() { // Snippet: ReportErrorEventAsync(string,ReportedErrorEvent,CallSettings) // Additional: ReportErrorEventAsync(string,ReportedErrorEvent,CancellationToken) // Create client ReportErrorsServiceClient reportErrorsServiceClient = ReportErrorsServiceClient.Create(); // Initialize request argument(s) string formattedProjectName = ReportErrorsServiceClient.FormatProjectName("[PROJECT]"); ReportedErrorEvent @event = new ReportedErrorEvent(); // Make the request ReportErrorEventResponse response = await reportErrorsServiceClient.ReportErrorEventAsync(formattedProjectName, @event); // End snippet }
/// <summary>Snippet for ReportErrorEvent</summary> public void ReportErrorEventRequestObject() { // Snippet: ReportErrorEvent(ReportErrorEventRequest, CallSettings) // Create client ReportErrorsServiceClient reportErrorsServiceClient = ReportErrorsServiceClient.Create(); // Initialize request argument(s) ReportErrorEventRequest request = new ReportErrorEventRequest { ProjectNameAsProjectName = ProjectName.FromProject("[PROJECT]"), Event = new ReportedErrorEvent(), }; // Make the request ReportErrorEventResponse response = reportErrorsServiceClient.ReportErrorEvent(request); // End snippet }
public CloudErrorReportingServices(IConfiguration configuration) { this.configuration = configuration; var helper = new CloudErrorReportingHelper(configuration); googleCredential = helper.GetGoogleCredential(); channel = new Channel( ReportErrorsServiceClient.DefaultEndpoint.Host, ReportErrorsServiceClient.DefaultEndpoint.Port, googleCredential.ToChannelCredentials() ); client = ReportErrorsServiceClient.Create(channel); projectId = helper.GetProjectId(); }
public static int Main(string[] args) { // Read projectId from args if (args.Length != 1) { Console.WriteLine("Usage: Project ID must be passed as first argument."); Console.WriteLine(); return(1); } string projectId = args[0]; // Create client ReportErrorsServiceClient client = ReportErrorsServiceClient.Create(); // Initialize request argument(s) ProjectName projectName = new ProjectName(projectId); ReportedErrorEvent @event = new ReportedErrorEvent { Message = "[MESSAGE]", ServiceContext = new ServiceContext { Service = "[SERVICE]", }, Context = new ErrorContext { ReportLocation = new SourceLocation { FilePath = "path/to/file.lang", LineNumber = 42, FunctionName = "meaningOfLife", }, }, }; // Call API method ReportErrorEventResponse response = client.ReportErrorEvent(projectName, @event); // Show the result Console.WriteLine(response); // Success Console.WriteLine("Smoke test passed OK"); return(0); }
public ErrorReportingClient(String serviceName, String serviceVersion) { var googleProjectId = Environment.GetEnvironmentVariable(_googleProjectEnvironmentVariableName); if (String.IsNullOrWhiteSpace(googleProjectId)) { throw new ArgumentNullException($"Environment variable was not found: \"{_googleProjectEnvironmentVariableName}\"!"); } var googleApplicationCredentialsPath = Environment.GetEnvironmentVariable(_googleApplicationCredentialsEnvironmentVariableName); if (String.IsNullOrWhiteSpace(googleApplicationCredentialsPath)) { throw new ArgumentNullException($"Environment variable was not found: \"{_googleApplicationCredentialsEnvironmentVariableName}\"!"); } _projectName = new ProjectName(googleProjectId); _serviceName = serviceName; _serviceVersion = serviceVersion; _client = ReportErrorsServiceClient.Create(); }
/// <summary> /// Report an exception to the Error Reporting service. /// </summary> private static void report(Exception e) { // Create the report and execute the request. var reporter = ReportErrorsServiceClient.Create(); // Get the project ID from the environement variables. var projectName = new ProjectName( Environment.GetEnvironmentVariable("GOOGLE_PROJECT_ID")); // Add a service context to the report. For more details see: // https://cloud.google.com/error-reporting/reference/rest/v1beta1/projects.events#ServiceContext ServiceContext serviceContext = new ServiceContext() { Service = "myapp", Version = "1.1", }; ReportedErrorEvent errorEvent = new ReportedErrorEvent() { Message = e.ToString(), ServiceContext = serviceContext, }; reporter.ReportErrorEvent(projectName, errorEvent); }
/// <summary> /// Creates an instance of <see cref="CloudErrorReportingExceptionLogger"/> using credentials as /// defined by <see cref="GoogleCredential.GetApplicationDefaultAsync"/>. /// </summary> /// <param name="projectId">The Google Cloud Platform project ID.</param> /// <param name="serviceName">An identifier of the service, such as the name of the executable or job.</param> /// <param name="version">Represents the source code version that the developer provided.</param> public static CloudErrorReportingExceptionLogger Create(string projectId, string serviceName, string version) => new CloudErrorReportingExceptionLogger(ReportErrorsServiceClient.Create(), projectId, serviceName, version);