Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 3.25.0 #782

Merged
merged 27 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8339965
minor fix for complete security disable flag
aayush-ap Aug 22, 2023
f999c57
Create FastHTTP Client Functions
mirackara Aug 25, 2023
79146fb
FastHTTP Request Integration
mirackara Aug 25, 2023
a36c213
FastHTTP example file
mirackara Aug 25, 2023
dd7d252
FastHTTP Request Integration
mirackara Aug 25, 2023
fc0b173
FastHTTP Response file
mirackara Aug 25, 2023
3108963
mod file
mirackara Aug 25, 2023
19abf99
update security agent version
aayush-ap Aug 28, 2023
55af84a
supportability metric
mirackara Aug 28, 2023
349fe30
Created unit tests and removed extraneous file
mirackara Aug 28, 2023
7d31904
Merge pull request #775 from k2io/develop
nr-swilloughby Sep 1, 2023
7f56709
Moved FastHTTP to internal instrumentation
mirackara Sep 6, 2023
de5ca15
Added testing for errors
mirackara Sep 7, 2023
607c734
chore: add logs-in-context example with logrus
Julien4218 Sep 11, 2023
5115a58
chore: move example to specific folder
Julien4218 Sep 11, 2023
f1750de
FastHTTP external segments/Client example
mirackara Sep 12, 2023
ef22a97
License for Server Example
mirackara Sep 12, 2023
0afb8ac
Merge pull request #778 from Julien4218/chore/add-lic-example
iamemilio Sep 12, 2023
aed3dde
Added test for external segment/minor fixes
mirackara Sep 14, 2023
5b2310b
FastHTTP Integration (#774)
mirackara Sep 14, 2023
09b6fac
V3.25.0 Changelog (#781)
mirackara Sep 14, 2023
ba9626f
corrected changelog for 3.25 release
nr-swilloughby Sep 14, 2023
7b8fc65
Merge pull request #783 from nr-swilloughby/3_25_changelog_fix
nr-swilloughby Sep 15, 2023
31ecf8c
Fixed test not passing
mirackara Sep 18, 2023
973d7cf
Merge branch 'develop' into fasthttpfixes
mirackara Sep 18, 2023
1488692
Update segments.go
mirackara Sep 18, 2023
25fcdc3
Merge pull request #784 from mirackara/fasthttpfixes
iamemilio Sep 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
## 3.25.0
### Added
* Added Support for FastHTTP package
* Added newrelic.WrapHandleFuncFastHTTP() and newrelic.StartExternalSegmentFastHTTP() functions to instrument fasthttp context and create wrapped handlers. These functions work similarly to the existing ones for net/http
* Added client-fasthttp and server-fasthttp examples to help get started with FastHTTP integration

### Fixed
* Corrected a bug where the security agent failed to correctly parse the `NEW_RELIC_SECURITY_AGENT_ENABLED` environment variable.

### Support statement
We use the latest version of the Go language. At minimum, you should be using no version of Go older than what is supported by the Go team themselves (i.e., Go versions 1.19 and later are supported).
We recommend updating to the latest agent version as soon as it’s available. If you can’t upgrade to the latest version, update your agents to a version no more than 90 days old. Read more about keeping agents up to date. (https://docs.newrelic.com/docs/new-relic-solutions/new-relic-one/install-configure/update-new-relic-agent/)
See the [Go agent EOL Policy](/docs/apm/agents/go-agent/get-started/go-agent-eol-policy/) for details about supported versions of the Go agent and third-party components.

## 3.24.1
### Fixed
* Performance improvement around calls to security agent. In some cases, unnecessary setup operations were being performed even if there was no security agent present to use that. These are now conditional on the security agent being present in the application (note that this will enable the setup code if the security agent is *present* in the application, regardless of whether it's currently enabled to run). This affects:
* Base agent code (updated to v3.24.1)
* `nrmongo` integration (updated to v1.1.1)
* Resolved a race condition caused by the above-mentioned calls to the security agent.

* Fixed unit tests for integrations which were failing because code level metrics are enabled by default now:
* `nrawssdk-v1` (updated to v1.1.2)
* `nrawssdk-v2` (updated to v1.2.2)
* `nrecho-v3` (updated to v1.0.2)
* `nrecho-v4` (updated to v1.0.4)
* `nrhttprouter` (updated to
* `nrhttprouter` (updated to v1.0.2)
* `nrlambda` (updated to v1.2.2)
* `nrnats` (updated to v1.1.5)
* `nrredis-v8` (updated to v1.0.1)
Expand Down
62 changes: 62 additions & 0 deletions v3/examples/client-fasthttp/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2020 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package main

import (
"fmt"
"os"
"time"

newrelic "github.com/newrelic/go-agent/v3/newrelic"
"github.com/valyala/fasthttp"
)

func doRequest(txn *newrelic.Transaction) error {
req := fasthttp.AcquireRequest()
resp := fasthttp.AcquireResponse()
defer fasthttp.ReleaseRequest(req)
defer fasthttp.ReleaseResponse(resp)

req.SetRequestURI("http://localhost:8080/hello")
req.Header.SetMethod("GET")

ctx := &fasthttp.RequestCtx{}
seg := newrelic.StartExternalSegmentFastHTTP(txn, ctx)
defer seg.End()

err := fasthttp.Do(req, resp)
if err != nil {
return err
}

fmt.Println("Response Code is ", resp.StatusCode())
return nil

}

func main() {
app, err := newrelic.NewApplication(
newrelic.ConfigAppName("Client App"),
newrelic.ConfigLicense(os.Getenv("NEW_RELIC_LICENSE_KEY")),
newrelic.ConfigDebugLogger(os.Stdout),
newrelic.ConfigDistributedTracerEnabled(true),
)

if err := app.WaitForConnection(5 * time.Second); nil != err {
fmt.Println(err)
}
if err != nil {
fmt.Println(err)
os.Exit(1)
}

txn := app.StartTransaction("client-txn")
err = doRequest(txn)
if err != nil {
txn.NoticeError(err)
}
txn.End()

// Shut down the application to flush data to New Relic.
app.Shutdown(10 * time.Second)
}
58 changes: 58 additions & 0 deletions v3/examples/server-fasthttp/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2020 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package main

import (
"errors"
"fmt"
"os"
"time"

newrelic "github.com/newrelic/go-agent/v3/newrelic"

"github.com/valyala/fasthttp"
)

func index(ctx *fasthttp.RequestCtx) {
ctx.WriteString("Hello World")
}

func noticeError(ctx *fasthttp.RequestCtx) {
ctx.WriteString("noticing an error")
txn := ctx.UserValue("transaction").(*newrelic.Transaction)
txn.NoticeError(errors.New("my error message"))
}

func main() {
// Initialize New Relic
app, err := newrelic.NewApplication(
newrelic.ConfigAppName("FastHTTP App"),
newrelic.ConfigLicense(os.Getenv("NEW_RELIC_LICENSE_KEY")),
newrelic.ConfigDebugLogger(os.Stdout),
newrelic.ConfigDistributedTracerEnabled(true),
)
if err != nil {
fmt.Println(err)
return
}
if err := app.WaitForConnection(5 * time.Second); nil != err {
fmt.Println(err)
}
_, helloRoute := newrelic.WrapHandleFuncFastHTTP(app, "/hello", index)
_, errorRoute := newrelic.WrapHandleFuncFastHTTP(app, "/error", noticeError)
handler := func(ctx *fasthttp.RequestCtx) {
path := string(ctx.Path())
method := string(ctx.Method())

switch {
case method == "GET" && path == "/hello":
helloRoute(ctx)
case method == "GET" && path == "/error":
errorRoute(ctx)
}
}

// Start the server with the instrumented handler
fasthttp.ListenAndServe(":8080", handler)
}
1 change: 1 addition & 0 deletions v3/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.19

require (
github.com/golang/protobuf v1.5.3
github.com/valyala/fasthttp v1.49.0
google.golang.org/grpc v1.54.0
)

Expand Down
9 changes: 9 additions & 0 deletions v3/integrations/nrfasthttp/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module github.com/newrelic/go-agent/v3/integrations/nrfasthttp

go 1.19

require (
github.com/newrelic/go-agent/v3 v3.23.1
github.com/stretchr/testify v1.8.4
github.com/valyala/fasthttp v1.48.0
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Copyright 2020 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

// An application that illustrates Distributed Tracing with Logs-in-Context
// when using http.Server or similar frameworks.
package main

import (
"context"
"fmt"
"io"
"net/http"
"os"
"time"

"github.com/newrelic/go-agent/v3/integrations/logcontext-v2/nrlogrus"
newrelic "github.com/newrelic/go-agent/v3/newrelic"
"github.com/sirupsen/logrus"
)

type handler struct {
App *newrelic.Application
}

func (h *handler) ServeHTTP(writer http.ResponseWriter, req *http.Request) {
// The call to StartTransaction must include the response writer and the
// request.
txn := h.App.StartTransaction("server-txn")
defer txn.End()

txnLogger := logrus.WithContext(newrelic.NewContext(context.Background(), txn))

writer = txn.SetWebResponse(writer)
txn.SetWebRequestHTTP(req)

if req.URL.String() == "/segments" {
defer txn.StartSegment("f1").End()

txnLogger.Infof("/segments just started")

func() {
defer txn.StartSegment("f2").End()

io.WriteString(writer, "segments!")
time.Sleep(10 * time.Millisecond)

txnLogger.Infof("segment func just about to complete")
}()
time.Sleep(10 * time.Millisecond)
} else {
// Transaction.WriteHeader has to be used instead of invoking
// WriteHeader on the response writer.
writer.WriteHeader(http.StatusNotFound)
}
txnLogger.Infof("handler completing")
}

func makeApplication() (*newrelic.Application, error) {
app, err := newrelic.NewApplication(
newrelic.ConfigAppName("HTTP Server App"),
newrelic.ConfigLicense(os.Getenv("NEW_RELIC_LICENSE_KEY")),
)
if nil != err {
return nil, err
}
nrlogrusFormatter := nrlogrus.NewFormatter(app, &logrus.TextFormatter{})
logrus.SetFormatter(nrlogrusFormatter)
// Alternatively and if preferred, create a new logger and use that logger
// for logging with
// log := logrus.New()
// log.SetFormatter(nrlogrusFormatter)

// Wait for the application to connect.
if err = app.WaitForConnection(5 * time.Second); nil != err {
return nil, err
}

return app, nil
}

func main() {

app, err := makeApplication()
if nil != err {
fmt.Println(err)
os.Exit(1)
}

logrus.Infof("Application Starting")

server := http.Server{
Addr: ":8000",
Handler: &handler{App: app},
}

server.ListenAndServe()
}
2 changes: 1 addition & 1 deletion v3/integrations/nrsecurityagent/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/newrelic/go-agent/v3/integrations/nrsecurityagent
go 1.19

require (
github.com/newrelic/csec-go-agent v0.3.0
github.com/newrelic/csec-go-agent v0.4.0
github.com/newrelic/go-agent/v3 v3.24.1
github.com/newrelic/go-agent/v3/integrations/nrsqlite3 v1.2.0
gopkg.in/yaml.v2 v2.4.0
Expand Down
2 changes: 1 addition & 1 deletion v3/integrations/nrsecurityagent/nrsecurityagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func defaultSecurityConfig() SecurityConfig {
// If env is set to false,the security module is not loaded
func isSecurityAgentEnabled() bool {
if env := os.Getenv("NEW_RELIC_SECURITY_AGENT_ENABLED"); env != "" {
if b, err := strconv.ParseBool("false"); err == nil {
if b, err := strconv.ParseBool(env); err == nil {
return b
}
}
Expand Down
14 changes: 14 additions & 0 deletions v3/newrelic/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"

"github.com/newrelic/go-agent/v3/internal"
"github.com/valyala/fasthttp"
)

// NewContext returns a new context.Context that carries the provided
Expand Down Expand Up @@ -52,3 +53,16 @@ func transactionFromRequestContext(req *http.Request) *Transaction {
}
return txn
}

func transactionFromRequestContextFastHTTP(ctx *fasthttp.RequestCtx) *Transaction {
var txn *Transaction
if nil != ctx {
txn := ctx.UserValue("transaction").(*Transaction)
return txn
}

if txn != nil {
return txn
}
return nil
}
Loading
Loading