// collectEvent marshals and collects the Event. func (r *Recorder) collectEvent(spanID appdash.SpanID, e appdash.Event) { ans, err := appdash.MarshalEvent(e) if err != nil { r.logError(spanID, err) return } r.collectAnnotation(spanID, ans...) }
// logError converts an error into a log event and collects it. // If for whatever reason the error can't be collected, it is logged to the // Recorder's logger if it is non-nil. func (r *Recorder) logError(spanID appdash.SpanID, err error) { ans, _ := appdash.MarshalEvent(appdash.Log(err.Error())) // At this point, something is definitely wrong. if err := r.collector.Collect(spanID, ans...); err != nil { if r.verbose { r.Log.Printf("Appdash Recorder collect error: %v\n", err) } else { r.logOnce.Do(func() { r.Log.Printf("Appdash Recorder collect error: %v\n", err) }) } } }
func TestNewServerEvent(t *testing.T) { r := &http.Request{ Host: "example.com", Method: "GET", URL: &url.URL{Path: "/foo"}, Proto: "HTTP/1.1", RemoteAddr: "127.0.0.1", ContentLength: 0, Header: http.Header{ "Authorization": []string{"Basic seeecret"}, "Accept": []string{"application/json"}, }, Trailer: http.Header{ "Authorization": []string{"Basic seeecret"}, "Connection": []string{"close"}, }, } e := NewServerEvent(r) e.Response.StatusCode = 200 if e.Schema() != "HTTPServer" { t.Errorf("unexpected schema: %v", e.Schema()) } anns, err := appdash.MarshalEvent(e) if err != nil { t.Fatal(err) } expected := map[string]string{ "_schema:HTTPServer": "", "Server.Request.Headers.Connection": "close", "Server.Request.Headers.Accept": "application/json", "Server.Request.Headers.Authorization": "REDACTED", "Server.Request.Proto": "HTTP/1.1", "Server.Request.RemoteAddr": "127.0.0.1", "Server.Request.Host": "example.com", "Server.Request.ContentLength": "0", "Server.Request.Method": "GET", "Server.Request.URI": "/foo", "Server.Response.StatusCode": "200", "Server.Response.ContentLength": "0", "Server.User": "", "Server.Route": "", "Server.Send": "0001-01-01T00:00:00Z", "Server.Recv": "0001-01-01T00:00:00Z", } if !reflect.DeepEqual(anns.StringMap(), expected) { t.Errorf("got %#v, want %#v", anns.StringMap(), expected) } }
func marshalEvent(e appdash.Event) appdash.Annotations { ans, _ := appdash.MarshalEvent(e) return ans }