Skip to content

Commit a213648

Browse files
Merge pull request #228 from newrelic/develop
Release v3.9.0
2 parents 34da20d + 523fc73 commit a213648

File tree

6 files changed

+128
-48
lines changed

6 files changed

+128
-48
lines changed

.github/workflows/ci.yaml

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -103,107 +103,109 @@ jobs:
103103
- go-version: 1.13.x
104104
dirs: v3/newrelic,v3/internal,v3/examples
105105
- go-version: 1.14.x
106+
dirs: v3/newrelic,v3/internal,v3/examples
107+
- go-version: 1.15.x
106108
dirs: v3/newrelic,v3/internal,v3/examples,v3/integrations/logcontext
107109

108110
# v3 integrations
109-
- go-version: 1.14.x
111+
- go-version: 1.15.x
110112
dirs: v3/integrations/logcontext/nrlogrusplugin
111113
extratesting: go get -u github.com/sirupsen/logrus@master
112-
- go-version: 1.14.x
114+
- go-version: 1.15.x
113115
dirs: v3/integrations/nrawssdk-v1
114116
extratesting: go get -u github.com/aws/aws-sdk-go@master
115-
- go-version: 1.14.x
117+
- go-version: 1.15.x
116118
dirs: v3/integrations/nrawssdk-v2
117119
extratesting: go get -u github.com/aws/aws-sdk-go-v2@master
118-
- go-version: 1.14.x
120+
- go-version: 1.15.x
119121
dirs: v3/integrations/nrecho-v3
120122
# Test against the latest v3 Echo:
121123
extratesting: go get -u github.com/labstack/echo@v3
122-
- go-version: 1.14.x
124+
- go-version: 1.15.x
123125
dirs: v3/integrations/nrecho-v4
124126
extratesting: go get -u github.com/labstack/echo/v4@master
125-
- go-version: 1.14.x
127+
- go-version: 1.15.x
126128
dirs: v3/integrations/nrelasticsearch-v7
127129
extratesting: go get -u github.com/elastic/go-elasticsearch/[email protected]
128-
- go-version: 1.14.x
130+
- go-version: 1.15.x
129131
dirs: v3/integrations/nrgin
130132
extratesting: go get -u github.com/gin-gonic/gin@master
131-
- go-version: 1.14.x
133+
- go-version: 1.15.x
132134
dirs: v3/integrations/nrgorilla
133135
extratesting: go get -u github.com/gorilla/mux@master
134-
- go-version: 1.14.x
136+
- go-version: 1.15.x
135137
dirs: v3/integrations/nrgraphgophers
136138
extratesting: go get -u github.com/graph-gophers/graphql-go@master
137-
- go-version: 1.14.x
139+
- go-version: 1.15.x
138140
dirs: v3/integrations/nrlogrus
139141
extratesting: go get -u github.com/sirupsen/logrus@master
140-
- go-version: 1.14.x
142+
- go-version: 1.15.x
141143
dirs: v3/integrations/nrlogxi
142144
extratesting: go get -u github.com/mgutz/logxi@master
143-
- go-version: 1.14.x
145+
- go-version: 1.15.x
144146
dirs: v3/integrations/nrpkgerrors
145147
extratesting: go get -u github.com/pkg/errors@master
146-
- go-version: 1.14.x
148+
- go-version: 1.15.x
147149
dirs: v3/integrations/nrlambda
148150
extratesting: go get -u github.com/aws/aws-lambda-go@master
149-
- go-version: 1.14.x
151+
- go-version: 1.15.x
150152
dirs: v3/integrations/nrmysql
151153
extratesting: go get -u github.com/go-sql-driver/mysql@master
152-
- go-version: 1.14.x
154+
- go-version: 1.15.x
153155
dirs: v3/integrations/nrpq
154156
extratesting: go get -u github.com/lib/pq@master
155-
- go-version: 1.14.x
157+
- go-version: 1.15.x
156158
dirs: v3/integrations/nrpq/example/sqlx
157-
- go-version: 1.14.x
159+
- go-version: 1.15.x
158160
dirs: v3/integrations/nrredis-v7
159161
extratesting: go get -u github.com/go-redis/redis/v7@master
160-
- go-version: 1.14.x
162+
- go-version: 1.15.x
161163
dirs: v3/integrations/nrsqlite3
162164
extratesting: go get -u github.com/mattn/go-sqlite3@master
163-
- go-version: 1.14.x
165+
- go-version: 1.15.x
164166
dirs: v3/integrations/nrsnowflake
165167
extratesting: go get -u github.com/snowflakedb/gosnowflake@master
166-
- go-version: 1.14.x
168+
- go-version: 1.15.x
167169
dirs: v3/integrations/nrgrpc
168170
extratesting: go get -u google.golang.org/grpc@master
169-
- go-version: 1.14.x
171+
- go-version: 1.15.x
170172
dirs: v3/integrations/nrmicro
171173
# As of Dec 2019, there is a race condition in when using go-micro@master
172174
# in their logging system. Instead, we'll test against the latest
173175
# released version.
174176
# As of Jan 2019, it is impossible to go get the latest micro version.
175177
# As of June 2020, confirmed errors still result
176178
# extratesting: go get -u github.com/micro/go-micro@latest
177-
- go-version: 1.14.x
179+
- go-version: 1.15.x
178180
dirs: v3/integrations/nrnats
179181
extratesting: go get -u github.com/nats-io/nats.go/@master
180-
- go-version: 1.14.x
182+
- go-version: 1.15.x
181183
dirs: v3/integrations/nrnats/test
182184
extratesting: go get -u github.com/nats-io/nats.go/@master
183-
- go-version: 1.14.x
185+
- go-version: 1.15.x
184186
dirs: v3/integrations/nrstan
185187
extratesting: go get -u github.com/nats-io/stan.go/@master
186-
- go-version: 1.14.x
188+
- go-version: 1.15.x
187189
dirs: v3/integrations/nrstan/test
188190
extratesting: go get -u github.com/nats-io/stan.go/@master
189-
- go-version: 1.14.x
191+
- go-version: 1.15.x
190192
dirs: v3/integrations/nrstan/examples
191193
extratesting: go get -u github.com/nats-io/stan.go/@master
192-
- go-version: 1.14.x
194+
- go-version: 1.15.x
193195
dirs: v3/integrations/logcontext
194196
extratesting: go get -u github.com/sirupsen/logrus@master
195-
- go-version: 1.14.x
197+
- go-version: 1.15.x
196198
dirs: v3/integrations/nrzap
197199
extratesting: go get -u go.uber.org/zap@master
198-
- go-version: 1.14.x
200+
- go-version: 1.15.x
199201
dirs: v3/integrations/nrhttprouter
200202
extratesting: go get -u github.com/julienschmidt/httprouter@master
201-
- go-version: 1.14.x
203+
- go-version: 1.15.x
202204
dirs: v3/integrations/nrb3
203-
- go-version: 1.14.x
205+
- go-version: 1.15.x
204206
dirs: v3/integrations/nrmongo
205207
extratesting: go get -u go.mongodb.org/mongo-driver@master
206-
- go-version: 1.14.x
208+
- go-version: 1.15.x
207209
dirs: v3/integrations/nrgraphqlgo,v3/integrations/nrgraphqlgo/example
208210
extratesting: go get -u github.com/graphql-go/graphql@master
209211

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# ChangeLog
22

