Skip to content

Commit

Permalink
telekom tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rgstephens committed Sep 25, 2023
1 parent 2c92578 commit 0c40985
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,5 @@ examples/moodbot/models/
*.DS_Store
tests/executor_test_packages
.pytype/
.history/
.vscode/
4 changes: 3 additions & 1 deletion rasa_sdk/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ async def webhook(request: Request) -> HTTPResponse:
action_call = json.loads(decompressed_data)
else:
action_call = request.json
action_call["domain"]["tracer"] = tracer
action_call["domain"]["context"] = context
if action_call is None:
body = {"error": "Invalid body request"}
return response.json(body, status=400)
Expand All @@ -116,7 +118,7 @@ async def webhook(request: Request) -> HTTPResponse:
if auto_reload:
executor.reload()
try:
result = await executor.run(action_call, tracer, context)
result = await executor.run(action_call)
except ActionExecutionRejection as e:
logger.debug(e)
body = {"error": e.message, "action_name": e.action_name}
Expand Down
6 changes: 4 additions & 2 deletions rasa_sdk/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,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", tracer: Optional[Any] = None, context: Optional[Any] = None) -> Optional[Dict[Text, Any]]:
async def run(self, action_call: "ActionCall") -> Optional[Dict[Text, Any]]:
from rasa_sdk.interfaces import Tracker

action_name = action_call.get("next_action")
Expand All @@ -393,11 +393,13 @@ async def run(self, action_call: "ActionCall", tracer: Optional[Any] = None, con

tracker_json = action_call["tracker"]
domain = action_call.get("domain", {})
tracer = domain.get("tracer", None)
context = domain.get("context", None)
tracker = Tracker.from_dict(tracker_json)
dispatcher = CollectingDispatcher()

events = await utils.call_potential_coroutine(
action(dispatcher, tracker, domain, tracer, context)
action(dispatcher, tracker, domain)
)

if not events:
Expand Down
58 changes: 44 additions & 14 deletions rasa_sdk/tracing/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter
from rasa_sdk.tracing.endpoints import EndpointConfig, read_endpoint_config


Expand All @@ -33,22 +33,52 @@ def get_tracer_provider(endpoints_file: Text) -> Optional[TracerProvider]:
:return: The `TracingProvider` to be used for all subsequent tracing.
"""
cfg = read_endpoint_config(endpoints_file, ENDPOINTS_TRACING_KEY)
tracer_provider = None

if not cfg:
logger.info(
f"No endpoint for tracing type available in {endpoints_file},"
f"tracing will not be configured."
)
return None
if cfg.type == "jaeger":
tracer_provider = JaegerTracerConfigurer.configure_from_endpoint_config(cfg)
elif cfg.type == "otlp":
tracer_provider = OTLPCollectorConfigurer.configure_from_endpoint_config(cfg)
# set from env vars if no endpoints.yml
OTEL_EXPORTERS = os.environ.get("OTEL_EXPORTERS")
OTEL_EXPORTER_OTLP_ENDPOINT = os.environ.get("OTEL_EXPORTER_OTLP_ENDPOINT")
OTEL_JAEGER_HOSTNAME = os.environ.get("OTEL_JAEGER_HOSTNAME", "localhost")
OTEL_JAEGER_PORT = os.environ.get("OTEL_JAEGER_PORT", "4317")
OTEL_SERVICE_NAME = os.environ.get("OTEL_SERVICE_NAME", "action_server")
insecure = os.environ.get("OTEL_EXPORTER_OTLP_INSECURE", True)
if OTEL_EXPORTERS:
resource = Resource(attributes={"service.name": OTEL_SERVICE_NAME})
tracer_provider = TracerProvider(resource=resource)
for t in OTEL_EXPORTERS.split(','):
if t == 'console':
logger.info(f"Starting Console Exporter")
tracer_provider.add_span_processor(BatchSpanProcessor(ConsoleSpanExporter()))
if t == 'otlp':
logger.info(f"Starting OTLP Exporter: {OTEL_EXPORTER_OTLP_ENDPOINT}, service: {OTEL_SERVICE_NAME}")
otlp_exporter = OTLPSpanExporter(endpoint=OTEL_EXPORTER_OTLP_ENDPOINT, insecure=insecure)
processor = BatchSpanProcessor(otlp_exporter)
tracer_provider.add_span_processor(processor)
if t == 'jaeger':
logger.info(f"Starting Jaeger Exporter: {OTEL_JAEGER_HOSTNAME}:{OTEL_JAEGER_PORT}, service: {OTEL_SERVICE_NAME}")
jaeger_exporter = JaegerExporter(
agent_host_name=OTEL_JAEGER_HOSTNAME,
agent_port=OTEL_JAEGER_PORT,
)
processor = BatchSpanProcessor(jaeger_exporter)
tracer_provider.add_span_processor(processor)
else:
logger.info(
f"No endpoint for tracing type available in {endpoints_file}, "
f"tracing will not be configured."
)
return None
else:
logger.warning(
f"Unknown tracing type {cfg.type} read from {endpoints_file}, ignoring."
)
return None
if cfg.type == "jaeger":
tracer_provider = JaegerTracerConfigurer.configure_from_endpoint_config(cfg)
elif cfg.type == "otlp":
tracer_provider = OTLPCollectorConfigurer.configure_from_endpoint_config(cfg)
else:
logger.warning(
f"Unknown tracing type {cfg.type} read from {endpoints_file}, ignoring."
)
return None

return tracer_provider

Expand Down

0 comments on commit 0c40985

Please sign in to comment.