[英]Stackdriver error reporting with gcloud
I'm retying to use the gcloud cli to send events to StackDriver Error Reporting.我正在尝试使用 gcloud cli 将事件发送到 StackDriver 错误报告。
The (very limited) documentation is here: https://cloud.google.com/sdk/gcloud/reference/beta/error-reporting/events/report (非常有限的)文档在这里: https://cloud.google.com/sdk/gcloud/reference/beta/error-reporting/events/report
Regardless of what I send as a message I seem to get this error:无论我作为消息发送什么,我似乎都会收到此错误:
ERROR: (gcloud.beta.error-reporting.events.report) INVALID_ARGUMENT: ReportedErrorEvent.context must contain a location unless
message
contain an exception or stacktrace.错误:(gcloud.beta.error-reporting.events.report) INVALID_ARGUMENT:ReportedErrorEvent.context 必须包含位置,除非
message
包含异常或堆栈跟踪。
I have tried formatting the message as a JSON representation of an error report: https://cloud.google.com/error-reporting/docs/formatting-error-messages but the message seems to be the same.我尝试将消息格式化为错误报告的 JSON 表示形式: https://cloud.google.com/error-reporting/docs/formatting-error-messages但消息似乎是相同的。 Here's an example command and JSON:
这是一个示例命令和 JSON:
gcloud beta error-reporting events report --service foo --message-file err.json
{
"serviceContext": {
"service": "foo"
},
"message": "Whoops!",
"context": {
"reportLocation": {
"filePath": "/usr/local/bin/test",
"lineNumber": 123,
"functionName": "main"
}
}
}
The gcloud --message or --message-field argument is just the message
field of the reported error, not the entire JSON. gcloud --message 或 --message-field 参数只是报告错误的
message
字段,而不是整个 JSON。 Since you can't provide the reportLocation
via gcloud, message
has to be a stack trace or exception.既然你不能提供
reportLocation
通过gcloud, message
必须是一个堆栈跟踪或异常。
Using the API explorer with the original request works.将API 资源管理器与原始请求配合使用。 Logging the error also makes its way into Error Reporting via:
记录错误也可以通过以下方式进入错误报告:
gcloud beta logging write --payload-type=json test-errors-log '
{
"serviceContext": {
"service": "foo"
},
"message": "Whoops!",
"context": {
"reportLocation": {
"filePath": "/usr/local/bin/test",
"lineNumber": 123,
"functionName": "main"
}
}
}'
Try adding httpRequest details under context.尝试在上下文中添加 httpRequest 详细信息。
You can find details of the json payload in the documentation.您可以在文档中找到 json 有效负载的详细信息。 The parent object in the json is ErrorEvent
json中的父对象是ErrorEvent
You can start from there and find links to its sub-elements ServiceContext and ErrorContext您可以从那里开始并找到指向其子元素ServiceContext和ErrorContext 的链接
Though I have not tried the command line option, I debugged the stackdriver logging classes which we use in our app, to find out what json payload we are sending and here is the sample json fired from our application.虽然我没有尝试过命令行选项,但我调试了我们在应用程序中使用的 stackdriver 日志记录类,以找出我们发送的 json 有效负载,这里是从我们的应用程序中触发的示例 json。
{ "context": { "httpRequest": { "responseStatusCode": 500, "method": "GET", "url": "http://localhost:16500/product" }, "user": "2247177" }, "message": "org.springframework.web.client.HttpServerErrorException: 500 Server Error at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java: 94) ", "serviceContext": { "service": "cart", "version": "" }
Yet another way.还是另一种方式。
gcloud logging write --payload-type=json test-errors-log '
{
"serviceContext": {"service": "foo"},
"message": "message with stacktrace\n at /test.js"
}
'
gcloud logging write --payload-type=json test-errors-log '
{
"@type": "type.googleapis.com/google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent",
"message": "message without stacktrace"
}
'
gcloud beta error-reporting events report --service foo --message 'message with stacktrace
at /test.js'
gcloud beta error-reporting events report
requires stacktrace from programming language to report it. gcloud beta error-reporting events report
需要来自编程语言的堆栈跟踪来报告它。 It is artificial (and actually quite stupid requirement).这是人为的(实际上是非常愚蠢的要求)。
Minimal Java like stacktrace:最小的 Java 像堆栈跟踪:
gcloud beta error-reporting events report --verbosity=debug \
--service test --service-version test1 \
--message "at a()"
You can append interesting data if you keep at<SP><CHARS>()
inside message on a separate line (thanks for Bash $'\n'
magic:):如果您将
at<SP><CHARS>()
内部消息放在单独的行中,您可以得到 append 有趣的数据(感谢 Bash $'\n'
魔法:):
gcloud beta error-reporting events report --verbosity=debug \
--service test --service-version test1 \
--message $'Hello world!\nat a()'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.