3+
## 3.9.0
4+
5+
### Changes
6+
* When sending Serverless telemetry using the `nrlambda` integration, support an externally-managed named pipe.
7+
38
## 3.8.1
49

510
### Bug Fixes

build-script.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
set -x
55
set -e
66

7-
LATEST_VERSION="go1.14"
7+
LATEST_VERSION="go1.15"
88

99
# NOTE: Once we get rid of travis for good, this whole section can be removed
1010
# along with the .travis.yml file.
@@ -40,8 +40,19 @@ for dir in $DIRS; do
4040
VERSION=$(go version)
4141
V17="1.7"
4242
V18="1.8"
43+
V19="1.9"
4344
if [[ "$VERSION" =~ .*"$V17".* || "$VERSION" =~ .*"$V18".* ]]; then
4445
echo "Not installing GRPC for old versions"
46+
elif [[ "$VERSION" =~ .*"$V19" ]]; then
47+
# install v3 dependencies that support this go version
48+
set +e
49+
go get -u google.golang.org/grpc # this go get will fail to build
50+
set -e
51+
cd $GOPATH/src/google.golang.org/grpc
52+
git checkout v1.31.0
53+
cd -
54+
55+
go get -u github.com/golang/protobuf/protoc-gen-go
4556
else
4657
go get -u github.com/golang/protobuf/protoc-gen-go
4758
go get -u google.golang.org/grpc

