Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Transaction with multiple http calls

go-agent
open_source

#1

Hi I’m trying to work with DistributedTrace in my Go micro services, but it seems it cannot trace http calls to multiple services as one transaction.
I have. middleware that wraps every call with transaction:

name := routeName(r)
txn := app.StartTransaction(name)
defer txn.End()
txn.SetWebRequestHTTP(r)
w = txn.SetWebResponse(w)
r = newrelic.RequestWithTransactionContext(r, txn)
next.ServeHTTP(w, r)

and I put this transaction into call to another service:

client := &http.Client{}
txn := newrelic.FromContext(ctx)
client.Transport = newrelic.NewRoundTripper(txn, client.Transport)
req = newrelic.RequestWithTransactionContext(req, txn)
resp, err := client.Do(req)

but NewRelic One aggregates only calls to the DB and every http call seems to be separate transaction.


#2

Hi @eugene_gartstein - Is your middleware also monitored by New Relic APM?


#3

Yes, it’s a part of the service where I created an agent

   newRelic, err := newrelic.NewApplication(
    		newrelic.ConfigAppName(reg.ServiceConfiguration.ServiceName),
    		newrelic.ConfigLicense(newRelicKey),
    		newrelic.ConfigDistributedTracerEnabled(true),
    		nrlogrus.ConfigLogger(lg),
    	)

and use this newRelic app as middleware for my router:

router.Use(nrgorilla.Middleware(newRelic))

#4

Have you checked that the Distributed Tracing is switched on for all your agents? If you have and the agents have been restarted then you will need someone from New Relic support to assist as I do not have experience with Go agents.


#5

It is enabled, and I can see results of the tracing, but aggregation of the spans is not correct.
I send request to the service and during processing of this request micro service sends a few requests to another services that have Distributed Tracing switched on.
And I see all those requests and I want them to be aggregated by one traceID.
But now I call microservice that sends a few requests to the DB and a few requests to other services and Distributed Tracing tool shows me a few calls to different services with a few DB spans as a separate transactions


#6

@eugene_gartstein -

I don’t see anything obviously wrong with the code snippets you have provided. It looks like everything is in place to propagate the DT info across services.

Would you include a few New Relic links to traces that demonstrate the issue? For example a link to a root service trace and then links to micro-service traces that should have the same traceId as the root service. Only, New Relic Support will be able to see those links.

You also might want to gather agent debug logs on both the calling and called services to see if any interesting DT related log entries show up. See https://docs.newrelic.com/docs/agents/go-agent/configuration/go-agent-logging for info on gathering logs.


#7

Thanks for your reply, but it was a mistake of a simple misunderstanding of the documentation.
From the documentation I understood that:

txn := newrelic.FromContext(ctx)
client.Transport = newrelic.NewRoundTripper(client.Transport)
r = newrelic.RequestWithTransactionContext(r, txn)

Will insert headers for Distributed Tracing but it appears I have to add another one line in order to make it work:

txn.InsertDistributedTraceHeaders(r.Header)