If we have http handler as entry point, everything is okay, and we have full trace, but if it in workers (for example), we have only transaction name and that's all.
I think that I misunderstand official docs part about transactions and spans, and it would be great if anyone could help me
And also I have another few questions:
- For what purpose we need spanType as third argument in startSpan() call (haven't find anything about it in docs).
- How to make available transaction result of worker running? In case that we have http call it's clear - we got http code, but what to do in this case? Should I write transaction.Result by myself and write errors like in bottom example?
HTTP handler example:
package main
import (
"context"
"net/http"
"go.elastic.co/apm"
)
func handler(r *http.Request, w http.ResponseWriter) {
example(r.Context())
//do something else
}
func example(ctx context.Context) {
span, apmCtx := apm.StartSpan(ctx, "example", "")
defer span.End()
//do something
}
Example of worker:
package main
import (
"context"
"go.elastic.co/apm"
)
func worker(ctx context.Context, msgs <-chan amqp.Delivery) error {
for m := range msgs {
transaction := app.Tracer().StartTransaction("my-worker-name", "worker")
transactionCtx := apm.ContextWithTransaction(ctx, transaction)
err := example(transactionCtx)
if err != nil {
//do something
}
} //range over messages from RabbitMQ
}
func example(ctx context.Context) error {
span, apmCtx := apm.StartSpan(ctx, "example", "")
defer span.End()
//do something
}
In result we got next things: If example() func calling from http handler, we see it in trace, otherwise - we don't (in our case, if we call it in worker)
Error send example:
apmErr := apm.CaptureError(transactionCtx, err)
apmErr.Send()