v3/integrations/nrlambda/handler.go

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"github.com/aws/aws-lambda-go/lambdacontext"
2727
"github.com/newrelic/go-agent/v3/internal"
2828
"github.com/newrelic/go-agent/v3/internal/integrationsupport"
29-
newrelic "github.com/newrelic/go-agent/v3/newrelic"
29+
"github.com/newrelic/go-agent/v3/newrelic"
3030
)
3131

3232
type response struct {
@@ -67,14 +67,37 @@ func responseEvent(ctx context.Context, event interface{}) {
6767
}
6868
}
6969

70+
type writerProvider interface {
71+
borrowWriter(needsWriter func(writer io.Writer))
72+
}
73+
74+
type defaultWriterProvider struct {
75+
}
76+
77+
const telemetryNamedPipe = "/tmp/newrelic-telemetry"
78+
79+
func (wp *defaultWriterProvider) borrowWriter(needsWriter func(io.Writer)) {
80+
// If the telemetry named pipe exists and is writable, use it instead of stdout
81+
pipeFile, err := os.OpenFile(telemetryNamedPipe, os.O_WRONLY, 0)
82+
if err != nil {
83+
needsWriter(os.Stdout)
84+
return
85+
}
86+
//We need to close the pipe; of course we don't close stdout
87+
defer pipeFile.Close()
88+
needsWriter(pipeFile)
89+
}
90+
7091
func (h *wrappedHandler) Invoke(ctx context.Context, payload []byte) ([]byte, error) {
7192
var arn, requestID string
7293
if lctx, ok := lambdacontext.FromContext(ctx); ok {
7394
arn = lctx.InvokedFunctionArn
7495
requestID = lctx.AwsRequestID
7596
}
7697

77-
defer internal.ServerlessWrite(h.app.Private, arn, h.writer)
98+
defer h.hasWriter.borrowWriter(func(writer io.Writer) {
99+
internal.ServerlessWrite(h.app.Private, arn, writer)
100+
})
78101

79102
txn := h.app.StartTransaction(h.functionName)
80103
defer txn.End()
@@ -110,9 +133,10 @@ type wrappedHandler struct {
110133
// a time, we use a synchronization primitive to determine if this is
111134
// the first transaction for defensiveness in case of future changes.
112135
firstTransaction sync.Once
113-
// writer is used to log the data JSON at the end of each transaction.
114-
// This field exists (rather than hardcoded os.Stdout) for testing.
115-
writer io.Writer
136+
// hasWriter is used to log the data JSON at the end of each transaction.
137+
// The writerProvider manages the lifecycle of the file handle being written
138+
// to, similar to the Loan pattern. This field exists mostly for testing.
139+
hasWriter writerProvider
116140
}
117141

118142
// WrapHandler wraps the provided handler and returns a new handler with
@@ -127,7 +151,7 @@ func WrapHandler(handler lambda.Handler, app *newrelic.Application) lambda.Handl
127151
original: handler,
128152
app: app,
129153
functionName: lambdacontext.FunctionName,
130-
writer: os.Stdout,
154+
hasWriter: &defaultWriterProvider{},
131155
}
132156
}
133157

v3/integrations/nrlambda/handler_test.go

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import (
88
"context"
99
"encoding/json"
1010
"errors"
11+
"io"
1112
"net/http"
13+
"os"
1214
"strings"
1315
"testing"
1416

@@ -45,14 +47,23 @@ func distributedTracingEnabled(key string) string {
4547
}
4648
}
4749

