groups:
  - id: rpc
    type: attribute_group
    brief: 'This document defines semantic conventions for remote procedure calls.'
    attributes:
      - ref: rpc.system
        requirement_level: required
      - ref: rpc.service
        requirement_level: recommended
      - ref: rpc.method
        requirement_level: recommended
      - ref: network.transport
        requirement_level: recommended
      - ref: network.type
        requirement_level: recommended
      - ref: server.address
        requirement_level: required
        brief: >
          RPC server [host name](https://grpc.github.io/grpc/core/md_doc_naming.html).
        note: >
          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.
      - ref: server.port
        requirement_level:
          conditionally_required: if the port is supported by the network transport used for communication.

  - id: span.rpc.client
    type: span
    stability: development
    brief: This span represents an outgoing Remote Procedure Call (RPC).
    note: |
      Remote procedure calls can only be represented with these semantic conventions
      when the names of the called service and method are known and available.

      **Span name:** refer to the [Span Name](#span-name) section.

      **Span kind** MUST be `CLIENT`.
    extends: rpc
    span_kind: client
    events: [rpc.message]
    attributes:
      - ref: network.peer.address
        requirement_level: recommended
      - ref: network.peer.port
        requirement_level:
          recommended: If `network.peer.address` is set.

  - id: span.rpc.server
    type: span
    stability: development
    extends: rpc
    span_kind: server
    brief: This span represents an incoming Remote Procedure Call (RPC).
    events: [rpc.message]
    note: |
      Remote procedure calls can only be represented with these semantic conventions
      when the names of the called service and method are known and available.

      **Span name:** refer to the [Span Name](#span-name) section.

      **Span kind** MUST be `SERVER`.
    attributes:
      - ref: client.address
        requirement_level: recommended
      - ref: client.port
        requirement_level: recommended
      - ref: network.peer.address
        requirement_level: recommended
      - ref: network.peer.port
        requirement_level:
          recommended: If `network.peer.address` is set.
      - ref: network.transport
        requirement_level: recommended
      - ref: network.type
        requirement_level: recommended

  - id: rpc.grpc.attributes
    stability: development
    type: attribute_group
    brief: 'Tech-specific attributes for gRPC.'
    attributes:
      - ref: rpc.grpc.status_code
        requirement_level: required
      - ref: rpc.grpc.request.metadata
        requirement_level: opt_in
      - ref: rpc.grpc.response.metadata
        requirement_level: opt_in

  - id: rpc.jsonrpc.attributes
    type: attribute_group
    stability: development
    brief: 'Tech-specific attributes for [JSON RPC](https://www.jsonrpc.org/).'
    attributes:
      - ref: rpc.jsonrpc.version
        requirement_level:
          conditionally_required: If other than the default version (`1.0`)
      - ref: rpc.jsonrpc.request_id
        requirement_level: recommended
      - ref: rpc.jsonrpc.error_code
        requirement_level:
          conditionally_required: If response is not successful.
      - ref: rpc.jsonrpc.error_message
        requirement_level: recommended
      - ref: rpc.method
        requirement_level: required
        note: >
          This is always required for jsonrpc. See the note in the general
          RPC conventions for more information.

  - id: event.rpc.message
    type: event
    stability: development
    name: rpc.message
    brief: Describes a message sent or received within the context of an RPC call.
    note: >
      In the lifetime of an RPC stream, an event for each message sent/received on
      client and server spans SHOULD be created. In case of unary calls only one sent
      and one received message will be recorded for both client and server spans.
    attributes:
      - ref: rpc.message.type
        requirement_level: recommended
      - ref: rpc.message.id
        requirement_level: recommended
      - ref: rpc.message.compressed_size
        requirement_level: recommended
      - ref: rpc.message.uncompressed_size
        requirement_level: recommended

  - id: rpc.connect_rpc.attributes
    type: attribute_group
    stability: development
    brief: 'Tech-specific attributes for Connect RPC.'
    attributes:
      - ref: rpc.connect_rpc.error_code
        requirement_level:
          conditionally_required: If response is not successful and if error code available.
      - ref: rpc.connect_rpc.request.metadata
        requirement_level: opt_in
      - ref: rpc.connect_rpc.response.metadata
        requirement_level: opt_in
