Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 7730b60

Browse files
committed
fixes #23
* honors `ochttp.Server#FormatSpanName` to set http.url
1 parent 6bcdc96 commit 7730b60

File tree

3 files changed

+7
-26
lines changed

3 files changed

+7
-26
lines changed

http.go

+4-20
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ import (
1818
"go.opencensus.io/plugin/ochttp"
1919
)
2020

21-
// URLAttribute allows a custom url to be specified
22-
const URLAttribute = "http.url"
23-
2421
// httpRequest – Information about an http request.
2522
type httpRequest struct {
2623
// Method – The request method. For example, GET.
@@ -66,22 +63,14 @@ type httpReqResp struct {
6663
Response httpResponse `json:"response"`
6764
}
6865

69-
func makeHttp(attributes map[string]interface{}) (map[string]interface{}, *httpReqResp, string) {
66+
func makeHttp(spanName string, attributes map[string]interface{}) (map[string]interface{}, *httpReqResp) {
7067
var (
71-
host string
72-
path string
7368
http httpReqResp
7469
filtered = map[string]interface{}{}
7570
)
7671

7772
for key, value := range attributes {
7873
switch key {
79-
case ochttp.HostAttribute:
80-
host, _ = value.(string)
81-
82-
case ochttp.PathAttribute:
83-
path, _ = value.(string)
84-
8574
case ochttp.MethodAttribute:
8675
http.Request.Method, _ = value.(string)
8776

@@ -91,21 +80,16 @@ func makeHttp(attributes map[string]interface{}) (map[string]interface{}, *httpR
9180
case ochttp.StatusCodeAttribute:
9281
http.Response.Status, _ = value.(int64)
9382

94-
case URLAttribute:
95-
http.Request.URL, _ = value.(string)
96-
9783
default:
9884
filtered[key] = value
9985
}
10086
}
10187

102-
if http.Request.URL == "" {
103-
http.Request.URL = host + path
104-
}
88+
http.Request.URL = spanName
10589

10690
if len(filtered) == len(attributes) {
107-
return attributes, nil, ""
91+
return attributes, nil
10892
}
10993

110-
return filtered, &http, host
94+
return filtered, &http
11195
}

http_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func TestHttp(t *testing.T) {
9797
t.Fatalf("unable to decode content, %v", err)
9898
}
9999

100-
if got, want := content.Name, host; got != want {
100+
if got, want := content.Name, path; got != want {
101101
t.Errorf("got %v; want %v", got, want)
102102
}
103103
if got, want := content.Http.Request.Method, http.MethodGet; got != want {
@@ -106,7 +106,7 @@ func TestHttp(t *testing.T) {
106106
if got, want := content.Http.Request.UserAgent, userAgent; got != want {
107107
t.Errorf("got %v; want %v", got, want)
108108
}
109-
if got, want := content.Http.Request.URL, host+path; got != want {
109+
if got, want := content.Http.Request.URL, path; got != want {
110110
t.Errorf("got %v; want %v", got, want)
111111
}
112112
}

segment.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -373,16 +373,13 @@ func rawSegment(span *trace.SpanData) segment {
373373
startTime = float64(startMicros) / 1e6
374374
endMicros = span.EndTime.UnixNano() / int64(time.Microsecond)
375375
endTime = float64(endMicros) / 1e6
376-
filtered, http, host = makeHttp(span.Attributes)
376+
filtered, http = makeHttp(span.Name, span.Attributes)
377377
isError, isFault, cause = makeCause(span.Status)
378378
annotations = makeAnnotations(span.Annotations, filtered)
379379
name = fixSegmentName(span.Name)
380380
namespace string
381381
)
382382

383-
if host != "" {
384-
name = host
385-
}
386383
if span.HasRemoteParent {
387384
namespace = "remote"
388385
}

0 commit comments

Comments
 (0)