50+
// bufWriterProvider is a testing implementation of writerProvider
51+
type bufWriterProvider struct {
52+
buf io.Writer
53+
}
54+
55+
func (bw bufWriterProvider) borrowWriter(needsWriter func(writer io.Writer)) {
56+
needsWriter(bw.buf)
57+
}
58+
4859
func TestColdStart(t *testing.T) {
4960
originalHandler := func(c context.Context) {}
5061
app := testApp(nil, t)
5162
wrapped := Wrap(originalHandler, app)
5263
w := wrapped.(*wrappedHandler)
5364
w.functionName = "functionName"
5465
buf := &bytes.Buffer{}
55-
w.writer = buf
66+
w.hasWriter = bufWriterProvider{buf}
5667

5768
ctx := context.Background()
5869
lctx := &lambdacontext.LambdaContext{
@@ -104,7 +115,7 @@ func TestColdStart(t *testing.T) {
104115

105116
// Invoke the handler again to test the cold-start attribute absence.
106117
buf = &bytes.Buffer{}
107-
w.writer = buf
118+
w.hasWriter = bufWriterProvider{buf}
108119
internal.HarvestTesting(app.Private, nil)
109120
resp, err = wrapped.Invoke(ctx, nil)
110121
if nil != err || string(resp) != "null" {
@@ -154,7 +165,7 @@ func TestErrorCapture(t *testing.T) {
154165
w := wrapped.(*wrappedHandler)
155166
w.functionName = "functionName"
156167
buf := &bytes.Buffer{}
157-
w.writer = buf
168+
w.hasWriter = bufWriterProvider{buf}
158169

159170
resp, err := wrapped.Invoke(context.Background(), nil)
160171
if err != returnError || string(resp) != "" {
@@ -229,7 +240,7 @@ func TestSetWebRequest(t *testing.T) {
229240
w := wrapped.(*wrappedHandler)
230241
w.functionName = "functionName"
231242
buf := &bytes.Buffer{}
232-
w.writer = buf
243+
w.hasWriter = bufWriterProvider{buf}
233244

234245
req := events.APIGatewayProxyRequest{
235246
Headers: map[string]string{
@@ -301,7 +312,7 @@ func TestDistributedTracing(t *testing.T) {
301312
w := wrapped.(*wrappedHandler)
302313
w.functionName = "functionName"
303314
buf := &bytes.Buffer{}
304-
w.writer = buf
315+
w.hasWriter = bufWriterProvider{buf}
305316

306317
dtHdr := http.Header{}
307318
app.StartTransaction("hello").InsertDistributedTraceHeaders(dtHdr)
@@ -396,7 +407,7 @@ func TestEventARN(t *testing.T) {
396407
w := wrapped.(*wrappedHandler)
397408
w.functionName = "functionName"
398409
buf := &bytes.Buffer{}
399-
w.writer = buf
410+
w.hasWriter = bufWriterProvider{buf}
400411

401412
req := events.DynamoDBEvent{
402413
Records: []events.DynamoDBEventRecord{{
@@ -473,7 +484,7 @@ func TestAPIGatewayProxyResponse(t *testing.T) {
473484
w := wrapped.(*wrappedHandler)
474485
w.functionName = "functionName"
475486
buf := &bytes.Buffer{}
476-
w.writer = buf
487+
w.hasWriter = bufWriterProvider{buf}
477488

478489
resp, err := wrapped.Invoke(context.Background(), nil)
479490
if nil != err {
@@ -535,7 +546,7 @@ func TestCustomEvent(t *testing.T) {
535546
w := wrapped.(*wrappedHandler)
536547
w.functionName = "functionName"
537548
buf := &bytes.Buffer{}
538-
w.writer = buf
549+
w.hasWriter = bufWriterProvider{buf}
539550

540551
resp, err := wrapped.Invoke(context.Background(), nil)
541552
if nil != err || string(resp) != "null" {
@@ -555,3 +566,30 @@ func TestCustomEvent(t *testing.T) {
555566
t.Error("no output written")
556567
}
557568
}
569+
570+
func TestDefaultWriterProvider(t *testing.T) {
571+
dwp := defaultWriterProvider{}
572+
dwp.borrowWriter(func(writer io.Writer) {
573+
if writer != os.Stdout {
574+
t.Error("Expected stdout")
575+
}
576+
})
577+
578+
const telemetryFile = "/tmp/newrelic-telemetry"
579+
defer os.Remove(telemetryFile)
580+
file, err := os.Create(telemetryFile)
581+
if err != nil {
582+
t.Error("Unexpected error creating telemetry file", err)
583+
}
584+
585+
err = file.Close()
586+
if err != nil {
587+
t.Error("Error closing telemetry file", err)
588+
}
589+
590+
dwp.borrowWriter(func(writer io.Writer) {
591+
if writer == os.Stdout {
592+
t.Error("Expected telemetry file, got stdout")
593+
}
594+
})
595+
}

v3/newrelic/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
const (
1313
// Version is the full string version of this Go Agent.
14-
Version = "3.8.1"
14+
Version = "3.9.0"
1515
)
1616

1717
var (

0 commit comments

Comments
 (0)