-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1074 from RasaHQ/ATO-2102-instrument-ValidationAc…
…tion.run [ATO-2102] Instrument `ValidationAction.run`
- Loading branch information
Showing
7 changed files
with
160 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Instrument `ValidationAction.run` method and extract attributes `class_name`, `sender_id`, `action_name` and `slots_to_validate`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from typing import List, Sequence | ||
|
||
import pytest | ||
from opentelemetry.sdk.trace import ReadableSpan, TracerProvider | ||
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter | ||
|
||
from rasa_sdk.tracing.instrumentation import instrumentation | ||
from tests.tracing.instrumentation.conftest import MockValidationAction | ||
from rasa_sdk import Tracker | ||
from rasa_sdk.executor import CollectingDispatcher | ||
from rasa_sdk.events import SlotSet, EventType | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"events, expected_slots_to_validate", | ||
[ | ||
([], "[]"), | ||
( | ||
[SlotSet("name", "Tom"), SlotSet("address", "Berlin")], | ||
'["name", "address"]', | ||
), | ||
], | ||
) | ||
@pytest.mark.asyncio | ||
async def test_tracing_action_executor_run( | ||
tracer_provider: TracerProvider, | ||
span_exporter: InMemorySpanExporter, | ||
previous_num_captured_spans: int, | ||
events: List[EventType], | ||
expected_slots_to_validate: str, | ||
) -> None: | ||
component_class = MockValidationAction | ||
|
||
instrumentation.instrument( | ||
tracer_provider, | ||
validation_action_class=component_class, | ||
) | ||
|
||
mock_validation_action = component_class() | ||
dispatcher = CollectingDispatcher() | ||
tracker = Tracker.from_dict({"sender_id": "test", "events": events}) | ||
|
||
await mock_validation_action.run(dispatcher, tracker, {}) | ||
|
||
captured_spans: Sequence[ | ||
ReadableSpan | ||
] = span_exporter.get_finished_spans() # type: ignore | ||
|
||
num_captured_spans = len(captured_spans) - previous_num_captured_spans | ||
assert num_captured_spans == 1 | ||
|
||
captured_span = captured_spans[-1] | ||
|
||
assert captured_span.name == "ValidationAction.MockValidationAction.run" | ||
|
||
expected_attributes = { | ||
"class_name": component_class.__name__, | ||
"sender_id": "test", | ||
"slots_to_validate": expected_slots_to_validate, | ||
"action_name": "mock_validation_action", | ||
} | ||
|
||
assert captured_span.attributes == expected_attributes |