File: internal_errors_13_test.go

package info (click to toggle)
golang-github-newrelic-go-agent 3.15.2-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 8,356 kB
  • sloc: sh: 65; makefile: 6
file content (54 lines) | stat: -rw-r--r-- 1,342 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2020 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

// +build go1.13

package newrelic

import (
	"fmt"
	"testing"

	"github.com/newrelic/go-agent/internal"
)

func TestNoticedWrappedError(t *testing.T) {
	gamma := func() error {
		return Error{
			Message: "socket error",
			Class:   "socketError",
			Attributes: map[string]interface{}{
				"zip": "zap",
			},
		}
	}
	beta := func() error { return fmt.Errorf("problem in beta: %w", gamma()) }
	alpha := func() error { return fmt.Errorf("problem in alpha: %w", beta()) }

	app := testApp(nil, nil, t)
	txn := app.StartTransaction("hello", nil, nil)
	err := txn.NoticeError(alpha())
	if nil != err {
		t.Error(err)
	}
	txn.End()
	app.ExpectErrors(t, []internal.WantError{{
		TxnName: "OtherTransaction/Go/hello",
		Msg:     "problem in alpha: problem in beta: socket error",
		Klass:   "socketError",
		UserAttributes: map[string]interface{}{
			"zip": "zap",
		},
	}})
	app.ExpectErrorEvents(t, []internal.WantEvent{{
		Intrinsics: map[string]interface{}{
			"error.class":     "socketError",
			"error.message":   "problem in alpha: problem in beta: socket error",
			"transactionName": "OtherTransaction/Go/hello",
		},
		UserAttributes: map[string]interface{}{
			"zip": "zap",
		},
	}})
	app.ExpectMetrics(t, backgroundErrorMetrics)
}