Skip to content
This repository was archived by the owner on May 20, 2021. It is now read-only.
This repository was archived by the owner on May 20, 2021. It is now read-only.

Thanks and a few ideas! #2

@StevenACoffman

Description

@StevenACoffman

Hi! Thanks for maintaining this library, as it's been very useful to me. In case you're curious, I use your version of logrus-stackdriver-formatter via go-kit's logger like this.

I noticed you added a nice middleware with a questioning comment about the trace, so I thought I'd also leave a thought or two.

If you're not running in AppEngine, you can simply generate any unique ID at the start of your request. The Trace ID has no powers in a standalone environment, and is simply used to differentiate one request from another, so any unique value is sufficient.

//import https://github.com/lithammer/shortuuid

			traceHeader := req.Header.Get("X-Cloud-Trace-Context")
			if traceHeader == "" {
				traceHeader = fmt.Sprintf("%s.%d.%s", instanceName, time.Now().UnixNano(), shortuuid.New())
				// alternative:
				// traceHeader = fmt.Sprintf("projects/%s/traces/%s", projectID, shortuuid.New())
			} 
			fields["trace"] = traceHeader

What would really be nice for me is if I could have Grouping Logs by Request as in this
grouplogger library or in Google Chromium LUCI.

To group all the log entries written during a single HTTP request, create two Loggers, a "parent" and a "child," with different log IDs. Both should be in the same project, and have the same MonitoredResource type and labels.

  • Parent entries must have HTTPRequest.Request populated. (Strictly speaking, only the URL is necessary.)

  • A child entry's timestamp must be within the time interval covered by the parent request. (i.e., before the parent.Timestamp and after the parent.Timestamp - parent.HTTPRequest.Latency. This assumes the parent.Timestamp marks the end of the request.)

  • The trace field must be populated in all of the entries and match exactly.

You should observe the child log entries grouped under the parent on the console. The parent entry will not inherit the severity of its children; you must update the parent severity yourself.

There's more details in this Summary Google Issue

So ideally, your middleware would take care of the parent log message, and any other explicit logging during the request would generate children. Anyway, that's what I was whiteboarding and going to try to implement when I noticed you already did some of the work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions