Skip to content

Commit

Permalink
Merge pull request #178 from ymorin-orange/nyma/otel-spans
Browse files Browse the repository at this point in the history
python/iot3: extend OpenTelemetry attributes
  • Loading branch information
ymorin-orange authored Oct 24, 2024
2 parents 9b97d2d + bc7dc8e commit 2eb528a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
15 changes: 9 additions & 6 deletions python/iot3/src/iot3/core/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ def publish(self, *, topic: str, payload: bytes | str):
:param payload: The payload to post.
"""
with self.span_ctxmgr_cb(
name="IoT3 Core MQTT message",
name="IoT3 Core MQTT Message",
kind=otel.SpanKind.PRODUCER,
) as span:
new_traceparent = span.to_traceparent()
span.set_attribute(key="test.iot3.core.mqtt.action", value="publish")
span.set_attribute(key="test.iot3.core.mqtt.topic", value=topic)
span.set_attribute(key="iot3.core.mqtt.topic", value=topic)
span.set_attribute(key="iot3.core.mqtt.payload_size", value=len(payload))
properties = paho.mqtt.properties.Properties(
paho.mqtt.packettypes.PacketTypes.PUBLISH,
)
Expand Down Expand Up @@ -281,7 +281,7 @@ def __on_message(
message: paho.mqtt.client.MQTTMessage,
):
span_kwargs = {
"name": "IoT3 Core MQTT message",
"name": "IoT3 Core MQTT Message",
"kind": otel.SpanKind.CONSUMER,
}
try:
Expand All @@ -292,8 +292,11 @@ def __on_message(
pass
with self.span_ctxmgr_cb(**span_kwargs) as span:
new_traceparent = span.to_traceparent()
span.set_attribute(key="test.iot3.core.mqtt.action", value="receive")
span.set_attribute(key="test.iot3.core.mqtt.topic", value=message.topic)
span.set_attribute(key="iot3.core.mqtt.topic", value=message.topic)
span.set_attribute(
key="iot3.core.mqtt.payload_size",
value=len(message.payload),
)
self.msg_cb(
data=self.msg_cb_data,
topic=message.topic,
Expand Down
1 change: 1 addition & 0 deletions python/iot3/src/iot3/core/otel.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ def __init__(
for span in span_links:
self.add_link(link=span)
self.status_code = SpanStatus.UNSET
self.set_attribute(key="iot3.core.sdk_language", value="python")
self.status_message = None

def finalise(self):
Expand Down

0 comments on commit 2eb528a

Please sign in to comment.