Semantic conventions for gRPC

Status: Development

The Semantic Conventions for gRPC extend and override the RPC spans and RPC metrics Semantic Conventions that describe common RPC operations attributes in addition to the Semantic Conventions described on this page.

Client Span

Status: Development

This span represents an outgoing Remote Procedure Call (RPC).

rpc.system MUST be set to "grpc" and SHOULD be provided at span creation time.

Span name: refer to the Span Name section.

Span kind MUST be CLIENT.

Span status Should be set based on the grpc status code. A mapping is defined in the grpc status section.

Attributes:

KeyStabilityRequirement LevelValue TypeDescriptionExample Values
rpc.grpc.status_codeDevelopmentRequiredintThe numeric status code of the gRPC request.0; 1; 2
rpc.methodDevelopmentRequiredstringThis is the logical name of the method from the RPC interface perspective. [1]exampleMethod
rpc.serviceDevelopmentRequiredstringThe full (logical) name of the service being called, including its package name, if applicable. [2]myservice.EchoService
server.addressStableRequiredstringRPC server host name. [3]example.com; 10.1.2.80; /tmp/my.sock
error.typeStableConditionally Required If and only if the operation failed.stringDescribes a class of error the operation ended with. [4]timeout; java.net.UnknownHostException; server_certificate_invalid; 500
server.portStableConditionally Required [5]intServer port number. [6]80; 8080; 443
network.peer.addressStableRecommendedstringPeer address of the network connection - IP address or Unix domain socket name.10.1.2.80; /tmp/my.sock
network.peer.portStableRecommended If network.peer.address is set.intPeer port number of the network connection.65123
network.protocol.nameStableRecommendedstringOSI application layer or non-OSI equivalent. [7]http
network.protocol.versionStableRecommendedstringThe actual version of the protocol used for network communication. [8]1.1; 2
network.transportStableRecommendedstringOSI transport layer or inter-process communication method. [9]tcp; udp
rpc.grpc.request.metadata.<key>DevelopmentOpt-Instring[]gRPC request metadata, <key> being the normalized gRPC Metadata key (lowercase), the value being the metadata values. [10]["1.2.3.4", "1.2.3.5"]
rpc.grpc.response.metadata.<key>DevelopmentOpt-Instring[]gRPC response metadata, <key> being the normalized gRPC Metadata key (lowercase), the value being the metadata values. [11]["attribute_value"]

[1] rpc.method: This is the logical name of the method from the RPC interface perspective, which can be different from the name of any implementing method/function. The code.function.name attribute may be used to store the latter (e.g., method actually executing the call on the server side, RPC client stub method on the client side).

[2] rpc.service: This is the logical name of the service from the RPC interface perspective, which can be different from the name of any implementing class. The code.namespace attribute may be used to store the latter (despite the attribute name, it may include a class name; e.g., class with method actually executing the call on the server side, RPC client stub class on the client side).

[3] server.address: May contain server IP address, DNS name, or local socket name. When host component is an IP address, instrumentations SHOULD NOT do a reverse proxy lookup to obtain DNS name and SHOULD set server.address to the IP address provided in the host component.

[4] error.type: The error.type SHOULD be predictable, and SHOULD have low cardinality.

When error.type is set to a type (e.g., an exception type), its canonical class name identifying the type within the artifact SHOULD be used.

Instrumentations SHOULD document the list of errors they report.

The cardinality of error.type within one instrumentation library SHOULD be low. Telemetry consumers that aggregate data from multiple instrumentation libraries and applications should be prepared for error.type to have high cardinality at query time when no additional filters are applied.

If the operation has completed successfully, instrumentations SHOULD NOT set error.type.

If a specific domain defines its own set of error identifiers (such as HTTP or gRPC status codes), it’s RECOMMENDED to:

  • Use a domain-specific attribute
  • Set error.type to capture all errors, regardless of whether they are defined within the domain-specific set or not.

[5] server.port: if the port is supported by the network transport used for communication.

[6] server.port: When observed from the client side, and when communicating through an intermediary, server.port SHOULD represent the server port behind any intermediaries, for example proxies, if it’s available.

[7] network.protocol.name: The value SHOULD be normalized to lowercase.

[8] network.protocol.version: If protocol version is subject to negotiation (for example using ALPN), this attribute SHOULD be set to the negotiated version. If the actual protocol version is not known, this attribute SHOULD NOT be set.

[9] network.transport: The value SHOULD be normalized to lowercase.

Consider always setting the transport when setting a port number, since a port number is ambiguous without knowing the transport. For example different processes could be listening on TCP port 12345 and UDP port 12345.

[10] rpc.grpc.request.metadata.<key>: Instrumentations SHOULD require an explicit configuration of which metadata values are to be captured. Including all request metadata values can be a security risk - explicit configuration helps avoid leaking sensitive information.

