Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ServiceBus] Update tracing #29995

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions sdk/servicebus/azure-servicebus/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@

### Other Changes

- Updated tracing ([#29995](https://github.com/Azure/azure-sdk-for-python/pull/29995)):
- A span will now be created upon calls to the service that settle messages.
- Additional attributes added to spans:
- `messaging.system` - messaging system (i.e., `servicebus`)
- `messaging.operation` - type of operation (i.e., `publish`, `receive`, or `settle`)
- `messaging.batch.message_count` - number of messages sent or received (if more than one)
- `messaging.source.name` added to receive spans in place of `message_bus.destination`
- All `send` spans now contain links to `message` spans. Now, `message` spans will no longer contain a link to the `send` span.
kashifkhan marked this conversation as resolved.
Show resolved Hide resolved

## 7.10.0b1 (2023-04-13)

### Features Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@
TOKEN_TYPE_SASTOKEN,
MGMT_REQUEST_OP_TYPE_ENTITY_MGMT,
ASSOCIATEDLINKPROPERTYNAME,
TRACE_NAMESPACE_PROPERTY,
TRACE_COMPONENT_PROPERTY,
TRACE_COMPONENT,
TRACE_PEER_ADDRESS_PROPERTY,
TRACE_BUS_DESTINATION_PROPERTY,
)

if TYPE_CHECKING:
Expand Down Expand Up @@ -543,12 +538,6 @@ def _mgmt_request_response_with_retry(
**kwargs
)

def _add_span_request_attributes(self, span):
span.add_attribute(TRACE_COMPONENT_PROPERTY, TRACE_COMPONENT)
span.add_attribute(TRACE_NAMESPACE_PROPERTY, TRACE_NAMESPACE_PROPERTY)
span.add_attribute(TRACE_BUS_DESTINATION_PROPERTY, self._entity_path)
span.add_attribute(TRACE_PEER_ADDRESS_PROPERTY, self.fully_qualified_namespace)

def _open(self): # pylint: disable=no-self-use
raise ValueError("Subclass should override the method.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,31 +137,6 @@
"ServiceBusDlqSupplementaryAuthorization"
)

# Distributed Tracing Constants

TRACE_COMPONENT_PROPERTY = "component"
TRACE_COMPONENT = "servicebus"

TRACE_NAMESPACE_PROPERTY = "az.namespace"
TRACE_NAMESPACE = "ServiceBus"

SPAN_NAME_RECEIVE = TRACE_NAMESPACE + ".receive"
SPAN_NAME_RECEIVE_DEFERRED = TRACE_NAMESPACE + ".receive_deferred"
SPAN_NAME_PEEK = TRACE_NAMESPACE + ".peek"
SPAN_NAME_SEND = TRACE_NAMESPACE + ".send"
SPAN_NAME_SCHEDULE = TRACE_NAMESPACE + ".schedule"
SPAN_NAME_MESSAGE = TRACE_NAMESPACE + ".message"

TRACE_BUS_DESTINATION_PROPERTY = "message_bus.destination"
TRACE_PEER_ADDRESS_PROPERTY = "peer.address"

SPAN_ENQUEUED_TIME_PROPERTY = "enqueuedTime"

TRACE_ENQUEUED_TIME_PROPERTY = b"x-opt-enqueued-time"
TRACE_PARENT_PROPERTY = b"Diagnostic-Id"
TRACE_PROPERTY_ENCODING = "ascii"


MAX_MESSAGE_LENGTH_BYTES = 1024 * 1024 # Backcompat with uAMQP
MESSAGE_PROPERTY_MAX_LENGTH = 128
# .NET TimeSpan.MaxValue: 10675199.02:48:05.4775807
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
from .utils import (
utc_from_timestamp,
utc_now,
trace_message,
transform_outbound_messages,
)
from .tracing import trace_message

if TYPE_CHECKING:
try:
Expand All @@ -60,7 +60,6 @@
except ImportError:
pass
from .._pyamqp.performatives import TransferFrame
from azure.core.tracing import AbstractSpan
from ..aio._servicebus_receiver_async import (
ServiceBusReceiver as AsyncServiceBusReceiver,
)
Expand Down Expand Up @@ -659,6 +658,7 @@ def __init__(
**kwargs: Any
) -> None:
self._amqp_transport = kwargs.pop("amqp_transport", PyamqpTransport)
self._tracing_attributes: Dict[str, Union[str, int]] = kwargs.pop("tracing_attributes", {})

self._max_size_in_bytes = max_size_in_bytes or MAX_MESSAGE_LENGTH_BYTES
self._message = self._amqp_transport.build_batch_message([])
Expand All @@ -676,15 +676,11 @@ def __repr__(self) -> str:
def __len__(self) -> int:
return self._count

def _from_list(self, messages: Iterable[ServiceBusMessage], parent_span: Optional["AbstractSpan"] = None) -> None:
def _from_list(self, messages: Iterable[ServiceBusMessage]) -> None:
for message in messages:
self._add(message, parent_span)
self._add(message)

def _add(
self,
add_message: Union[ServiceBusMessage, Mapping[str, Any], AmqpAnnotatedMessage],
parent_span: Optional["AbstractSpan"] = None
) -> None:
def _add(self, add_message: Union[ServiceBusMessage, Mapping[str, Any], AmqpAnnotatedMessage]) -> None:
"""Actual add implementation. The shim exists to hide the internal parameters such as parent_span."""
outgoing_sb_message = transform_outbound_messages(
add_message, ServiceBusMessage, self._amqp_transport.to_outgoing_amqp_message
Expand All @@ -694,8 +690,8 @@ def _add(
outgoing_sb_message._message = trace_message(
outgoing_sb_message._message,
amqp_transport=self._amqp_transport,
parent_span=parent_span
) # parent_span is e.g. if built as part of a send operation.
additional_attributes=self._tracing_attributes
)
message_size = self._amqp_transport.get_message_encoded_size(
outgoing_sb_message._message # pylint: disable=protected-access
)
Expand Down
Loading