Skip to content

Commit

Permalink
ref:extend tracer to custom actions
Browse files Browse the repository at this point in the history
  • Loading branch information
souvikg10 committed Sep 15, 2023
1 parent c2bdf97 commit 2c92578
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion rasa_sdk/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
7 changes: 4 additions & 3 deletions rasa_sdk/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions rasa_sdk/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 2c92578

Please sign in to comment.