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

Commit 4814870

Browse files
author
Bogdan Drutu
authored
Add initial documentation for gRPC trace. (#98)
* Add initial documentation for gRPC trace. * Address comments. * Clarify MessageId generation.
1 parent de137eb commit 4814870

3 files changed

Lines changed: 77 additions & 28 deletions

File tree

trace/HTTP.md

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
# HTTP
1+
# HTTP Trace
22

33
This document explains tracing of HTTP requests with OpenCensus.
44

55
## Spans
66

7-
Implementations MUST create a span for outgoing requests at the
8-
client and a span for incoming requests at the server.
7+
Implementations MUST create a span for outgoing requests at the client and a span for incoming
8+
requests at the server.
99

1010
Span name is formatted as:
1111

1212
* /$path for outgoing requests.
1313
* /($path|$route) for incoming requests.
1414

15-
If route cannot be determined, path is used to name the
16-
the span for outgoing requests.
15+
If route cannot be determined, path is used to name the the span for outgoing requests.
1716

1817
Port MUST be omitted if it is 80 or 443.
1918

@@ -28,35 +27,31 @@ incoming requests should be a span kind of SERVER.
2827

2928
## Propagation
3029

31-
Propagation is how SpanContext is transmitted on the wire
32-
in an HTTP request.
30+
Propagation is how SpanContext is transmitted on the wire in an HTTP request.
3331

34-
Implementations MUST allow users to set their own propagation
35-
format and MUST provide an implementation for B3 at least.
32+
Implementations MUST allow users to set their own propagation format and MUST provide an
33+
implementation for B3 at least.
3634

3735
If user doesn't set any propagation methods explicitly, B3 is used.
3836

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.
37+
The propagation method SHOULD modify a request object to insert a SpanContext or SHOULD be able
38+
to extract a SpanContext from a request object.
4239

4340
## Status
4441

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.
42+
Implementations MUST set status if HTTP request or response is not successful (e.g. not 2xx). In
43+
redirection case, if the client doesn't have autoredirection support, request should be
44+
considered successful.
4945

50-
Set status code to UNKNOWN (2) if the reason cannot be inferred
51-
at the callsite or from the HTTP status code.
46+
Set status code to UNKNOWN (2) if the reason cannot be inferred at the callsite or from the HTTP
47+
status code.
5248

53-
Don't set the status message if the reason can be inferred at
54-
the callsite of from the HTTP status code.
49+
Don't set the status message if the reason can be inferred at the callsite of from the HTTP
50+
status code.
5551

5652
## Message events
5753

58-
In the lifetime of an incoming and outgoing request, the following
59-
message events SHOULD be created:
54+
In the lifetime of an incoming and outgoing request, the following message events SHOULD be created:
6055

6156
* A message event for the request body size if/when determined.
6257
* A message event for the response size if/when determined.
@@ -75,9 +70,8 @@ Implementations SHOULD create message event when response size is determined.
7570

7671
## Attributes
7772

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.
73+
Implementations SHOULD set the following attributes on the client and server spans. For a server,
74+
request represents the incoming request. For a client, request represents the outgoing request.
8175

8276
All attributes are optional.
8377

@@ -90,9 +84,8 @@ All attributes are optional.
9084
| "http.user_agent" | Request user-agent | "HTTPClient/1.2" |
9185
| "http.status_code" | Response status code | 200 |
9286

93-
Exporters should always export the collected attributes.
94-
Exporters should map the collected attributes to backend's
95-
known attributes/labels.
87+
Exporters should always export the collected attributes. Exporters should map the collected
88+
attributes to backend's known attributes/labels.
9689

9790
The following table summarizes how OpenCensus attributes maps to the
9891
known attributes/labels on supported tracing backends.

trace/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ describes the key types and the overall behavior.
77
* [TraceConfig](TraceConfig.md)
88

99
## Utils
10+
* [gRPC integration](gRPC.md): document about how to instrument gRPC framework.
1011
* [HTTP integration](HTTP.md): document about how to instrument http frameworks.
1112
* [Sampling logic](Sampling.md): document about how sampling works.

trace/gRPC.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# gRPC Trace
2+
3+
This document explains tracing of gRPC requests with OpenCensus.
4+
5+
## Spans
6+
7+
Implementations MUST create a span, when the gRPC call starts, for the client and a span for the
8+
server.
9+
10+
Span name is formatted as (also known as full gRPC method name):
11+
12+
* $package.$service/$method
13+
14+
Examples of span names:
15+
16+
* grpc.test.EchoService/Echo
17+
18+
Outgoing requests should be a span kind of CLIENT and
19+
incoming requests should be a span kind of SERVER.
20+
21+
For backends that does not support Span.Kind, the exported span names can be prefixed with `Sent.`
22+
(for CLIENT kind) and `Recv.` (for SERVER kind).
23+
24+
## Propagation
25+
26+
Propagation is how SpanContext is transmitted on the wire in an gRPC request.
27+
28+
The propagation MUST inject a SpanContext (as a gRPC metadata `grpc-trace-bin`) and MUST extract
29+
a SpanContext from the gRPC metadata. The serialization format is defined
30+
[here](../encodings/BinaryEncoding.md).
31+
32+
## Status
33+
34+
Implementations MUST set status which should be the same as the gRPC client/server status. The
35+
mapping between gRPC canonical codes and OpenCensus status codes can be found
36+
[here](https://github.com/grpc/grpc-go/blob/master/codes/codes.go).
37+
38+
## Message events
39+
40+
In the lifetime of a gRPC stream, the following message events SHOULD be created:
41+
42+
* A message event for each message sent/received on client and server spans.
43+
44+
```
45+
-> [time], MessageEventTypeSent, MessageId, UncompressedByteSize, CompressedByteSize
46+
```
47+
48+
```
49+
-> [time], MessageEventTypeRecv, MessageId, UncompressedByteSize, CompressedByteSize
50+
```
51+
52+
The `MessageId` must be calculated as two different counters starting from `1` one for sent
53+
messages and one for received message. This way we guarantee that the values will be consistent
54+
between different implementations. In case of unary calls only one sent and one received message
55+
will be recorded for both client and server spans.

0 commit comments

Comments
 (0)