groups:
  - id: messaging.message
    type: attribute_group
    brief: 'Semantic convention describing per-message attributes populated on messaging spans or links.'
    attributes:
      - ref: messaging.destination.name
      - ref: messaging.message.id
      - ref: messaging.message.conversation_id
      - ref: messaging.message.envelope.size
      - ref: messaging.message.body.size

  - id: messaging.destination
    type: attribute_group
    brief: 'Semantic convention for attributes that describe messaging destination on broker'
    note: |
      Destination attributes should be set on publish, receive, or other spans
      describing messaging operations.

      Destination attributes should be set when the messaging operation handles
      single messages. When the operation handles a batch of messages,
      the destination attributes should only be applied when the attribute value
      applies to all messages in the batch.
      In other cases, destination attributes may be set on links.
    attributes:
      - ref: messaging.destination.name
      - ref: messaging.destination.template
      - ref: messaging.destination.temporary
      - ref: messaging.destination.anonymous

  - id: messaging.destination_publish
    prefix: messaging.destination_publish
    type: attribute_group
    brief: >
      Semantic convention for attributes that describe the publish messaging destination on broker.
      The term Publish Destination refers to the destination the message was originally published to.
      These attributes should be used on the consumer side when information about
      the publish destination is available and different than the destination message are consumed from.
    note: |
      Publish destination attributes should be set on publish, receive,
      or other spans describing messaging operations.
      Destination attributes should be set when the messaging operation handles
      single messages. When the operation handles a batch of messages,
      the destination attributes should only be applied when the attribute value
      applies to all messages in the batch.
      In other cases, destination attributes may be set on links.
    attributes:
      - ref: messaging.destination_publish.name
      - ref: messaging.destination_publish.anonymous

  - id: messaging
    type: span
    brief: >
        This document defines general attributes used in
        messaging systems.
    attributes:
      - ref: messaging.system
        requirement_level: required
      - ref: messaging.operation
        requirement_level: required
      - ref: messaging.batch.message_count
        requirement_level:
          conditionally_required: If the span describes an operation on a batch of messages.
      - ref: messaging.client_id
        requirement_level:
          recommended: If a client id is available
      - ref: messaging.destination.name
        requirement_level:
          conditionally_required: If span describes operation on a single message or if the value applies to all messages in the batch.
      - ref: messaging.destination.template
        requirement_level:
          conditionally_required: >
            If available. Instrumentations MUST NOT use `messaging.destination.name` as template
            unless low-cardinality of destination name is guaranteed.
      - ref: messaging.destination.temporary
        requirement_level:
          conditionally_required: If value is `true`. When missing, the value is assumed to be `false`.
      - ref: messaging.destination.anonymous
        requirement_level:
          conditionally_required: If value is `true`. When missing, the value is assumed to be `false`.
      - ref: messaging.message.id
        requirement_level:
          recommended: Only for spans that represent an operation on a single message.
      - ref: messaging.message.conversation_id
        requirement_level:
          recommended: Only if span represents operation on a single message.
      - ref: messaging.message.envelope.size
        requirement_level:
          recommended: Only if span represents operation on a single message.
      - ref: messaging.message.body.size
        requirement_level:
          recommended: Only if span represents operation on a single message.
      - ref: server.address
        note: >
          This should be the IP/hostname of the broker (or other network-level peer) this specific message is sent to/received from.
        requirement_level:
          conditionally_required: If available.
      - ref: network.peer.address
        tag: connection-level
      - ref: network.peer.port
        requirement_level:
          recommended: If `network.peer.address` is set.
        tag: connection-level
      - ref: network.transport
        tag: connection-level
      - ref: network.type
        tag: connection-level
      - ref: network.protocol.name
        examples: ['amqp', 'mqtt']
      - ref: network.protocol.version

  - id: messaging.rabbitmq
    type: attribute_group
    extends: messaging
    brief: >
      Attributes for RabbitMQ
    attributes:
      - ref: messaging.rabbitmq.destination.routing_key
        requirement_level:
          conditionally_required: If not empty.
        tag: tech-specific-rabbitmq

  - id: messaging.kafka
    type: attribute_group
    extends: messaging
    brief: >
      Attributes for Apache Kafka
    attributes:
      - ref: messaging.kafka.message.key
        tag: tech-specific-kafka
      - ref: messaging.kafka.consumer.group
        tag: tech-specific-kafka
      - ref: messaging.kafka.destination.partition
        tag: tech-specific-kafka
      - ref: messaging.kafka.message.offset
        tag: tech-specific-kafka
      - ref: messaging.kafka.message.tombstone
        requirement_level:
          conditionally_required: If value is `true`. When missing, the value is assumed to be `false`.
        tag: tech-specific-kafka

  - id: messaging.rocketmq
    type: attribute_group
    extends: messaging
    brief: >
      Attributes for Apache RocketMQ
    attributes:
      - ref: messaging.rocketmq.namespace
        requirement_level: required
        tag: tech-specific-rocketmq
      - ref: messaging.rocketmq.client_group
        requirement_level: required
        tag: tech-specific-rocketmq
      - ref: messaging.rocketmq.message.delivery_timestamp
        requirement_level:
          conditionally_required: If the message type is delay and delay time level is not specified.
        tag: tech-specific-rocketmq
      - ref: messaging.rocketmq.message.delay_time_level
        requirement_level:
          conditionally_required: If the message type is delay and delivery timestamp is not specified.
        tag: tech-specific-rocketmq
      - ref: messaging.rocketmq.message.group
        requirement_level:
          conditionally_required: If the message type is FIFO.
        tag: tech-specific-rocketmq
      - ref: messaging.rocketmq.message.type
        tag: tech-specific-rocketmq
      - ref: messaging.rocketmq.message.tag
        tag: tech-specific-rocketmq
      - ref: messaging.rocketmq.message.keys
        tag: tech-specific-rocketmq
      - ref: messaging.rocketmq.consumption_model
        tag: tech-specific-rocketmq
