- Package Name:
azure-eventhub
- Package Version:
5.10.1
- Operating System: Linux-Debian (docker container)
- Python Version: 3.11.1
Describe the bug
Today in an experiment with adding tracing spans to our EventhubProducerClient calls, I followed a helpful example provided by the package azure-core-tracing-opentelemetry.
After some tracing spans were produced, I noticed an exception in the logs (but these did not prevent events from being published):
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/opentelemetry/trace/__init__.py", line 573, in use_span
yield span
File "/usr/local/lib/python3.11/site-packages/azure/eventhub/_utils.py", line 181, in trace_message
event.properties.setdefault(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'MessageProperties' object has no attribute 'setdefault'
In the _utils.py module, there's a function called trace_message with a few lines like this:
if not event.properties:
event.properties = dict()
event.properties.setdefault(
b"Diagnostic-Id", message_span.get_trace_parent().encode("ascii")
)
Here, if event.properties is truthy, then it will not be a Python dict (as in my case), and instead it's an instance of MessageProperties from the uamqp library, which has no setdefault function.
To fix it, we could indent setdefault under the if not event.properties and add an else that sets the property differently for MessageProperties.
I would be happy to submit a PR for this change if it is useful.
To Reproduce
Steps to reproduce the behavior:
- Follow the example for instrumenting an
EventhubProducerClient
- Produce some events.
- Load tracing span waterfall graph matching this trace id.
- See exception screenshot below
Screenshots

Expected behavior
No exceptions when instrumenting Eventhub calls with opentelemetry tracing spans.
azure-eventhub5.10.1Describe the bug
Today in an experiment with adding tracing spans to our
EventhubProducerClientcalls, I followed a helpful example provided by the packageazure-core-tracing-opentelemetry.After some tracing spans were produced, I noticed an exception in the logs (but these did not prevent events from being published):
In the
_utils.pymodule, there's a function calledtrace_messagewith a few lines like this:Here, if
event.propertiesis truthy, then it will not be a Pythondict(as in my case), and instead it's an instance ofMessagePropertiesfrom theuamqplibrary, which has nosetdefaultfunction.To fix it, we could indent
setdefaultunder theif not event.propertiesand add anelsethat sets the property differently forMessageProperties.I would be happy to submit a PR for this change if it is useful.
To Reproduce
Steps to reproduce the behavior:
EventhubProducerClientScreenshots
Expected behavior
No exceptions when instrumenting Eventhub calls with opentelemetry tracing spans.