func()

in xray/httptrace.go [142:171]


func (xt *HTTPSubsegments) GotConn(info *httptrace.GotConnInfo, err error) {
	xt.mu.Lock()
	defer xt.mu.Unlock()
	if xt.connCtx != nil && GetSegment(xt.opCtx).safeInProgress() { // GetConn may not have been called (client_test.TestBadRoundTrip)
		if info != nil {
			if info.Reused {
				GetSegment(xt.opCtx).RemoveSubsegment(GetSegment(xt.connCtx))
				// Remove the connCtx context since it is no longer needed.
				xt.connCtx = nil
			} else {
				metadata := make(map[string]interface{})
				metadata["reused"] = info.Reused
				metadata["was_idle"] = info.WasIdle
				if info.WasIdle {
					metadata["idle_time"] = info.IdleTime
				}

				AddMetadataToNamespace(xt.connCtx, "http", "connection", metadata)
				GetSegment(xt.connCtx).Close(err)
			}
		} else if xt.connCtx != nil && GetSegment(xt.connCtx).safeInProgress() {
			GetSegment(xt.connCtx).Close(err)
		}

		if err == nil {
			xt.reqCtx, _ = BeginSubsegment(xt.opCtx, "request")
		}

	}
}