-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* minor fix for complete security disable flag * Create FastHTTP Client Functions * FastHTTP Request Integration * FastHTTP example file * FastHTTP Request Integration * FastHTTP Response file * mod file * update security agent version * supportability metric * Created unit tests and removed extraneous file * Moved FastHTTP to internal instrumentation * Added testing for errors * chore: add logs-in-context example with logrus * chore: move example to specific folder * FastHTTP external segments/Client example * License for Server Example * Added test for external segment/minor fixes * FastHTTP Integration (#774) Added Support For FastHTTP * V3.25.0 Changelog (#781) * V3.25.0 * update version * corrected changelog for 3.25 release * Fixed test not passing * Update segments.go Removed extra function --------- Co-authored-by: aayush-ap <agarg@newrelic.com> Co-authored-by: Steve Willoughby <76975199+nr-swilloughby@users.noreply.github.com> Co-authored-by: Julien Erard <jerard@newrelic.com> Co-authored-by: Emilio Garcia <iamemilio@users.noreply.github.com> Co-authored-by: Steve Willoughby <swilloughby@newrelic.com>
- Loading branch information
1 parent
d59f46c
commit a8c6bf8
Showing
15 changed files
with
447 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
97 changes: 97 additions & 0 deletions
97
v3/integrations/nrlogrus/examples/server-http-logs-in-context/main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.