이 페이지에서는 Cloud Logging을 사용하여 오류 이벤트를 보고하는 데 필요한 로그 항목 형식을 설명합니다.
시작하기 전에
Error Reporting API를 사용하는 경우 오류 이벤트를 ReportedErrorEvent
에 작성하여 애플리케이션에서 보고할 수 있습니다. 이렇게 하면 Cloud Logging에 올바른 형식의 오류 메시지가 포함된 로그 항목이 생성됩니다. 결과 logName
형식은 다음과 같습니다.
projects/<PROJECT_ID>/clouderrorreporting.googleapis.com%2Freported_errors
이 메서드를 사용하는 Cloud Logging 수집 비용이 발생할 수 있습니다. 이러한 비용을 관리하려면 로그 제외를 참조하세요.
Cloud Logging을 사용하여 오류 이벤트를 보고하려는 경우 다음 섹션을 읽어보세요.
형식 지정 요구사항
스택 트레이스 또는 예외가 포함되거나 ReportedErrorEvent
와 같은 형식의 Cloud Logging의 로그 항목은 Error Reporting에 오류를 생성합니다.
오류 데이터는 LogEntry
통합 필드 payload
에 다음 유형 중 하나로 로깅되어야 합니다.
- 여러 줄로 구성된
textPayload
jsonPayload
의message
필드
사용 언어 및 플랫폼의 설정 안내도 따라야 합니다. App Engine, Compute Engine, Google Kubernetes Engine에서 오류 데이터를 로깅할 때는 로그 항목에 전체 예외 메시지와 스택 트레이스를 포함하기만 하면 됩니다.
예외 메시지 및 스택 트레이스의 형식을 지정하는 방법은 Error Reporting report
참조 페이지의 ReportedErrorEvent를 참조하세요.
@type
지정
로그 항목에 type.googleapis.com/google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent
의 @type
이 포함되어 있다면 Error Reporting은 모든 필수 필드가 존재함에 따라 로그 항목을 평가하며, 오류 이벤트를 캡처합니다.
JSON 표현
Cloud Logging을 사용하여 오류 데이터를 전송할 때 사용자가 제공하는 ReportedErrorEvent
는 다음 JSON 구조를 사용해야 합니다.
{
"eventTime": string,
"serviceContext": {
"service": string, // Required.
"version": string
},
"message": string, // Required. This field contains the content to report.
// For information on populating this field, see Formatting requirements.
"@type": string // Optional. For information on this field, see Specifying @type
.
"context": {
"httpRequest": {
"method": string,
"url": string,
"userAgent": string,
"referrer": string,
"responseStatusCode": number,
"remoteIp": string
},
"user": string,
"reportLocation": { // Required if no stack trace is provided.
"filePath": string,
"lineNumber": number,
"functionName": string
}
}
}
지원되는 모니터링 리소스 유형
LogEntry
구조를 통해 로깅할 때, resource
필드는 다음 지원되는 모니터링 리소스 유형 중 하나로 설정되어야 합니다.
app_script_function
aws_ec2_instance
cloud_function
cloud_run_revision
consumed_api
container
dataflow_step
gae_app
gce_instance
k8s_container
ml_job
1global
1
1 textPayload
지원되지 않음
로그 항목 형식 지정 예시
다음 예시에서는 LogEntry.jsonPayload
에 로깅한 경우 Error Reporting에서 올바르게 처리하는 로그 항목을 보여줍니다.
@type
이 올바르게 지정되어 있기 때문에 로그 항목이 그룹화됩니다.
{... { "jsonPayload": { "@type": "type.googleapis.com/google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent", "message": "A simple text message" }, "logName": "projects/test-project/logs/reported-error", "resource": { "labels": { "project_id": "test-project" }, "type": "global" }, "severity": "ERROR", "timestamp": "2019-06-27T13:43:26.375834551Z" } }
이 로그 항목의 페이로드 message
에는 스택 트레이스 및 예외가 포함되어 있으므로 Error Reporting에 의해 그룹화됩니다.
{ "serviceContext": { "service": "frontend", "version": "bf6b5b09b9d3da92c7bf964ab1664fe751104517" }, "message": "com.example.shop.Template$CartDiv retrieveCart: Error\njava.lang.IndexOutOfBoundsException: Index: 4, Size: 4\n\tat java.util.ArrayList.rangeCheck(ArrayList.java:635)\n\tat java.util.ArrayList.get(ArrayList.java:411)\n\tat com.example.shop.Cart.retrieve(Cart.java:76)\n\tat com.example.shop.Cart.generate(Cart.java:55)\n\tat com.example.shop.Template$CartDiv.retrieveCart(Template.java:113)\n\tat com.example.shop.Template.generate(Template.java:22)\n\tat com.example.shop.CartServlet.doGet(CartServlet.java:115)\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:717)\n", "context": { "httpRequest": { "method": "GET", "url": "http://example.com/shop/cart", "responseStatusCode": 500 }, "user": "9f32f587135aa6774e78ed30fbaabcce3ec5528f" } }
ReportedErrorEvent
인스턴스에서 사용되는 필드에 대한 자세한 내용은 문서를 참조하세요.