Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to parse error logs to Error Reporting type #667

Merged
merged 2 commits into from
Jul 18, 2023

Conversation

damemi
Copy link
Member

@damemi damemi commented Jul 7, 2023

Fixes #665
This adds an option to the logs exporter, log.error_reporting_type, to automatically format error logs to GCP Error Reporting. To do this, it adds the @type field to existing JSON payloads, or converts string payloads to JSON (with a message field) and then adds @type.

I don't think there is a behavior that makes sense for byte payloads, since that would mean a mixture of byte and string values in the json payload (?).

An improvement to this could be using the ReportedErrorEvent protobuf directly rather than just setting @type, as documented in https://cloud.google.com/error-reporting/docs/formatting-error-messages#reported-error-example. This adds a requirement for a service field.

{
Payload: map[string]interface{}{
"@type": "type.googleapis.com/google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent",
"message": `{"message": "hello!"}`,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that "json" bodies (that are actually string values) can end up with a redundant message key. I don't think we should try automatically parsing bodies that are string valued to JSON and making assumptions to remove them

exporter/collector/logs.go Show resolved Hide resolved
exporter/collector/logs.go Outdated Show resolved Hide resolved
exporter/collector/logs_test.go Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Jul 10, 2023

Codecov Report

Merging #667 (8ee42c7) into main (cc91e37) will increase coverage by 0.08%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #667      +/-   ##
==========================================
+ Coverage   68.47%   68.56%   +0.08%     
==========================================
  Files          36       36              
  Lines        4559     4577      +18     
==========================================
+ Hits         3122     3138      +16     
- Misses       1284     1286       +2     
  Partials      153      153              
Impacted Files Coverage Δ
exporter/collector/config.go 45.04% <ø> (ø)
...lector/integrationtest/testcases/testcases_logs.go 100.00% <100.00%> (ø)
exporter/collector/logs.go 41.02% <100.00%> (+2.67%) ⬆️

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@psx95 psx95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit (variable naming), but looks good to me overall.

@@ -180,6 +180,9 @@ type LogConfig struct {
// service.name, service.namespace, and service.instance.id resource attributes into the Cloud Logging LogEntry labels.
// Disabling this option does not prevent resource_filters from adding those labels. Default is true.
ServiceResourceLabels bool `mapstructure:"service_resource_labels"`
// ErrorReportingType enables automatically parsing error logs to a json payload containing the
// type value for GCP Error Reporting. See https://cloud.google.com/error-reporting/docs/formatting-error-messages#log-text.
ErrorReportingType bool `mapstructure:"error_reporting_type"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it isn't clear from the name what it does. Prefer send_errors_to_error_reporting, or something that implies what the effect is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afaict, adding this attribute doesn't send them "to" error reporting. they're still sent to cloud logging, just reformatted to have a special attribute that Error Reporting picks up. I'm not entirely clear on the ux from that point, will talk to some of the folks who work on ER

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Thanks for checking!

@damemi damemi merged commit b6fc3f0 into GoogleCloudPlatform:main Jul 18, 2023
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Formatting error messages in logs to report error events to GCP Error Reporting service
3 participants