Comments (3)
@antonholmquist
Roughly it would look something like this:
https://gist.github.com/ianomad/4bb66617316836131e2f62e3d0abfdbd
I didn't try to run it locally, just in case.
from go-agent.
Great! Seems to work :) One thing, it should be fmt.Sprintf
instead of fmt.Sprint
on line 21. And by the way, the path doesn't include the query params, wouldn't you recommend adding this to the transaction name?
Also, maybe this this be added to the docs somewhere?
from go-agent.
Hi antonholmquist
Supposing you are using negroni just like the getting started example here:
(https://github.com/urfave/negroni#getting-started) you have a couple options:
- You can add instrumentation to select routes when registering them with your
mux.
func main() {
config := newrelic.NewConfig("negroni example", "__LICENSE_KEY__")
config.Logger = newrelic.NewDebugLogger(os.Stdout)
app, err := newrelic.NewApplication(config)
if nil != err {
fmt.Println(err)
os.Exit(1)
}
mux := http.NewServeMux()
mux.HandleFunc(newrelic.WrapHandleFunc(app, "/", func(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "Welcome to the home page!")
}))
n := negroni.Classic() // Includes some default middlewares
n.UseHandler(mux)
http.ListenAndServe(":3000", n)
}
- You can replace the mux with another mux that adds the instrumentation:
type wrapMux struct {
app newrelic.Application
original *http.ServeMux
}
func (mux wrapMux) Handle(p string, h http.Handler) {
mux.original.Handle(newrelic.WrapHandle(mux.app, p, h))
}
func (mux wrapMux) HandleFunc(p string, h func(http.ResponseWriter, *http.Request)) {
mux.original.HandleFunc(newrelic.WrapHandleFunc(mux.app, p, h))
}
func (mux wrapMux) Handler(r *http.Request) (h http.Handler, p string) {
return mux.original.Handler(r)
}
func (mux wrapMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
mux.original.ServeHTTP(w, r)
}
func main() {
config := newrelic.NewConfig("negroni example", "__LICENSE_KEY__")
config.Logger = newrelic.NewDebugLogger(os.Stdout)
app, err := newrelic.NewApplication(config)
if nil != err {
fmt.Println(err)
os.Exit(1)
}
mux := wrapMux{
original: http.NewServeMux(),
app: app,
}
mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "Welcome to the home page!")
})
n := negroni.Classic() // Includes some default middlewares
n.UseHandler(mux)
http.ListenAndServe(":3000", n)
}
- You can introduce a negroni middleware to add the instrumentation, as
demonstrated by the example from @ianomad. Unfortunately, this approach
necessitates naming the transaction using properties of the request (or
having a single transaction name). As @mikegleasonjr said, using the path as
the transaction name has the downside that it could lead to an explosion of
transaction names. Though is not a concern if the app is a backend service
(and the consumers will definitely not make requests with spurious paths), we
generally don't recommend it. For the same reason, using the query params
in the transaction name is not recommended.
I hope this helps.
from go-agent.
Related Issues (20)
- Consumes a lot of memory during large body size requests HOT 2
- External Services(AWS sdk go v2 ) api calls are not logged / visible when using github.com/newrelic/go-agent/v3/integrations/nrawssdk-v HOT 3
- Remove fasthttp dependency from main module HOT 2
- Update google.golang.org/grpc from 1.54.0 to 1.56.3 HOT 2
- transaction.go reqBody(req *http.Request) turn nil body into non Nil body for request.Body == http.NoBody HOT 1
- Add support to CopyFrom method in pgx integration HOT 1
- fmt.Stringer support for user attributes (especially for SQL query parameters)
- UNKNOWN log levels when using the native log package HOT 2
- `.Ignore()` not ignoring transaction (go-agent + nrgin) HOT 6
- Integration for gqlgen HOT 2
- nrpgx5 data-race HOT 5
- Changelog Go agent EOL Policy link is broken HOT 1
- agent with nrzap is not forwarding logs to newrelic HOT 3
- WrapBackgroundCore background logger is not sending logs to new relic but transaction logger is HOT 12
- zap logger.With log message properties are not sent to new relic HOT 4
- Attributes are not forwarded to NewRelic for logs HOT 16
- go agent , but not see span, please help me ,thanks HOT 3
- Specify service version during initial newrelic configuration HOT 6
- Possible memory leak in Go agent HOT 11
- How to use AWS Lambda Web Adapter in golang app
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-agent.