-
Notifications
You must be signed in to change notification settings - Fork 931
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
217 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package wrapper | ||
|
||
import ( | ||
"code.cloudfoundry.org/cli/api/cloudcontroller" | ||
) | ||
|
||
// TODO | ||
// 1. tests | ||
// 2. do not overwrite headers if explicitly set (cf curl) | ||
// 3. headers should go on other clients (uaa/routing) as well (with same value) | ||
// 4. environment variable override | ||
|
||
const ( | ||
// B3TraceIDHeader is the header key for the b3 trace id. | ||
B3TraceIDHeader = "X-B3-Traceid" | ||
|
||
// B3SpanIDHeader is the header key for the b3 span id. | ||
B3SpanIDHeader = "X-B3-Spanid" | ||
) | ||
|
||
// TraceHeaderRequest is a wrapper that adds b3 trace headers to requests. | ||
type TraceHeaderRequest struct { | ||
b3trace string | ||
b3span string | ||
connection cloudcontroller.Connection | ||
} | ||
|
||
// NewTraceHeaderRequest returns a pointer to a TraceHeaderRequest wrapper. | ||
func NewTraceHeaderRequest(trace, span string) *TraceHeaderRequest { | ||
return &TraceHeaderRequest{ | ||
b3trace: trace, | ||
b3span: span, | ||
} | ||
} | ||
|
||
// Add tracing headers if they are not already set. | ||
func (t *TraceHeaderRequest) Make(request *cloudcontroller.Request, passedResponse *cloudcontroller.Response) error { | ||
|
||
// todo | ||
// only override the trace headers if they are not already set (e.g. already explicitly set by cf curl) | ||
if request.Header.Get(B3TraceIDHeader) != "" { | ||
request.Header.Add(B3TraceIDHeader, t.b3trace) | ||
} | ||
if request.Header.Get(B3SpanIDHeader) != "" { | ||
request.Header.Add(B3SpanIDHeader, t.b3span) | ||
} | ||
return t.connection.Make(request, passedResponse) | ||
} | ||
|
||
// Wrap sets the connection in the TraceHeaderRequest and returns itself. | ||
func (t *TraceHeaderRequest) Wrap(innerconnection cloudcontroller.Connection) cloudcontroller.Connection { | ||
t.connection = innerconnection | ||
return t | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters