Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Commit

Permalink
Remove URL attribute, introduce path attribute
Browse files Browse the repository at this point in the history
Also remove request and response size related attributes
to be compatible with the spec.

https://github.com/census-instrumentation/opencensus-specs/blob/master/trace/HTTPAttributes.md
  • Loading branch information
rakyll committed Feb 26, 2018
1 parent e2fe6be commit 4c6b85e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
19 changes: 9 additions & 10 deletions exporter/stackdriver/trace_proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ const (
maxAttributeStringValue = 256
agentLabel = "g.co/agent"

labelErrorMessage = `trace.cloud.google.com/error/message`
labelHTTPHost = `trace.cloud.google.com/http/host`
labelHTTPMethod = `trace.cloud.google.com/http/method`
labelHTTPRequestSize = `trace.cloud.google.com/http/request/size`
labelHTTPResponseSize = `trace.cloud.google.com/http/response/size`
labelHTTPStatusCode = `trace.cloud.google.com/http/status_code`
labelHTTPURL = `trace.cloud.google.com/http/url`
labelHTTPUserAgent = `trace.cloud.google.com/http/user_agent`
labelHTTPHost = `/http/host`
labelHTTPMethod = `/http/method`
labelHTTPRequestSize = `/http/request/size`
labelHTTPResponseSize = `/http/response/size`
labelHTTPStatusCode = `/http/status_code`
labelHTTPPath = `/http/path`
labelHTTPUserAgent = `/http/user_agent`
)

// proto returns a protocol buffer representation of a SpanData.
Expand Down Expand Up @@ -178,8 +177,8 @@ func copyAttributes(out **tracepb.Span_Attributes, in map[string]interface{}) {
continue
}
switch key {
case ochttp.URLAttribute:
(*out).AttributeMap[labelHTTPURL] = av
case ochttp.PathAttribute:
(*out).AttributeMap[labelHTTPPath] = av
case ochttp.HostAttribute:
(*out).AttributeMap[labelHTTPHost] = av
case ochttp.MethodAttribute:
Expand Down
20 changes: 8 additions & 12 deletions plugin/ochttp/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@ import (
// Attributes recorded on the span for the requests.
// Only trace exporters will need them.
const (
URLAttribute = "http.url"
HostAttribute = "http.host"
MethodAttribute = "http.method"
PathAttribute = "http.path"
UserAgentAttribute = "http.user_agent"
StatusCodeAttribute = "http.status"
RequestSizeAttribute = "http.request_size"
ResponseSizeAttribute = "http.response_size"
HostAttribute = "http.host"
MethodAttribute = "http.method"
PathAttribute = "http.path"
UserAgentAttribute = "http.user_agent"
StatusCodeAttribute = "http.status"
)

type traceTransport struct {
Expand All @@ -45,6 +42,8 @@ type traceTransport struct {
format propagation.HTTPFormat
}

// TODO(jbd): Add message events for request and response size.

// RoundTrip creates a trace.Span and inserts it into the outgoing request's headers.
// The created span can follow a parent span, if a parent is presented in
// the request's context.
Expand All @@ -68,7 +67,6 @@ func (t *traceTransport) RoundTrip(req *http.Request) (*http.Response, error) {
return resp, err
}

// TODO(jbd): Set status based on the status code.
span.SetAttributes(responseAttrs(resp)...)

// span.End() will be invoked after
Expand Down Expand Up @@ -194,18 +192,16 @@ func spanNameFromURL(prefix string, u *url.URL) string {

func requestAttrs(r *http.Request) []trace.Attribute {
return []trace.Attribute{
trace.StringAttribute{Key: URLAttribute, Value: r.URL.String()},
trace.StringAttribute{Key: PathAttribute, Value: r.URL.Path},
trace.StringAttribute{Key: HostAttribute, Value: r.URL.Host},
trace.StringAttribute{Key: MethodAttribute, Value: r.Method},
trace.StringAttribute{Key: PathAttribute, Value: r.URL.Path},
trace.StringAttribute{Key: UserAgentAttribute, Value: r.UserAgent()},
trace.Int64Attribute{Key: RequestSizeAttribute, Value: r.ContentLength},
}
}

func responseAttrs(resp *http.Response) []trace.Attribute {
return []trace.Attribute{
trace.Int64Attribute{Key: ResponseSizeAttribute, Value: resp.ContentLength},
trace.Int64Attribute{Key: StatusCodeAttribute, Value: int64(resp.StatusCode)},
}
}

0 comments on commit 4c6b85e

Please sign in to comment.