|
| 1 | +# Semantic Conventions for gRPC |
| 2 | + |
| 3 | +**Status**: [Experimental][DocumentStatus] |
| 4 | + |
| 5 | +The Semantic Conventions for [gRPC](https://grpc.io/) extend and override the [RPC spans](rpc-spans.md) and [RPC metrics](rpc-metrics.md) Semantic Conventions |
| 6 | +that describe common RPC operations attributes in addition to the Semantic Conventions |
| 7 | +described on this page. |
| 8 | + |
| 9 | +## gRPC Attributes |
| 10 | + |
| 11 | +`rpc.system` MUST be set to `"grpc"`. |
| 12 | + |
| 13 | +Below is a table of attributes that SHOULD be included on client and server gRPC measurements. |
| 14 | + |
| 15 | +<!-- semconv rpc.grpc --> |
| 16 | +| Attribute | Type | Description | Examples | Requirement Level | |
| 17 | +|---|---|---|---|---| |
| 18 | +| `rpc.grpc.status_code` | int | The [numeric status code](https://github.com/grpc/grpc/blob/v1.33.2/doc/statuscodes.md) of the gRPC request. | `0` | Required | |
| 19 | + |
| 20 | +`rpc.grpc.status_code` MUST be one of the following: |
| 21 | + |
| 22 | +| Value | Description | |
| 23 | +|---|---| |
| 24 | +| `0` | OK | |
| 25 | +| `1` | CANCELLED | |
| 26 | +| `2` | UNKNOWN | |
| 27 | +| `3` | INVALID_ARGUMENT | |
| 28 | +| `4` | DEADLINE_EXCEEDED | |
| 29 | +| `5` | NOT_FOUND | |
| 30 | +| `6` | ALREADY_EXISTS | |
| 31 | +| `7` | PERMISSION_DENIED | |
| 32 | +| `8` | RESOURCE_EXHAUSTED | |
| 33 | +| `9` | FAILED_PRECONDITION | |
| 34 | +| `10` | ABORTED | |
| 35 | +| `11` | OUT_OF_RANGE | |
| 36 | +| `12` | UNIMPLEMENTED | |
| 37 | +| `13` | INTERNAL | |
| 38 | +| `14` | UNAVAILABLE | |
| 39 | +| `15` | DATA_LOSS | |
| 40 | +| `16` | UNAUTHENTICATED | |
| 41 | +<!-- endsemconv --> |
| 42 | + |
| 43 | +## gRPC Status |
| 44 | + |
| 45 | +The table below describes when |
| 46 | +the [Span Status](https://github.com/open-telemetry/opentelemetry-specification/tree/v1.21.0/specification/trace/api.md#set-status) MUST be set |
| 47 | +to `Error` or remain unset |
| 48 | +depending on the [gRPC status code](https://github.com/grpc/grpc/blob/v1.33.2/doc/statuscodes.md) |
| 49 | +and [Span Kind](https://github.com/open-telemetry/opentelemetry-specification/tree/v1.21.0/specification/trace/api.md#spankind). |
| 50 | + |
| 51 | +| gRPC Status Code | `SpanKind.SERVER` Span Status | `SpanKind.CLIENT` Span Status | |
| 52 | +|---|---|---| |
| 53 | +| OK | unset | unset | |
| 54 | +| CANCELLED | unset | `Error` | |
| 55 | +| UNKNOWN | `Error` | `Error` | |
| 56 | +| INVALID_ARGUMENT | unset | `Error` | |
| 57 | +| DEADLINE_EXCEEDED | `Error` | `Error` | |
| 58 | +| NOT_FOUND | unset | `Error` | |
| 59 | +| ALREADY_EXISTS | unset | `Error` | |
| 60 | +| PERMISSION_DENIED | unset | `Error` | |
| 61 | +| RESOURCE_EXHAUSTED | unset| `Error` | |
| 62 | +| FAILED_PRECONDITION | unset | `Error` | |
| 63 | +| ABORTED | unset | `Error` | |
| 64 | +| OUT_OF_RANGE | unset | `Error` | |
| 65 | +| UNIMPLEMENTED | `Error` | `Error` | |
| 66 | +| INTERNAL | `Error` | `Error` | |
| 67 | +| UNAVAILABLE | `Error` | `Error` | |
| 68 | +| DATA_LOSS | `Error` | `Error` | |
| 69 | +| UNAUTHENTICATED | unset | `Error` | |
| 70 | + |
| 71 | +## gRPC Request and Response Metadata |
| 72 | + |
| 73 | +| Attribute | Type | Description | Examples | Requirement Level | |
| 74 | +|-------------------------------|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------|-------------------| |
| 75 | +| `rpc.grpc.request.metadata.<key>` | string[] | gRPC request metadata, `<key>` being the normalized gRPC Metadata key (lowercase, with `-` characters replaced by `_`), the value being the metadata values. [1] | `rpc.grpc.request.metadata.my_custom_metadata_attribute=["1.2.3.4", "1.2.3.5"]` | Opt-In | |
| 76 | +| `rpc.grpc.response.metadata.<key>` | string[] | gRPC response metadata, `<key>` being the normalized gRPC Metadata key (lowercase, with `-` characters replaced by `_`), the value being the metadata values. [1] | `rpc.grpc.response.metadata.my_custom_metadata_attribute=["attribute_value"]` | Opt-In | |
| 77 | + |
| 78 | +**[1]:** Instrumentations SHOULD require an explicit configuration of which metadata values are to be captured. |
| 79 | +Including all request/response metadata values can be a security risk - explicit configuration helps avoid leaking sensitive information. |
| 80 | + |
| 81 | +[DocumentStatus]: https://github.com/open-telemetry/opentelemetry-specification/blob/v1.21.0/specification/document-status.md |
0 commit comments