简体   繁体   English

使用 gcloud 报告 Stackdriver 错误

[英]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您可以从那里开始并找到指向其子元素ServiceContextErrorContext 的链接

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.

相关问题 GKE 中的 Stackdriver 抛出 rpc 错误“无法导出到 Stackdriver”“超出上下文截止日期” - Stackdriver in GKE throws rpc error "Failed to export to Stackdriver" "context deadline exceeded" 执行 Stackdriver AsyncReporter 运行状况检查时出现 GCP 错误 - GCP Error when performing Stackdriver AsyncReporter health check 尝试使用“gcloud init”进行身份验证时出错 - Error while trying to authenticate with `gcloud init` 是什么导致 Google gcloud 错误消息“错误:(gcloud)无效选择:'gcloud'”以及如何解决这个问题? - What causes Google gcloud error message "ERROR: (gcloud) Invalid choice: 'gcloud'" and how to resolve this? GCloud 错误:源代码大小超出限制 - GCloud Error: Source code size exceeds the limit GCloud function 调用错误:错误:无法处理请求 - GCloud function call error: Error: could not handle the request 运行 gcloud auth 时出错此应用已被阻止 - Error running gcloud auth This app is blocked Stackdriver 错误记录 API - 错误代码”:400 “消息”:“缺少 group_id。” - 获取错误日志 - Stackdriver Error Logging API - error code": 400 "message": "Missing group_id." - Get error logs 使用nodejs批量更新报告争用错误 - Batch updates reporting contention error using nodejs 机器学习的 tensorflow.python.keras.applications 在 gcloud 上出错 - Error on gcloud with tensorflow.python.keras.applications for machine learning
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM