Effective Go on Cloud Run: Structured Logging

This page summarizes the projects mentioned and recommended in the original post on dev.to

InfluxDB - Power Real-Time Data Analytics at Scale
Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
www.influxdata.com
featured
SaaSHub - Software Alternatives and Reviews
SaaSHub helps you find the best software and product alternatives
www.saashub.com
featured
  • google-cloud

    Google Cloud Client Libraries for Go.

  • package logx import ( "fmt" "net/http" ) func info(r *http.Request, message interface{}, projectID string) { get := r.Header.Get("X-Cloud-Trace-Context") traceID, spanID, traceSampled := deconstructXCloudTraceContext(get) traceID = fmt.Sprintf("projects/%s/traces/%s", projectID, traceID) entry := logEntry{ Severity: "INFO", Message: message, HttpRequest: &httpRequest{ RequestMethod: r.Method, RequestUrl: r.URL.String(), UserAgent: r.UserAgent(), RemoteIp: r.RemoteAddr, Referer: r.Referer(), }, Timestamp: time.Now(), Labels: map[string]string{"labels": "rock"}, SpanID: spanID, TraceID: traceID, TraceSampled: traceSampled, } writelog(&entry) } func writelog(entry *logEntry) { if err := json.NewEncoder(os.Stderr).Encode(entry); err != nil { fmt.Printf("failure to write structured log entry: %v", err) } } // taken from https://github.com/googleapis/google-cloud-go/blob/master/logging/logging.go#L774 var reCloudTraceContext = regexp.MustCompile( // Matches on "TRACE_ID" `([a-f\d]+)?` + // Matches on "/SPAN_ID" `(?:/([a-f\d]+))?` + // Matches on ";0=TRACE_TRUE" `(?:;o=(\d))?`) func deconstructXCloudTraceContext(s string) (traceID, spanID string, traceSampled bool) { // As per the format described at https://cloud.google.com/trace/docs/setup#force-trace // "X-Cloud-Trace-Context: TRACE_ID/SPAN_ID;o=TRACE_TRUE" // for example: // "X-Cloud-Trace-Context: 105445aa7843bc8bf206b120001000/1;o=1" // // We expect: // * traceID (optional): "105445aa7843bc8bf206b120001000" // * spanID (optional): "1" // * traceSampled (optional): true matches := reCloudTraceContext.FindStringSubmatch(s) traceID, spanID, traceSampled = matches[1], matches[2], matches[3] == "1" if spanID == "0" { spanID = "" } return }

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts

  • Out of process pagination on BigQuery table

    1 project | /r/bigquery | 11 Dec 2023
  • Bigquery response mismatch with httpreplay

    1 project | /r/golang | 8 Oct 2023
  • Is it just me or does google not provide SDK documentation

    2 projects | /r/googlecloud | 2 Feb 2023
  • Does the aiplatform (VertexAI) Go grpc implementation work?

    1 project | /r/googlecloud | 14 Apr 2022
  • Finding and fixing memory leaks in Go

    1 project | dev.to | 11 Aug 2021