Skip to content

NatsBatchTelemetrySettingsProvider

faststream.nats.opentelemetry.provider.NatsBatchTelemetrySettingsProvider #

NatsBatchTelemetrySettingsProvider()

Bases: BaseNatsTelemetrySettingsProvider[List['Msg']]

Source code in faststream/nats/opentelemetry/provider.py
def __init__(self) -> None:
    self.messaging_system = "nats"

messaging_system instance-attribute #

messaging_system = 'nats'

get_publish_attrs_from_kwargs #

get_publish_attrs_from_kwargs(kwargs)
Source code in faststream/nats/opentelemetry/provider.py
def get_publish_attrs_from_kwargs(
    self,
    kwargs: "AnyDict",
) -> "AnyDict":
    return {
        SpanAttributes.MESSAGING_SYSTEM: self.messaging_system,
        SpanAttributes.MESSAGING_DESTINATION_NAME: kwargs["subject"],
        SpanAttributes.MESSAGING_MESSAGE_CONVERSATION_ID: kwargs["correlation_id"],
    }

get_publish_destination_name #

get_publish_destination_name(kwargs)
Source code in faststream/nats/opentelemetry/provider.py
def get_publish_destination_name(
    self,
    kwargs: "AnyDict",
) -> str:
    subject: str = kwargs.get("subject", SERVICE_NAME)
    return subject

get_consume_attrs_from_message #

get_consume_attrs_from_message(msg)
Source code in faststream/nats/opentelemetry/provider.py
def get_consume_attrs_from_message(
    self,
    msg: "StreamMessage[List[Msg]]",
) -> "AnyDict":
    return {
        SpanAttributes.MESSAGING_SYSTEM: self.messaging_system,
        SpanAttributes.MESSAGING_MESSAGE_ID: msg.message_id,
        SpanAttributes.MESSAGING_MESSAGE_CONVERSATION_ID: msg.correlation_id,
        SpanAttributes.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES: len(msg.body),
        SpanAttributes.MESSAGING_BATCH_MESSAGE_COUNT: len(msg.raw_message),
        MESSAGING_DESTINATION_PUBLISH_NAME: msg.raw_message[0].subject,
    }

get_consume_destination_name #

get_consume_destination_name(msg)
Source code in faststream/nats/opentelemetry/provider.py
def get_consume_destination_name(
    self,
    msg: "StreamMessage[List[Msg]]",
) -> str:
    return msg.raw_message[0].subject