Skip to content

Commit b972074

Browse files
Merge pull request #616 from newrelic/develop
3.20.2 Release
2 parents e4d1622 + fbbbb5c commit b972074

21 files changed

+285
-78
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
## 3.20.2
2+
3+
### Added
4+
* New `NoticeExpectedError()` method allows you to capture errors that you are expecting to handle, without triggering alerts
5+
6+
### Fixed
7+
* More defensive harvest cycle code that will avoid crashing even in the event of a panic.
8+
* Update `nats-server` version to avoid known zip-slip exploit
9+
* Update `labstack/echo` version to mitigate known open redirect exploit
10+
11+
### Support Statement
12+
New Relic recommends that you upgrade the agent regularly to ensure that you’re getting the latest features and performance benefits. Additionally, older releases will no longer be supported when they reach end-of-life.
13+
14+
We also recommend using the latest version of the Go language. At minimum, you should at least be using no version of Go older than what is supported by the Go team themselves.
15+
16+
See the [Go Agent EOL Policy](https://docs.newrelic.com/docs/apm/agents/go-agent/get-started/go-agent-eol-policy/) for details about supported versions of the Go Agent and third-party components.
17+
118
## 3.20.1
219

320
### Added

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Before submitting an Issue, please search for similar ones in the
2424

2525
## Pull Requests
2626

27-
Pull requests must pass all automated tests and must be reviewed by at least one maintaining engineer before being merged.
27+
Pull requests must pass all automated tests and must be reviewed by at least one maintaining engineer before being merged. Please contribute all pull requests against the `develop` branch, which is where we stage changes ahead of a release and run our most complete suite of tests.
2828

2929
When contributing a new integration package, please follow the [Writing a New Integration Package](https://github.com/newrelic/go-agent/wiki/Writing-a-New-Integration-Package) wiki page.
3030

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
2-
[![Community Plus header](https://github.com/newrelic/opensource-website/raw/master/src/images/categories/Community_Plus.png)](https://opensource.newrelic.com/oss-category/#community-plus)
1+
[![Community Plus header](https://github.com/newrelic/opensource-website/raw/main/src/images/categories/Community_Plus.png)](https://opensource.newrelic.com/oss-category/#community-plus)
32

43
# New Relic Go Agent [![GoDoc](https://godoc.org/github.com/newrelic/go-agent?status.svg)](https://godoc.org/github.com/newrelic/go-agent/v3/newrelic/) [![Go Report Card](https://goreportcard.com/badge/github.com/newrelic/go-agent)](https://goreportcard.com/report/github.com/newrelic/go-agent)
54

v3/examples/server/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ func noticeError(w http.ResponseWriter, r *http.Request) {
3131
txn.NoticeError(errors.New("my error message"))
3232
}
3333

34+
func noticeExpectedError(w http.ResponseWriter, r *http.Request) {
35+
io.WriteString(w, "noticing an error")
36+
37+
txn := newrelic.FromContext(r.Context())
38+
txn.NoticeExpectedError(errors.New("my expected error message"))
39+
}
40+
3441
func noticeErrorWithAttributes(w http.ResponseWriter, r *http.Request) {
3542
io.WriteString(w, "noticing an error")
3643

@@ -273,6 +280,7 @@ func main() {
273280
http.HandleFunc(newrelic.WrapHandleFunc(app, "/", index))
274281
http.HandleFunc(newrelic.WrapHandleFunc(app, "/version", versionHandler))
275282
http.HandleFunc(newrelic.WrapHandleFunc(app, "/notice_error", noticeError))
283+
http.HandleFunc(newrelic.WrapHandleFunc(app, "/notice_expected_error", noticeExpectedError))
276284
http.HandleFunc(newrelic.WrapHandleFunc(app, "/notice_error_with_attributes", noticeErrorWithAttributes))
277285
http.HandleFunc(newrelic.WrapHandleFunc(app, "/custom_event", customEvent))
278286
http.HandleFunc(newrelic.WrapHandleFunc(app, "/set_name", setName))

v3/integrations/nrecho-v4/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ module github.com/newrelic/go-agent/v3/integrations/nrecho-v4
55
go 1.17
66

77
require (
8-
github.com/labstack/echo/v4 v4.5.0
8+
github.com/labstack/echo/v4 v4.9.0
99
github.com/newrelic/go-agent/v3 v3.18.2
1010
)

v3/integrations/nrstan/test/go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ module github.com/newrelic/go-agent/v3/integrations/nrstan/test
66
go 1.13
77

88
require (
9-
github.com/nats-io/nats-streaming-server v0.24.1
10-
github.com/nats-io/stan.go v0.10.2
11-
github.com/newrelic/go-agent/v3 v3.4.0
9+
github.com/nats-io/nats-streaming-server v0.24.3
10+
github.com/nats-io/stan.go v0.10.3
11+
github.com/newrelic/go-agent/v3 v3.18.2
1212
github.com/newrelic/go-agent/v3/integrations/nrstan v0.0.0
1313
)
1414

v3/internal/jsonx/encode_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package jsonx
55

66
import (
77
"bytes"
8+
"fmt"
89
"math"
910
"testing"
1011
)
@@ -28,6 +29,30 @@ func TestAppendFloat(t *testing.T) {
2829
}
2930
}
3031

32+
func TestAppendFloat32(t *testing.T) {
33+
buf := &bytes.Buffer{}
34+
35+
err := AppendFloat32(buf, float32(math.NaN()))
36+
if err == nil {
37+
t.Error("AppendFloat(NaN) should return an error")
38+
}
39+
40+
err = AppendFloat32(buf, float32(math.Inf(1)))
41+
if err == nil {
42+
t.Error("AppendFloat(+Inf) should return an error")
43+
}
44+
45+
err = AppendFloat32(buf, float32(math.Inf(-1)))
46+
if err == nil {
47+
t.Error("AppendFloat(-Inf) should return an error")
48+
}
49+
50+
err = AppendFloat32(buf, float32(12.5))
51+
if err != nil {
52+
t.Error("AppendFloat(12.5) should not return an error")
53+
}
54+
}
55+
3156
func TestAppendFloats(t *testing.T) {
3257
buf := &bytes.Buffer{}
3358

@@ -166,6 +191,15 @@ var encodeStringTests = []struct {
166191
{"\\", `"\\"`},
167192
{`"`, `"\""`},
168193
{"the\u2028quick\t\nbrown\u2029fox", `"the\u2028quick\t\nbrown\u2029fox"`},
194+
195+
//extra edge cases
196+
{string([]byte{237, 159, 193}), `"\ufffd\ufffd\ufffd"`}, // invalid utf8
197+
{string([]byte{55, 237, 159, 193, 55}), `"7\ufffd\ufffd\ufffd7"`}, // invalid utf8 surrounded by valid utf8
198+
{`abcdefghijklmnopqrstuvwxyz1234567890`, `"abcdefghijklmnopqrstuvwxyz1234567890"`}, // alphanumeric
199+
{"'", `"'"`},
200+
{``, `""`},
201+
{`\`, `"\\"`},
202+
{fmt.Sprintf("%c", rune(65533)), fmt.Sprintf("\"%c\"", rune(65533))}, // invalid rune utf8 symbol (valid utf8)
169203
}
170204

171205
func TestAppendString(t *testing.T) {
@@ -181,6 +215,41 @@ func TestAppendString(t *testing.T) {
181215
}
182216
}
183217

218+
func TestAppendStringArray(t *testing.T) {
219+
buf := &bytes.Buffer{}
220+
221+
var encodeStringArrayTests = []struct {
222+
in []string
223+
out string
224+
}{
225+
{
226+
in: []string{
227+
"hi",
228+
"foo",
229+
},
230+
out: `["hi","foo"]`,
231+
},
232+
{
233+
in: []string{
234+
"foo",
235+
},
236+
out: `["foo"]`,
237+
},
238+
{
239+
in: []string{},
240+
out: `[]`,
241+
},
242+
}
243+
244+
for _, tt := range encodeStringArrayTests {
245+
buf.Reset()
246+
247+
AppendStringArray(buf, tt.in...)
248+
if got := buf.String(); got != tt.out {
249+
t.Errorf("AppendString(%q) = %#q, want %#q", tt.in, got, tt.out)
250+
}
251+
}
252+
}
184253
func BenchmarkAppendString(b *testing.B) {
185254
buf := &bytes.Buffer{}
186255

v3/newrelic/attributes_from_internal.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,8 @@ func (attr agentAttributes) Add(id string, stringVal string, otherVal interface{
275275
}
276276
}
277277

278-
//
279278
// Remove is used to remove agent attributes.
280279
// It is not an error if the attribute wasn't present to begin with.
281-
//
282280
func (attr agentAttributes) Remove(id string) {
283281
if _, ok := attr[id]; ok {
284282
delete(attr, id)
@@ -453,14 +451,14 @@ func writeAttributeValueJSON(w *jsonFieldsWriter, key string, val interface{}) {
453451
}
454452

455453
func agentAttributesJSON(a *attributes, buf *bytes.Buffer, d destinationSet) {
456-
if nil == a {
454+
if a == nil {
457455
buf.WriteString("{}")
458456
return
459457
}
460458
w := jsonFieldsWriter{buf: buf}
461459
buf.WriteByte('{')
462460
for id, val := range a.Agent {
463-
if 0 != a.config.agentDests[id]&d {
461+
if a.config.agentDests[id]&d != 0 {
464462
if val.stringVal != "" {
465463
w.stringField(id, val.stringVal)
466464
} else {
@@ -478,12 +476,12 @@ func userAttributesJSON(a *attributes, buf *bytes.Buffer, d destinationSet, extr
478476
w := jsonFieldsWriter{buf: buf}
479477
for key, val := range extraAttributes {
480478
outputDest := applyAttributeConfig(a.config, key, d)
481-
if 0 != outputDest&d {
479+
if outputDest&d != 0 {
482480
writeAttributeValueJSON(&w, key, val)
483481
}
484482
}
485483
for name, atr := range a.user {
486-
if 0 != atr.dests&d {
484+
if atr.dests&d != 0 {
487485
if _, found := extraAttributes[name]; found {
488486
continue
489487
}

v3/newrelic/errors_from_internal.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ type errorData struct {
6161
Msg string
6262
Klass string
6363
SpanID string
64+
Expect bool
6465
}
6566

6667
// txnError combines error data with information about a transaction. txnError is used for
@@ -113,7 +114,7 @@ func (h *tracedError) WriteJSON(buf *bytes.Buffer) {
113114
buf.WriteByte(',')
114115
buf.WriteString(`"intrinsics"`)
115116
buf.WriteByte(':')
116-
intrinsicsJSON(&h.txnEvent, buf)
117+
intrinsicsJSON(&h.txnEvent, buf, h.errorData.Expect)
117118
if nil != h.Stack {
118119
buf.WriteByte(',')
119120
buf.WriteString(`"stack_trace"`)
@@ -152,7 +153,7 @@ func mergeTxnErrors(errors *harvestErrors, errs txnErrors, txnEvent txnEvent) {
152153
}
153154

154155
func (errors harvestErrors) Data(agentRunID string, harvestStart time.Time) ([]byte, error) {
155-
if 0 == len(errors) {
156+
if len(errors) == 0 {
156157
return nil, nil
157158
}
158159
estimate := 1024 * len(errors)

v3/newrelic/harvest.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,16 @@ func createTxnMetrics(args *txnData, metrics *metricTable) {
327327
}
328328

329329
// Error Metrics
330-
if args.HasErrors() {
330+
if args.NoticeErrors() {
331331
metrics.addSingleCount(errorsRollupMetric.all, forced)
332332
metrics.addSingleCount(errorsRollupMetric.webOrOther(args.IsWeb), forced)
333333
metrics.addSingleCount(errorsPrefix+args.FinalName, forced)
334334
}
335335

336+
if args.HasExpectedErrors() {
337+
metrics.addSingleCount(expectedErrorsRollupMetric.all, forced)
338+
}
339+
336340
// Queueing Metrics
337341
if args.Queuing > 0 {
338342
metrics.addDuration(queueMetric, "", args.Queuing, args.Queuing, forced)

0 commit comments

Comments
 (0)