census-instrumentation / opencensus-go

A stats collection and distributed tracing framework
http://opencensus.io
Apache License 2.0
2.06k stars 327 forks source link

ochttp.NewSpanAnnotator doesn't work #861

Closed rakyll closed 6 years ago

rakyll commented 6 years ago

If ochttp.NewSpanAnnotator is used, I cannot see any outgoing spans in the trace. I was expecting to see a client span with some annotations representing the networking events.

Program to reproduce:

// Package contains a small demo that records
// network event details as a part of HTTP traces.
package main

import (
    "fmt"
    "log"
    "net/http"

    "contrib.go.opencensus.io/exporter/stackdriver"
    "contrib.go.opencensus.io/exporter/stackdriver/propagation"
    "go.opencensus.io/plugin/ochttp"
    "go.opencensus.io/trace"
    "go.opencensus.io/zpages"
)

func main() {
    se, err := stackdriver.NewExporter(stackdriver.Options{
        ProjectID: "bamboo-shift-504",
    })
    if err != nil {
        log.Fatal(err)
    }
    trace.RegisterExporter(se)

    client := &http.Client{
        Transport: &ochttp.Transport{
            NewClientTrace: ochttp.NewSpanAnnotator,
        },
    }

    mux := http.NewServeMux()
    zpages.Handle(mux, "/debug")

    mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        req, _ := http.NewRequest("GET", "http://google.com", nil)
        req = req.WithContext(r.Context())

        client.Do(req)
        fmt.Fprint(w, "Welcome!")
    })

    http.ListenAndServe(":8080", &ochttp.Handler{
        Handler:     mux,
        Propagation: &propagation.HTTPFormat{},
        StartOptions: trace.StartOptions{
            Sampler: trace.AlwaysSample(),
        },
    })
}

/cc @basvanbeek

rakyll commented 6 years ago

There was a problem with my UI and I spoke too soon and blamed the NewSpanAnnotator. Sorry for the noise.