From 8733d1454ce15d42e730d67b410ca9f2b73f1720 Mon Sep 17 00:00:00 2001 From: Anca Lita <27920906+ancalita@users.noreply.github.com> Date: Mon, 19 Aug 2024 14:41:59 +0100 Subject: [PATCH] [ATO-2697] Stringify None attribute values to fix opentelemetry warning (#1135) * stringify None values * add changelog entry --- changelog/1135.misc.md | 2 ++ rasa_sdk/tracing/instrumentation/attribute_extractors.py | 2 +- rasa_sdk/tracing/utils.py | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 changelog/1135.misc.md diff --git a/changelog/1135.misc.md b/changelog/1135.misc.md new file mode 100644 index 000000000..e4d7f9009 --- /dev/null +++ b/changelog/1135.misc.md @@ -0,0 +1,2 @@ +Stringify `None` values for `message_id` and `sender_id` tracing tags to fix the +`opentelemetry` warning about invalid type `NoneType` for these tags. diff --git a/rasa_sdk/tracing/instrumentation/attribute_extractors.py b/rasa_sdk/tracing/instrumentation/attribute_extractors.py index ff389438c..40fd0051f 100644 --- a/rasa_sdk/tracing/instrumentation/attribute_extractors.py +++ b/rasa_sdk/tracing/instrumentation/attribute_extractors.py @@ -25,7 +25,7 @@ def extract_attrs_for_action_executor( :param action_call: The `ActionCall` argument. :return: A dictionary containing the attributes. """ - attributes = {"sender_id": action_call["sender_id"]} + attributes = {"sender_id": action_call.get("sender_id", "None")} action_name = action_call.get("next_action") if action_name: diff --git a/rasa_sdk/tracing/utils.py b/rasa_sdk/tracing/utils.py index 719b9f1ac..55b89dbfd 100644 --- a/rasa_sdk/tracing/utils.py +++ b/rasa_sdk/tracing/utils.py @@ -43,7 +43,7 @@ def set_span_attributes(span: Any, action_call: dict) -> None: "next_action": action_call.get("next_action"), "version": action_call.get("version"), "sender_id": tracker.get("sender_id"), - "message_id": tracker.get("latest_message", {}).get("message_id"), + "message_id": tracker.get("latest_message", {}).get("message_id", "None"), } if span.is_recording():