For example, a property my-custom-key with value ["1.2.3.4", "1.2.3.5"] SHOULD be recorded as rpc.grpc.request.metadata.my-custom-key attribute with value ["1.2.3.4", "1.2.3.5"]

[11] rpc.grpc.response.metadata.<key>: Instrumentations SHOULD require an explicit configuration of which metadata values are to be captured. Including all response metadata values can be a security risk - explicit configuration helps avoid leaking sensitive information.

For example, a property my-custom-key with value ["attribute_value"] SHOULD be recorded as the rpc.grpc.response.metadata.my-custom-key attribute with value ["attribute_value"]


error.type has the following list of well-known values. If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.

ValueDescriptionStability
_OTHERA fallback error value to be used when the instrumentation doesn’t define a custom value.Stable

network.transport has the following list of well-known values. If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.

ValueDescriptionStability
pipeNamed or anonymous pipe.Stable
quicQUICStable
tcpTCPStable
udpUDPStable
unixUnix domain socketStable

rpc.grpc.status_code has the following list of well-known values. If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.

ValueDescriptionStability
0OKDevelopment
1CANCELLEDDevelopment
2UNKNOWNDevelopment
3INVALID_ARGUMENTDevelopment
4DEADLINE_EXCEEDEDDevelopment
5NOT_FOUNDDevelopment
6ALREADY_EXISTSDevelopment
7PERMISSION_DENIEDDevelopment
8RESOURCE_EXHAUSTEDDevelopment
9FAILED_PRECONDITIONDevelopment
10ABORTEDDevelopment
11OUT_OF_RANGEDevelopment
12UNIMPLEMENTEDDevelopment
13INTERNALDevelopment
14UNAVAILABLEDevelopment
15DATA_LOSSDevelopment
16UNAUTHENTICATEDDevelopment

Server Span

Status: Development

This span represents an incoming Remote Procedure Call (RPC).

rpc.system MUST be set to "grpc" and SHOULD be provided at span creation time.

Span name: refer to the Span Name section.

Span kind MUST be SERVER.

Span status Should be set based on the grpc status code. A mapping is defined in the grpc status section.

Attributes:

KeyStabilityRequirement LevelValue TypeDescriptionExample Values
rpc.grpc.status_codeDevelopmentRequiredintThe numeric status code of the gRPC request.0; 1; 2
server.addressStableRequiredstringRPC server host name. [1]example.com; 10.1.2.80; /tmp/my.sock
error.typeStableConditionally Required If and only if the operation failed.stringDescribes a class of error the operation ended with. [2]timeout; java.net.UnknownHostException; server_certificate_invalid; 500
server.portStableConditionally Required [3]intServer port number. [4]80; 8080; 443
client.addressStableRecommendedstringClient address - domain name if available without reverse DNS lookup; otherwise, IP address or Unix domain socket name. [5]client.example.com; 10.1.2.80; /tmp/my.sock
client.portStableRecommendedintClient port number. [6]65123
network.peer.addressStableRecommendedstringPeer address of the network connection - IP address or Unix domain socket name.10.1.2.80; /tmp/my.sock
network.peer.portStableRecommended If network.peer.address is set.intPeer port number of the network connection.65123
network.protocol.nameStableRecommendedstringOSI application layer or non-OSI equivalent. [7]http
network.protocol.versionStableRecommendedstringThe actual version of the protocol used for network communication. [8]1.1; 2
network.transportStableRecommendedstringOSI transport layer or inter-process communication method. [9]tcp; udp
rpc.methodDevelopmentRecommendedstringThis is the logical name of the method from the RPC interface perspective. [10]exampleMethod
rpc.serviceDevelopmentRecommendedstringThe full (logical) name of the service being called, including its package name, if applicable. [11]myservice.EchoService
rpc.grpc.request.metadata.<key>DevelopmentOpt-Instring[]gRPC request metadata, <key> being the normalized gRPC Metadata key (lowercase), the value being the metadata values. [12]["1.2.3.4", "1.2.3.5"]
rpc.grpc.response.metadata.<key>DevelopmentOpt-Instring[]gRPC response metadata, <key> being the normalized gRPC Metadata key (lowercase), the value being the metadata values. [13]["attribute_value"]

[1] server.address: May contain server IP address, DNS name, or local socket name. When host component is an IP address, instrumentations SHOULD NOT do a reverse proxy lookup to obtain DNS name and SHOULD set server.address to the IP address provided in the host component.

[2] error.type: The error.type SHOULD be predictable, and SHOULD have low cardinality.

When error.type is set to a type (e.g., an exception type), its canonical class name identifying the type within the artifact SHOULD be used.

Instrumentations SHOULD document the list of errors they report.

The cardinality of error.type within one instrumentation library SHOULD be low. Telemetry consumers that aggregate data from multiple instrumentation libraries and applications should be prepared for error.type to have high cardinality at query time when no additional filters are applied.

