|
| 1 | +# HTTP |
| 2 | + |
| 3 | +This document explains tracing of HTTP requests with OpenCensus. |
| 4 | + |
| 5 | +## Spans |
| 6 | + |
| 7 | +Implementations MUST create a span for outgoing requests at the |
| 8 | +client and a span for incoming requests at the server. |
| 9 | + |
| 10 | +Span name is formatted as: |
| 11 | + |
| 12 | +* /$path for outgoing requests. |
| 13 | +* /($path|$route) for incoming requests. |
| 14 | + |
| 15 | +If route cannot be determined, path is used to name the |
| 16 | +the span for outgoing requests. |
| 17 | + |
| 18 | +Port MUST be omitted if it is 80 or 443. |
| 19 | + |
| 20 | +Examples of span names: |
| 21 | + |
| 22 | +* /users |
| 23 | +* /messages/[:id] |
| 24 | +* /users/25f4c31d |
| 25 | + |
| 26 | +Outgoing requests should be a span kind of CLIENT and |
| 27 | +incoming requests should be a span kind of SERVER. |
| 28 | + |
| 29 | +## Propagation |
| 30 | + |
| 31 | +Propagation is how SpanContext is transmitted on the wire |
| 32 | +in an HTTP request. |
| 33 | + |
| 34 | +Implementations MUST allow users to set their own propagation |
| 35 | +format and MUST provide an implementation for B3 at least. |
| 36 | + |
| 37 | +If user doesn't set any propagation methods explicitly, B3 is used. |
| 38 | + |
| 39 | +The propagation method SHOULD modify a request object to insert |
| 40 | +a SpanContext or SHOULD be able to extract a SpanContext from a |
| 41 | +request object. |
| 42 | + |
| 43 | +## Status |
| 44 | + |
| 45 | +Implementations MUST set status if HTTP request or response |
| 46 | +is not successful (e.g. not 2xx). In redirection case, if |
| 47 | +the client doesn't have autoredirection support, request |
| 48 | +should be considered successful. |
| 49 | + |
| 50 | +Set status code to UNKNOWN (2) if the reason cannot be inferred |
| 51 | +at the callsite or from the HTTP status code. |
| 52 | + |
| 53 | +Don't set the status message if the reason can be inferred at |
| 54 | +the callsite of from the HTTP status code. |
| 55 | + |
| 56 | +## Message events |
| 57 | + |
| 58 | +In the lifetime of an incoming and outgoing request, the following |
| 59 | +message events SHOULD be created: |
| 60 | + |
| 61 | +* A message event for the request body size if/when determined. |
| 62 | +* A message event for the response size if/when determined. |
| 63 | + |
| 64 | +Implementations SHOULD create message event when body size is determined. |
| 65 | + |
| 66 | +``` |
| 67 | +-> [time], MessageEventTypeSent, UncompressedByteSize, CompressedByteSize |
| 68 | +``` |
| 69 | + |
| 70 | +Implementations SHOULD create message event when response size is determined. |
| 71 | + |
| 72 | +``` |
| 73 | +-> [time], MessageEventTypeRecv, UncompressedByteSize, CompressedByteSize |
| 74 | +``` |
| 75 | + |
| 76 | +## Attributes |
| 77 | + |
| 78 | +Implementations SHOULD set the following attributes on the client |
| 79 | +and server spans. For a server, request represents the incoming request. |
| 80 | +For a client, request represents the outgoing request. |
| 81 | + |
| 82 | +All attributes are optional. |
| 83 | + |
| 84 | +| Attribute name | Description | Example value | |
| 85 | +|---------------------------|-----------------------------|---------------------------------| |
| 86 | +| "http.host" | Request URL host | "example.com" | |
| 87 | +| "http.port" | Request URL port | 443 | |
| 88 | +| "http.method" | Request URL method | "GET" | |
| 89 | +| "http.path" | Request URL path | "/users/25f4c31d" | |
| 90 | +| "http.route" | Matched request URL route | "/users/:userID" | |
| 91 | +| "http.user_agent" | Request user-agent | "HTTPClient/1.2" | |
| 92 | +| "http.status_code" | Response status code | 200 | |
| 93 | + |
| 94 | +Exporters should always export the collected attributes. |
| 95 | +Exporters should map the collected attributes to backend's |
| 96 | +known attributes/labels. |
| 97 | + |
| 98 | +The following table summarizes how OpenCensus attributes maps to the |
| 99 | +known attributes/labels on supported tracing backends. |
| 100 | + |
| 101 | +| OpenCensus attribute | Zipkin | Jaeger | Stackdriver Trace label | |
| 102 | +|---------------------------|--------------------|--------------------|---------------------------| |
| 103 | +| "http.host" | "http.host" | "http.host" | "/http/host" | |
| 104 | +| "http.method" | "http.method" | "http.method" | "/http/method" | |
| 105 | +| "http.path" | "http.path" | "http.path" | "/http/path" | |
| 106 | +| "http.port" | "http.port" | "http.port" | "http.port" | |
| 107 | +| "http.route" | "http.route" | "http.route" | "/http/route" | |
| 108 | +| "http.user_agent" | "http.user_agent" | "http.user_agent" | "/http/user_agent" | |
| 109 | +| "http.status_code" | "http.status_code" | "http.status_code" | "/http/status_code" | |
0 commit comments