-
Notifications
You must be signed in to change notification settings - Fork 232
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 #1075 from RasaHQ/ATO-2105-create-custom-spans
[ATO-2105] Implement functionality to create custom spans
- Loading branch information
Showing
6 changed files
with
105 additions
and
3 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 @@ | ||
Implement functionality that enables creating additional spans within custom actions. |
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,23 @@ | ||
from typing import Optional | ||
from rasa_sdk.utils import Singleton | ||
from opentelemetry.trace import Tracer | ||
|
||
|
||
class ActionExecutorTracerRegister(metaclass=Singleton): | ||
"""Represents a provider for ActionExecutor tracer.""" | ||
|
||
tracer: Optional[Tracer] = None | ||
|
||
def register_tracer(self, tracer: Tracer) -> None: | ||
"""Register an ActionExecutor tracer. | ||
Args: | ||
trace: The tracer to register. | ||
""" | ||
self.tracer = tracer | ||
|
||
def get_tracer(self) -> Optional[Tracer]: | ||
"""Get the ActionExecutor tracer. | ||
Returns: | ||
The tracer. | ||
""" | ||
return self.tracer |
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,21 @@ | ||
from rasa_sdk.tracing.tracer_register import ActionExecutorTracerRegister | ||
from opentelemetry import trace | ||
|
||
|
||
def test_tracer_register_is_singleton() -> None: | ||
tracer_register_1 = ActionExecutorTracerRegister() | ||
tracer_register_2 = ActionExecutorTracerRegister() | ||
|
||
assert tracer_register_1 is tracer_register_2 | ||
assert tracer_register_1.tracer is tracer_register_2.tracer | ||
|
||
|
||
def test_trace_register() -> None: | ||
tracer_register = ActionExecutorTracerRegister() | ||
assert tracer_register.get_tracer() is None | ||
|
||
tracer = trace.get_tracer(__name__) | ||
tracer_register.register_tracer(tracer) | ||
|
||
assert tracer_register.tracer == tracer | ||
assert tracer_register.get_tracer() == tracer |