示例#1
0
文件: recorder.go 项目: bg451/appdash
// 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...)
}
示例#2
0
文件: recorder.go 项目: bg451/appdash
// 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) })
		}
	}
}
示例#3
0
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)
	}
}
示例#4
0
func marshalEvent(e appdash.Event) appdash.Annotations {
	ans, _ := appdash.MarshalEvent(e)
	return ans
}