Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Sie haben zwei Möglichkeiten, Fehler von Ihren Google Kubernetes Engine-Anwendungen an Error Reporting zu senden:
Durch Logging in Cloud Logging: Wenn Sie Cloud Logging bereits verwenden, besteht die einzige zusätzliche Anforderung darin, dass Ihre Logeinträge von Error Reporting erkannt werden müssen. Weitere Informationen zu den Anforderungen an die Fehlerformatierung finden Sie unter Fehler in Cloud Logging formatieren.
Durch Verwendung der Error Reporting API: Ihre Anwendung kann HTTP-Anfragen über die REST API senden oder experimentelle Bibliotheken in mehreren Sprachen verwenden.
Logging zum Melden von Fehlern verwenden
Der Standard-Logging-Agent von GKE bietet eine verwaltete Lösung zum Bereitstellen und Verwalten von Agents, die Logs für Ihre Cluster an Cloud Logging senden. Die Struktur des Agents hängt von der Version des Clusters ab. Weitere Informationen zu diesem Agent finden Sie unter GKE-Logs verwalten.
Für Error Reporting müssen Ausnahmen oder Stacktraces in einem einzelnen Logeintrag enthalten sein. Die meisten Logging-Agents können erkennen, dass mehrere Logzeilen – Stackframes, die jeweils in einer neuen Zeile ausgegeben werden – einen Stacktrace darstellen, und senden ihn als einzelnen Logeintrag an Cloud Logging.
Wenn der Agent nicht in der Lage ist, mehrere Zeilen als einen einzelnen Fehler zu rekonstruieren, verwenden Sie den projects.events.report-API-Endpunkt, mit dem Sie den Inhalt eines Fehlers steuern können.
Error Reporting-API zum Beschreiben von Fehlern verwenden
Die Error Reporting API bietet einen report-Endpunkt zum Schreiben von Fehlerinformationen in den Dienst.
Das ASP.NET-NuGet-Paket meldet nicht erfasste Ausnahmen von ASP.NET-Webanwendungen an Error Reporting.
NuGet-Paket installieren
So installieren Sie das Stackdriver-ASP.NET-NuGet-Paket in Visual Studio:
Klicken Sie mit der rechten Maustaste auf Ihre Lösung und wählen Sie NuGet-Pakete für Lösung verwalten aus.
Wählen Sie das Kästchen Vorabversion einbeziehen aus.
Suchen Sie nach dem Paket mit dem Namen Google.Cloud.Diagnostics.AspNet und installieren Sie es.
Nutzung
Nachdem Sie das Stackdriver-ASP.NET-NuGet-Paket installiert haben, können Sie
die folgende Anweisung zu Ihrem Anwendungscode hinzufügen und Fehler an
Stackdriver senden:
using Google.Cloud.Diagnostics.AspNet;
Fügen Sie den folgenden HttpConfiguration-Code in die Methode Register Ihrer .NET-Webanwendung ein. Ersetzen Sie dabei your-project-id durch Ihre tatsächliche Projekt-ID, um das Melden von Ausnahmen zu aktivieren:
publicstaticvoidRegister(HttpConfigurationconfig){stringprojectId="YOUR-PROJECT-ID";stringserviceName="NAME-OF-YOUR-SERVICE";stringversion="VERSION-OF-YOUR-SERVCICE";// ...// Add a catch all for the uncaught exceptions.config.Services.Add(typeof(IExceptionLogger),ErrorReportingExceptionLogger.Create(projectId,serviceName,version));// ...}
Nachdem Sie Ihrer ASP.NET-Anwendung diese Methode hinzugefügt haben, können Sie alle nicht erfassten Ausnahmen in der Google Cloud -Konsole aufrufen, da sie an Google Cloudgemeldet und dort im Bereich Error Reporting angezeigt werden.
Ersetzen Sie [YOUR_PROJECT_ID] durch den korrekten Wert aus derGoogle Cloud -Konsole.
Senden Sie dann Ausnahmedaten mit Code ähnlich dem folgenden:
publicclassErrorReportingSample{publicstaticvoidMain(string[]args){try{thrownewException("Generic exception for testing Stackdriver Error Reporting");}catch(Exceptione){report(e);Console.WriteLine("Stackdriver Error Report Sent");}}/// <summary>/// Create the Error Reporting service (<seealso cref="ClouderrorreportingService"/>)/// with the Application Default Credentials and the proper scopes./// See: https://developers.google.com/identity/protocols/application-default-credentials./// </summary>privatestaticClouderrorreportingServiceCreateErrorReportingClient(){// Get the Application Default Credentials.GoogleCredentialcredential=GoogleCredential.GetApplicationDefaultAsync().Result;// Add the needed scope to the credentials.credential.CreateScoped(ClouderrorreportingService.Scope.CloudPlatform);// Create the Error Reporting Service.ClouderrorreportingServiceservice=newClouderrorreportingService(newBaseClientService.Initializer{HttpClientInitializer=credential,});returnservice;}/// <summary>/// Creates a <seealso cref="ReportRequest"/> from a given exception./// </summary>privatestaticReportRequestCreateReportRequest(Exceptione){// Create the service.ClouderrorreportingServiceservice=CreateErrorReportingClient();// Get the project ID from the environement variables.stringprojectId=Environment.GetEnvironmentVariable("GOOGLE_PROJECT_ID");// Format the project id to the format Error Reporting expects. See:// https://cloud.google.com/error-reporting/reference/rest/v1beta1/projects.events/reportstringformattedProjectId=string.Format("projects/{0}",projectId);// Add a service context to the report. For more details see:// https://cloud.google.com/error-reporting/reference/rest/v1beta1/projects.events#ServiceContextServiceContextserviceContext=newServiceContext(){Service="myapp",Version="8c1917a9eca3475b5a3686d1d44b52908463b989",};ReportedErrorEventerrorEvent=newReportedErrorEvent(){Message=e.ToString(),ServiceContext=serviceContext,};returnnewReportRequest(service,errorEvent,formattedProjectId);}/// <summary>/// Report an exception to the Error Reporting service./// </summary>privatestaticvoidreport(Exceptione){// Create the report and execute the request.ReportRequestrequest=CreateReportRequest(e);request.Execute();}}
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-08-11 (UTC)."],[[["\u003cp\u003eGKE applications can send errors to Error Reporting through Cloud Logging or by using the Error Reporting API.\u003c/p\u003e\n"],["\u003cp\u003eWhen using Cloud Logging, ensure that log entries containing exceptions or stack traces are formatted as single log entries for proper recognition by Error Reporting.\u003c/p\u003e\n"],["\u003cp\u003eThe Error Reporting API allows error reporting via REST API calls or through experimental client libraries available in various languages such as ASP.NET, Go, Java, Node.js, Ruby, Python, and PHP.\u003c/p\u003e\n"],["\u003cp\u003eThe Error Reporting API provides a \u003ccode\u003ereport\u003c/code\u003e endpoint, and client libraries such as the ASP.NET NuGet package, include specific setup instructions within their documentation to integrate with the service.\u003c/p\u003e\n"],["\u003cp\u003eThe Error Reporting page in the Google Cloud console allows users to view reported error groups and requires prior setup to function properly.\u003c/p\u003e\n"]]],[],null,["# Setting up on Google Kubernetes Engine\n\nYou can send errors from your Google Kubernetes Engine applications to\nError Reporting in one of two ways:\n\n- [By logging to Cloud Logging](#using_logging). If you're already using\n Cloud Logging, the only additional requirement is that your log entries be\n recognizable by Error Reporting. For more information\n on error formatting requirements, read\n [Formatting errors in Cloud Logging](/error-reporting/docs/formatting-error-messages).\n\n- [Using the Error Reporting API](#using_the_api). Your application\n can send HTTP requests using the REST API, or can make use of\n experimental libraries in several languages.\n\nUsing Logging to report errors\n------------------------------\n\nGKE's default logging agent provides a managed solution to\ndeploy and manage the agents that send the logs for your clusters to\nCloud Logging. The structure of the agent depends on the version of the\ncluster. For information about this agent, see\n[Managing GKE logs](/stackdriver/docs/solutions/gke/managing-logs).\n\nError Reporting requires that exceptions or stack traces be contained\nin a single log entry. Most logging agents are capable of recognizing that\nseveral log lines---stack frames printed each on a new line---represent\na stack trace and send it to Cloud Logging as a single log entry.\nIf the agent isn't capable of reconstructing multiple lines as a single error,\nthen use the\n[`projects.events.report` API endpoint](/error-reporting/reference/rest/v1beta1/projects.events/report),\nwhich allows you to control the contents of an error.\n\nUsing the Error Reporting API to write errors\n---------------------------------------------\n\nThe Error Reporting API provides a `report` endpoint for writing\nerror information to the service.\n\n1.\n\n\n Enable the Error Reporting API.\n\n\n [Enable the API](https://console.cloud.google.com/flows/enableapi?apiid=clouderrorreporting.googleapis.com)\n\n \u003cbr /\u003e\n\n2. Report errors to the API using either the REST API or a client library.\n\n - REST API\n\n See the\n [reference documentation](/error-reporting/reference/rest/v1beta1/projects.events/report)\n for information about the API.\n - Using client libraries\n\n Libraries exist in a limited number of languages to help you call\n the Error Reporting API from your application:\n - [ASP.NET](/error-reporting/docs/setup/dotnet)\n - [Go](/error-reporting/docs/setup/go)\n - [Java](/error-reporting/docs/setup/java)\n - [Node.js](/error-reporting/docs/setup/nodejs)\n - [Ruby](/error-reporting/docs/setup/ruby)\n - [Python](/error-reporting/docs/setup/python)\n - [PHP](/error-reporting/docs/setup/php)\n\n### Samples\n\n### ASP.NET\n\nThe ASP.NET NuGet package reports uncaught exceptions from\nASP.NET web applications to Error Reporting.\n\n### Install the NuGet package\n\nTo install the Stackdriver ASP.NET NuGet package in Visual Studio:\n\n1. Right-click your solution and select **Manage NuGet packages for\n solution**.\n2. Select the **Include prerelease** checkbox.\n3. Search for and install the package named `Google.Cloud.Diagnostics.AspNet`.\n\n### Usage\n\nOnce you've installed the Stackdriver ASP.NET NuGet package, add the\nfollowing statement to your application code to start sending errors to\nStackdriver: \n\n using Google.Cloud.Diagnostics.AspNet;\n\nAdd the following `HttpConfiguration` code to the `Register` method of your\n.NET web app (replacing `your-project-id` with your actual\n[project ID](https://support.google.com/cloud/answer/6158840?hl=en)\nto enable the reporting of exceptions: \n\n public static void Register(HttpConfiguration config)\n {\n string projectId = \"YOUR-PROJECT-ID\";\n string serviceName = \"NAME-OF-YOUR-SERVICE\";\n string version = \"VERSION-OF-YOUR-SERVCICE\";\n // ...\n // Add a catch all for the uncaught exceptions.\n config.Services.Add(typeof(IExceptionLogger),\n ErrorReportingExceptionLogger.Create(projectId, serviceName, version));\n // ...\n }\n\nOnce you've added this method to your ASP.NET application, you can view any\nuncaught exceptions that occur as they get reported to Google Cloud\nin the [Error Reporting](https://console.cloud.google.com/errors)\nsection of the Google Cloud console.\n\n### C#\n\nThe following example can be found in the\n[GoogleCloudPlatform/dotnet-docs-samples](https://github.com/GoogleCloudPlatform/dotnet-docs-samples/tree/vs2015)\nrepo. To use it, after building the project, specify your\n[project ID](https://support.google.com/cloud/answer/6158840?hl=en): \n\n C:\\...\\bin\\Debug\u003e set GOOGLE_PROJECT_ID=[YOUR_PROJECT_ID]\n\nMake sure to replace `[YOUR_PROJECT_ID]` with the correct value from the\nGoogle Cloud console.\n\nThen, send exception data with code similar to the following: \n\n public class ErrorReportingSample\n {\n public static void Main(string[] args)\n {\n try\n {\n throw new Exception(\"Generic exception for testing Stackdriver Error Reporting\");\n }\n catch (Exception e)\n {\n report(e);\n Console.WriteLine(\"Stackdriver Error Report Sent\");\n }\n }\n\n /// \u003csummary\u003e\n /// Create the Error Reporting service (\u003cseealso cref=\"ClouderrorreportingService\"/\u003e)\n /// with the Application Default Credentials and the proper scopes.\n /// See: https://developers.google.com/identity/protocols/application-default-credentials.\n /// \u003c/summary\u003e\n private static ClouderrorreportingService CreateErrorReportingClient()\n {\n // Get the Application Default Credentials.\n GoogleCredential credential = GoogleCredential.GetApplicationDefaultAsync().Result;\n\n // Add the needed scope to the credentials.\n credential.CreateScoped(ClouderrorreportingService.Scope.CloudPlatform);\n\n // Create the Error Reporting Service.\n ClouderrorreportingService service = new ClouderrorreportingService(new BaseClientService.Initializer\n {\n HttpClientInitializer = credential,\n });\n return service;\n }\n\n /// \u003csummary\u003e\n /// Creates a \u003cseealso cref=\"ReportRequest\"/\u003e from a given exception.\n /// \u003c/summary\u003e\n private static ReportRequest CreateReportRequest(Exception e)\n {\n // Create the service.\n ClouderrorreportingService service = CreateErrorReportingClient();\n\n // Get the project ID from the environement variables.\n string projectId = Environment.GetEnvironmentVariable(\"GOOGLE_PROJECT_ID\");\n\n // Format the project id to the format Error Reporting expects. See:\n // https://cloud.google.com/error-reporting/reference/rest/v1beta1/projects.events/report\n string formattedProjectId = string.Format(\"projects/{0}\", projectId);\n\n // Add a service context to the report. For more details see:\n // https://cloud.google.com/error-reporting/reference/rest/v1beta1/projects.events#ServiceContext\n ServiceContext serviceContext = new ServiceContext()\n {\n Service = \"myapp\",\n Version = \"8c1917a9eca3475b5a3686d1d44b52908463b989\",\n };\n ReportedErrorEvent errorEvent = new ReportedErrorEvent()\n {\n Message = e.ToString(),\n ServiceContext = serviceContext,\n };\n return new ReportRequest(service, errorEvent, formattedProjectId);\n }\n\n /// \u003csummary\u003e\n /// Report an exception to the Error Reporting service.\n /// \u003c/summary\u003e\n private static void report(Exception e)\n {\n // Create the report and execute the request.\n ReportRequest request = CreateReportRequest(e);\n request.Execute();\n }\n }\n\n### Go\n\nSee [Setting up Error Reporting for Go](/error-reporting/docs/setup/go).\n\n### Java\n\nSee [Setting up Error Reporting for Java](/error-reporting/docs/setup/java).\n\n### Node.js\n\nSee [Setting up Error Reporting for Node.js](/error-reporting/docs/setup/nodejs).\n\n### Ruby\n\nSee [Setting up Error Reporting for Ruby](/error-reporting/docs/setup/ruby).\n\n### Python\n\nSee [Setting up Error Reporting for Python](/error-reporting/docs/setup/python).\n\n### PHP\n\nSee [Setting up Error Reporting for PHP](/error-reporting/docs/setup/php).\n\nView error groups\n-----------------\n\nIn the Google Cloud console, go to the **Error Reporting** page:\n\n[Go to **Error Reporting**](https://console.cloud.google.com/errors)\n\n\u003cbr /\u003e\n\nYou can also find this page by using the search bar.\n\n\u003cbr /\u003e\n\n| **Note** : If you see the message \"Set up Error Reporting\" on the **Error Reporting** page, then your Google Cloud project has no error groups to display.\n\n\u003cbr /\u003e"]]