census-instrumentation / opencensus-specs

Apache License 2.0
188 stars 50 forks source link

Trace should Ignore Options method and specific paths #251

Open Talento90 opened 5 years ago

Talento90 commented 5 years ago

First of all thanks for this amazing project. I am using tracing to stackdriver and I would like to know How can I ignore http OPTION method and also some specific paths like /swagger or /.

For your info I am using ochttp to instrument my http server.

    return &http.Server{
        Handler:      &ochttp.Handler{Handler: router },
    }
Talento90 commented 5 years ago

It seems that using GetStartOptions it ignores the OPTIONS method but not the "/" path :(

Handler: &ochttp.Handler{
    Handler: router,
    GetStartOptions: func(r *http.Request) trace.StartOptions {
        if r.Method == http.MethodOptions || r.URL.Path == "/" {
            return trace.StartOptions{
                Sampler:  trace.NeverSample(),
                SpanKind: trace.SpanKindServer,
            }
        }

        return trace.StartOptions{
            Sampler:  trace.AlwaysSample(),
            SpanKind: trace.SpanKindServer,
        }
    },
},