in step1/src/client/main.go [57:95]
func (cs *clientService) handler(w http.ResponseWriter, r *http.Request) {
// NOTE: do not pass the raw query in production systems.
rawQuery := r.URL.Query().Get("q")
query, err := url.QueryUnescape(rawQuery)
if err != nil {
writeError(w, fmt.Sprintf("can't unescape the query: %s", rawQuery))
return
}
ctx := r.Context()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
// step1. instrument trace
span := trace.SpanFromContext(ctx)
defer span.End()
// step1. end instrument
cli := shakesapp.NewShakespeareServiceClient(cs.serverSvcConn)
resp, err := cli.GetMatchCount(ctx, &shakesapp.ShakespeareRequest{
Query: query,
})
if err != nil {
writeError(w, fmt.Sprintf("error calling GetMatchCount: %v", err))
return
}
ret, err := json.Marshal(resp)
if err != nil {
writeError(w, fmt.Sprintf("error marshalling data: %v", err))
return
}
// step1. add span specific attribute
span.SetAttributes(attribute.Key("matched").Int64(resp.MatchCount))
// step1. end adding attribute
log.Println(string(ret))
if _, err = w.Write(ret); err != nil {
writeError(w, fmt.Sprintf("error on writing response: %v", err))
return
}
}