I want to trace the whole project with Opencensus and Jaeger. I added HTTP trace in entry services and add stratspan
in middleware surrounded whol my services and this two-span called and show on Jaeger. My problem is each service contain a lot of function and I want see a trace of all my functions but in this way not show overall service not shown each function. I don't like add per function add one stratspan
. I use ctx context.Context
entry all my function but not different!
Asked
Active
Viewed 133 times
1

Mahmoud Masih Tehrani
- 319
- 1
- 2
- 8
1 Answers
0
There's really not many options for other than starting a span in each function you'd like to instrument:
func something(ctx context.Context) {
ctx, span := trace.StartSpan(ctx, "something")
defer span.End()
}
If your functions have a common call signature, or you can coalesce your function into a common call signature, you can write a wrapper. Examples of this can be seen in http "middleware".
Consider the http.Handler, you could write a decorator for your functions that handles the span lifecycle:
func WithTraced(handler http.Handler, opName string) http.Handler {
return func(w http.ResponseWriter, r *http.Request) {
ctx, span := trace.StartSpan(ctx, opName)
defer span.End()
handler.ServeHTTP(w, r.WithContext(ctx))
}
}
A similar pattern could be applied by embedding structs.

dm03514
- 54,664
- 18
- 108
- 145
-
I used Gokit with the same yo middleware `opencensus.TraceEndpoint('service_name')` of package `github.com/go-kit/kit/tracing/opencensus` this use same your way use middleware surrounded all services functions but just add one span not per function one span! – Mahmoud Masih Tehrani Mar 28 '20 at 11:58