Ejemplo n.º 1
0
func (h *NewRelicTracer) ServeHTTPContext(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
	path := templatePath(h.router, r)
	txName := fmt.Sprintf("%s %s", r.Method, path)

	tx := h.createTx(txName, r.URL.String(), h.tracer)
	ctx = newrelic.WithTx(ctx, tx)

	tx.Start()
	defer tx.End()

	return h.handler.ServeHTTPContext(ctx, w, r)
}
Ejemplo n.º 2
0
func TestReport(t *testing.T) {
	tx := newrelic.NewTx("GET /boom")
	tx.Reporter = &TestReporter{
		f: func(id int64, exceptionType, errorMessage, stackTrace, stackFrameDelim string) {
			if got, want := exceptionType, "*errors.errorString"; got != want {
				t.Errorf("exceptionType => %v; want %v", got, want)
			}
			if got, want := errorMessage, "boom"; got != want {
				t.Errorf("errorMessage => %v; want %v", got, want)
			}

			if stackTrace == "" {
				t.Error("stackTrace: expected to not be empty")
			}
		},
	}

	ctx := context.Background()
	ctx = newrelic.WithTx(ctx, tx)

	r := NewReporter()
	r.Report(ctx, errBoomMore)
}