TODO(sszuecs): copy from net.Client, we should refactor this to use net.Client
(req *http.Request, span ot.Span)
| 1964 | |
| 1965 | // TODO(sszuecs): copy from net.Client, we should refactor this to use net.Client |
| 1966 | func injectClientTraceByEvent(req *http.Request, span ot.Span) *http.Request { |
| 1967 | trace := &httptrace.ClientTrace{ |
| 1968 | DNSStart: func(httptrace.DNSStartInfo) { |
| 1969 | span.LogKV(ClientTraceDNS) |
| 1970 | }, |
| 1971 | DNSDone: func(httptrace.DNSDoneInfo) { |
| 1972 | span.LogKV(ClientTraceDNS, EndEvent) |
| 1973 | }, |
| 1974 | ConnectStart: func(string, string) { |
| 1975 | span.LogKV(ClientTraceConnect, StartEvent) |
| 1976 | }, |
| 1977 | ConnectDone: func(string, string, error) { |
| 1978 | span.LogKV(ClientTraceConnect, EndEvent) |
| 1979 | }, |
| 1980 | TLSHandshakeStart: func() { |
| 1981 | span.LogKV(ClientTraceTLS, StartEvent) |
| 1982 | }, |
| 1983 | TLSHandshakeDone: func(tls.ConnectionState, error) { |
| 1984 | span.LogKV(ClientTraceTLS, EndEvent) |
| 1985 | }, |
| 1986 | GetConn: func(string) { |
| 1987 | span.LogKV(ClientTraceGetConn, StartEvent) |
| 1988 | }, |
| 1989 | GotConn: func(httptrace.GotConnInfo) { |
| 1990 | span.LogKV(ClientTraceGetConn, EndEvent) |
| 1991 | }, |
| 1992 | WroteHeaders: func() { |
| 1993 | span.LogKV(ClientTraceWroteHeaders, EndEvent) |
| 1994 | }, |
| 1995 | WroteRequest: func(wri httptrace.WroteRequestInfo) { |
| 1996 | if wri.Err != nil { |
| 1997 | span.LogKV(ClientTraceWroteRequest, ensureUTF8(wri.Err.Error())) |
| 1998 | } else { |
| 1999 | span.LogKV(ClientTraceWroteRequest, EndEvent) |
| 2000 | } |
| 2001 | }, |
| 2002 | GotFirstResponseByte: func() { |
| 2003 | span.LogKV(ClientTraceGotFirstByte, EndEvent) |
| 2004 | }, |
| 2005 | } |
| 2006 | return req.WithContext(httptrace.WithClientTrace(req.Context(), trace)) |
| 2007 | } |
| 2008 | |
| 2009 | func ensureUTF8(s string) string { |
| 2010 | if utf8.ValidString(s) { |
no test coverage detected
searching dependent graphs…