Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added oryxBuildBinary
Binary file not shown.
10 changes: 8 additions & 2 deletions plugins/http/client_intercepter.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,18 @@ type ClientInterceptor struct {

func (h *ClientInterceptor) BeforeInvoke(invocation operator.Invocation) error {
request := invocation.Args()[0].(*http.Request)
s, err := tracing.CreateExitSpan(fmt.Sprintf("%s:%s", request.Method, request.URL.Path), request.Host, func(headerKey, headerValue string) error {
host := request.Host
if host == "" {
if request.URL != nil {
host = request.URL.Host
}
}
s, err := tracing.CreateExitSpan(fmt.Sprintf("%s:%s", request.Method, request.URL.Path), host, func(headerKey, headerValue string) error {
request.Header.Add(headerKey, headerValue)
return nil
}, tracing.WithLayer(tracing.SpanLayerHTTP),
tracing.WithTag(tracing.TagHTTPMethod, request.Method),
tracing.WithTag(tracing.TagURL, request.Host+request.URL.Path),
tracing.WithTag(tracing.TagURL, host+request.URL.Path),
tracing.WithComponent(5005))
if err != nil {
return err
Expand Down
12 changes: 12 additions & 0 deletions plugins/http/client_intercepter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ func TestClientInvoke(t *testing.T) {
assert.Nil(t, err, "after invoke error should be nil")

time.Sleep(100 * time.Millisecond)

reqWithoutHost, err := http.NewRequest("GET", "/api/hello", http.NoBody) // Create request with path only, will result empty Request.Host
// Set URL after is valid behavior
reqWithoutHost.URL.Scheme = "http"
reqWithoutHost.URL.Host = "localhost"
assert.Nil(t, err, "new request with no host in url should be no error")
invocationWithoutHost := operator.NewInvocation(nil, reqWithoutHost)
err = interceptor.BeforeInvoke(invocationWithoutHost)
assert.Nil(t, err, "BeforeInvoke with URL.Host should be no error")

time.Sleep(100 * time.Millisecond)

spans := core.GetReportedSpans()
assert.NotNil(t, spans, "spans should not be nil")
assert.Equal(t, 1, len(spans), "spans length should be 1")
Expand Down