다음 두 가지 방법 중 하나로 Google Kubernetes Engine 애플리케이션에서 Error Reporting으로 오류를 보낼 수 있습니다.
Cloud Logging에 로깅. Cloud Logging을 이미 사용 중인 경우 유일한 추가 요구사항은 Error Reporting에서 로그 항목을 인식할 수 있어야 한다는 것입니다. 오류 형식 지정 요구사항에 대한 자세한 내용은 Cloud Logging의 형식 지정 오류를 참조하세요.
Error Reporting API 사용. 애플리케이션은 REST API를 사용하여 HTTP 요청을 보내거나 여러 언어로 실험용 라이브러리를 활용할 수 있습니다.
Logging을 사용해 오류 보고하기
GKE의 기본 로깅 에이전트는 클러스터의 로그를 Cloud Logging으로 보내는 에이전트를 배포하고 관리하는 관리형 솔루션을 제공합니다. 에이전트 구조는 클러스터 버전에 따라 달라집니다. 이 에이전트에 대한 자세한 내용은 GKE 로그 관리를 참조하세요.
Error Reporting을 사용하려면 예외 사항 또는 스택 트레이스가 단일 로그 항목에 포함되어야 합니다. 대부분의 로깅 에이전트는 새 행에 출력된 각 스택 프레임과 같은 여러 로그 행이 스택 트레이스를 나타내는 것을 인식할 수 있고 이를 Cloud Logging에 단일 로그 항목으로 전송합니다.
에이전트가 여러 행을 단일 오류로 재구성할 수 없으면 오류 콘텐츠를 제어할 수 있는 projects.events.report API 엔드포인트를 사용합니다.
Error Reporting API를 사용하여 오류 쓰기
Error Reporting API는 서비스에 오류 정보를 작성하기 위한 report 엔드포인트를 제공합니다.
ASP.NET NuGet 패키지는 ASP.NET 웹 애플리케이션에서 포착되지 않은 예외를 Error Reporting으로 보고합니다.
NuGet 패키지 설치
Visual Studio에서 Stackdriver ASP.NET NuGet 패키지를 설치하려면 다음 단계를 따르세요.
솔루션을 마우스 오른쪽 버튼으로 클릭하고 Manage NuGet packages for solution(솔루션용 NuGet 패키지 관리)를 선택합니다.
Include prerelease(사전 출시 포함) 체크박스를 선택합니다.
이름이 Google.Cloud.Diagnostics.AspNet인 패키지를 검색하여 설치합니다.
사용
Stackdriver ASP.NET NuGet 패키지를 설치했으면 애플리케이션 코드에 다음 문을 추가하여 Stackdriver로 오류 보내기를 시작합니다.
using Google.Cloud.Diagnostics.AspNet;
다음 HttpConfiguration 코드를 .NET 웹 앱(your-project-id를 실제 프로젝트 ID로 바꿈)의 Register 메서드에 추가하여 예외 보고를 사용 설정합니다.
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));// ...}
이 메서드를 ASP.NET 애플리케이션에 추가하면 Google Cloud 콘솔의 Error Reporting 섹션에서 Google Cloud에 보고될 때 발생하는 포착되지 않은 예외를 볼 수 있습니다.
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();}}
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-03(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,["You 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\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\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\nSamples \n\nASP.NET\n\nThe ASP.NET NuGet package reports uncaught exceptions from\nASP.NET web applications to Error Reporting.\n\nInstall 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\nUsage\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\nC#\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\nGo\n\nSee [Setting up Error Reporting for Go](/error-reporting/docs/setup/go).\n\nJava\n\nSee [Setting up Error Reporting for Java](/error-reporting/docs/setup/java).\n\nNode.js\n\nSee [Setting up Error Reporting for Node.js](/error-reporting/docs/setup/nodejs).\n\nRuby\n\nSee [Setting up Error Reporting for Ruby](/error-reporting/docs/setup/ruby).\n\nPython\n\nSee [Setting up Error Reporting for Python](/error-reporting/docs/setup/python).\n\nPHP\n\nSee [Setting up Error Reporting for PHP](/error-reporting/docs/setup/php).\n\nView error groups\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"]]