diff --git a/rasa_sdk/endpoint.py b/rasa_sdk/endpoint.py index 4c2a038f0..0cbb28603 100644 --- a/rasa_sdk/endpoint.py +++ b/rasa_sdk/endpoint.py @@ -116,7 +116,7 @@ async def webhook(request: Request) -> HTTPResponse: if auto_reload: executor.reload() try: - result = await executor.run(action_call) + result = await executor.run(action_call, tracer, context) except ActionExecutionRejection as e: logger.debug(e) body = {"error": e.message, "action_name": e.action_name} diff --git a/rasa_sdk/executor.py b/rasa_sdk/executor.py index 5d3e7a9f4..98633dd1f 100644 --- a/rasa_sdk/executor.py +++ b/rasa_sdk/executor.py @@ -9,10 +9,11 @@ import types import sys import os - +from opentelemetry.sdk.trace import TracerProvider from rasa_sdk.interfaces import Tracker, ActionNotFoundException, Action from rasa_sdk import utils +from rasa_sdk.tracing.utils import get_tracer_and_context, set_span_attributes if typing.TYPE_CHECKING: # pragma: no cover from rasa_sdk.types import ActionCall @@ -380,7 +381,7 @@ def validate_events(events: List[Dict[Text, Any]], action_name: Text): # we won't append this to validated events -> will be ignored return validated - async def run(self, action_call: "ActionCall") -> Optional[Dict[Text, Any]]: + async def run(self, action_call: "ActionCall", tracer: Optional[Any] = None, context: Optional[Any] = None) -> Optional[Dict[Text, Any]]: from rasa_sdk.interfaces import Tracker action_name = action_call.get("next_action") @@ -396,7 +397,7 @@ async def run(self, action_call: "ActionCall") -> Optional[Dict[Text, Any]]: dispatcher = CollectingDispatcher() events = await utils.call_potential_coroutine( - action(dispatcher, tracker, domain) + action(dispatcher, tracker, domain, tracer, context) ) if not events: diff --git a/rasa_sdk/interfaces.py b/rasa_sdk/interfaces.py index d4ec22194..ac1d586fc 100644 --- a/rasa_sdk/interfaces.py +++ b/rasa_sdk/interfaces.py @@ -334,6 +334,8 @@ async def run( dispatcher: "CollectingDispatcher", tracker: Tracker, domain: "DomainDict", + tracer: Optional[Any] = None, + context: Optional[Any] = None ) -> List[Dict[Text, Any]]: """Execute the side effects of this action.