If the operation has completed successfully, instrumentations SHOULD NOT set error.type.

If a specific domain defines its own set of error identifiers (such as HTTP or gRPC status codes), it’s RECOMMENDED to:

  • Use a domain-specific attribute
  • Set error.type to capture all errors, regardless of whether they are defined within the domain-specific set or not.

[3] server.port: if the port is supported by the network transport used for communication.

[4] server.port: When observed from the client side, and when communicating through an intermediary, server.port SHOULD represent the server port behind any intermediaries, for example proxies, if it’s available.

[5] client.address: When observed from the server side, and when communicating through an intermediary, client.address SHOULD represent the client address behind any intermediaries, for example proxies, if it’s available.

[6] client.port: When observed from the server side, and when communicating through an intermediary, client.port SHOULD represent the client port behind any intermediaries, for example proxies, if it’s available.

[7] network.protocol.name: The value SHOULD be normalized to lowercase.

[8] network.protocol.version: If protocol version is subject to negotiation (for example using ALPN), this attribute SHOULD be set to the negotiated version. If the actual protocol version is not known, this attribute SHOULD NOT be set.

[9] network.transport: The value SHOULD be normalized to lowercase.

Consider always setting the transport when setting a port number, since a port number is ambiguous without knowing the transport. For example different processes could be listening on TCP port 12345 and UDP port 12345.

[10] rpc.method: This is the logical name of the method from the RPC interface perspective, which can be different from the name of any implementing method/function. The code.function.name attribute may be used to store the latter (e.g., method actually executing the call on the server side, RPC client stub method on the client side).

[11] rpc.service: This is the logical name of the service from the RPC interface perspective, which can be different from the name of any implementing class. The code.namespace attribute may be used to store the latter (despite the attribute name, it may include a class name; e.g., class with method actually executing the call on the server side, RPC client stub class on the client side).

[12] rpc.grpc.request.metadata.<key>: Instrumentations SHOULD require an explicit configuration of which metadata values are to be captured. Including all request metadata values can be a security risk - explicit configuration helps avoid leaking sensitive information.

For example, a property my-custom-key with value ["1.2.3.4", "1.2.3.5"] SHOULD be recorded as rpc.grpc.request.metadata.my-custom-key attribute with value ["1.2.3.4", "1.2.3.5"]

[13] rpc.grpc.response.metadata.<key>: Instrumentations SHOULD require an explicit configuration of which metadata values are to be captured. Including all response metadata values can be a security risk - explicit configuration helps avoid leaking sensitive information.

For example, a property my-custom-key with value ["attribute_value"] SHOULD be recorded as the rpc.grpc.response.metadata.my-custom-key attribute with value ["attribute_value"]


error.type has the following list of well-known values. If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.

ValueDescriptionStability
_OTHERA fallback error value to be used when the instrumentation doesn’t define a custom value.Stable

network.transport has the following list of well-known values. If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.

ValueDescriptionStability
pipeNamed or anonymous pipe.Stable
quicQUICStable
tcpTCPStable
udpUDPStable
unixUnix domain socketStable

rpc.grpc.status_code has the following list of well-known values. If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.

ValueDescriptionStability
0OKDevelopment
1CANCELLEDDevelopment
2UNKNOWNDevelopment
3INVALID_ARGUMENTDevelopment
4DEADLINE_EXCEEDEDDevelopment
5NOT_FOUNDDevelopment
6ALREADY_EXISTSDevelopment
7PERMISSION_DENIEDDevelopment
8RESOURCE_EXHAUSTEDDevelopment
9FAILED_PRECONDITIONDevelopment
10ABORTEDDevelopment
11OUT_OF_RANGEDevelopment
12UNIMPLEMENTEDDevelopment
13INTERNALDevelopment
14UNAVAILABLEDevelopment
15DATA_LOSSDevelopment
16UNAUTHENTICATEDDevelopment

gRPC Status

The table below describes when the Span Status MUST be set to Error or remain unset depending on the gRPC status code and Span Kind.

gRPC Status CodeSpanKind.SERVER Span StatusSpanKind.CLIENT Span Status
OKunsetunset
CANCELLEDunsetError
UNKNOWNErrorError
INVALID_ARGUMENTunsetError
DEADLINE_EXCEEDEDErrorError
NOT_FOUNDunsetError
ALREADY_EXISTSunsetError
PERMISSION_DENIEDunsetError
RESOURCE_EXHAUSTEDunsetError
FAILED_PRECONDITIONunsetError
ABORTEDunsetError
OUT_OF_RANGEunsetError
UNIMPLEMENTEDErrorError
INTERNALErrorError
UNAVAILABLEErrorError
DATA_LOSSErrorError
UNAUTHENTICATEDunsetError