@@ -63,7 +63,7 @@ func NewOriginProxy(
6363// a simple roundtrip or a tcp/websocket dial depending on ingres rule setup.
6464func (p * Proxy ) ProxyHTTP (
6565 w connection.ResponseWriter ,
66- tr * tracing.TracedRequest ,
66+ tr * tracing.TracedHTTPRequest ,
6767 isWebsocket bool ,
6868) error {
6969 incrementRequests ()
@@ -108,7 +108,7 @@ func (p *Proxy) ProxyHTTP(
108108 }
109109
110110 rws := connection .NewHTTPResponseReadWriterAcker (w , req )
111- if err := p .proxyStream (req . Context (), rws , dest , originProxy ); err != nil {
111+ if err := p .proxyStream (tr . ToTracedContext (), rws , dest , originProxy ); err != nil {
112112 rule , srv := ruleField (p .ingressRules , ruleNum )
113113 p .logRequestError (err , cfRay , "" , rule , srv )
114114 return err
@@ -137,9 +137,11 @@ func (p *Proxy) ProxyTCP(
137137 serveCtx , cancel := context .WithCancel (ctx )
138138 defer cancel ()
139139
140+ tracedCtx := tracing .NewTracedContext (serveCtx , req .CfTraceID , p .log )
141+
140142 p .log .Debug ().Str (LogFieldFlowID , req .FlowID ).Msg ("tcp proxy stream started" )
141143
142- if err := p .proxyStream (serveCtx , rwa , req .Dest , p .warpRouting .Proxy ); err != nil {
144+ if err := p .proxyStream (tracedCtx , rwa , req .Dest , p .warpRouting .Proxy ); err != nil {
143145 p .logRequestError (err , req .CFRay , req .FlowID , "" , ingress .ServiceWarpRouting )
144146 return err
145147 }
@@ -160,7 +162,7 @@ func ruleField(ing ingress.Ingress, ruleNum int) (ruleID string, srv string) {
160162// ProxyHTTPRequest proxies requests of underlying type http and websocket to the origin service.
161163func (p * Proxy ) proxyHTTPRequest (
162164 w connection.ResponseWriter ,
163- tr * tracing.TracedRequest ,
165+ tr * tracing.TracedHTTPRequest ,
164166 httpService ingress.HTTPOriginProxy ,
165167 isWebsocket bool ,
166168 disableChunkedEncoding bool ,
@@ -211,7 +213,7 @@ func (p *Proxy) proxyHTTPRequest(
211213 }
212214
213215 // Add spans to response header (if available)
214- tr .AddSpans (resp .Header , p . log )
216+ tr .AddSpans (resp .Header )
215217
216218 err = w .WriteRespHeaders (resp .StatusCode , resp .Header )
217219 if err != nil {
@@ -248,17 +250,23 @@ func (p *Proxy) proxyHTTPRequest(
248250// proxyStream proxies type TCP and other underlying types if the connection is defined as a stream oriented
249251// ingress rule.
250252func (p * Proxy ) proxyStream (
251- ctx context. Context ,
253+ tr * tracing. TracedContext ,
252254 rwa connection.ReadWriteAcker ,
253255 dest string ,
254256 connectionProxy ingress.StreamBasedOriginProxy ,
255257) error {
258+ ctx := tr .Context
259+ _ , connectSpan := tr .Tracer ().Start (ctx , "stream_connect" )
256260 originConn , err := connectionProxy .EstablishConnection (ctx , dest )
257261 if err != nil {
262+ tracing .EndWithErrorStatus (connectSpan , err )
258263 return err
259264 }
265+ connectSpan .End ()
266+
267+ encodedSpans := tr .GetSpans ()
260268
261- if err := rwa .AckConnection (); err != nil {
269+ if err := rwa .AckConnection (encodedSpans ); err != nil {
262270 return err
263271 }
264272
0 commit comments