Skip to content

Commit

Permalink
improve otel
Browse files Browse the repository at this point in the history
  • Loading branch information
vemonet committed Dec 22, 2023
1 parent ffc6e39 commit eeefe9d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/trapi_predict_kit/trapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(
title="Translator Reasoner API",
version="1.0.0",
openapi_version="3.0.1",
add_opentelemetry=False,
opentelemetry=False,
description="""Get predicted targets for a given entity
\n\nService supported by the [NCATS Translator project](https://ncats.nih.gov/translator/about)""",
**kwargs: Any,
Expand All @@ -72,6 +72,9 @@ def __init__(
root_path_in_servers=False,
**kwargs,
)
if itrb_url_prefix and opentelemetry and not os.environ.get("NO_JAEGER"):
add_opentelemetry(self, itrb_url_prefix)

self.predict_endpoints = predict_endpoints
self.info = info
self.infores = self.info.get("x-translator", {}).get("infores")
Expand All @@ -84,9 +87,6 @@ def __init__(
# On ITRB deployment and local dev we directly use the current server
self.servers = []

if itrb_url_prefix and add_opentelemetry and not os.environ.get("NO_JAEGER"):
add_opentelemetry(self, itrb_url_prefix)

# For the API deployed on our server and registered to SmartAPI we provide the complete list
if os.getenv("VIRTUAL_HOST"):
if itrb_url_prefix:
Expand Down Expand Up @@ -279,7 +279,7 @@ def openapi(self) -> Dict[str, Any]:
return self.openapi_schema


def add_opentelemetry(app: TRAPI, service_name: str) -> None:
def add_opentelemetry(app: FastAPI, service_name: str) -> None:
"""Configure Open Telemetry
https://github.com/ranking-agent/aragorn/blob/main/src/otel_config.py#L4
https://ncatstranslator.github.io/TranslatorTechnicalDocumentation/deployment-guide/monitoring/
Expand All @@ -305,6 +305,7 @@ def add_opentelemetry(app: TRAPI, service_name: str) -> None:
warnings.filterwarnings("ignore", category=ResourceWarning)
trace.set_tracer_provider(TracerProvider(resource=Resource.create({SERVICE_NAME: service_name})))
jaeger_host = os.environ.get("JAEGER_HOST", "jaeger-otel-agent.sri")
# jaeger_host = os.environ.get("JAEGER_HOST", "localhost")
jaeger_port = int(os.environ.get("JAEGER_PORT", "6831"))
jaeger_exporter = JaegerExporter(
agent_host_name=jaeger_host,
Expand Down
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,6 @@ def get_predictions(request: PredictInput) -> PredictOutput:
\n\nService supported by the [NCATS Translator project](https://ncats.nih.gov/translator/about)""",
itrb_url_prefix="openpredict",
dev_server_url="https://openpredict.semanticscience.org",
# opentelemetry=True,
# docker run -d --name jaeger -p 16686:16686 -p 6831:6831/udp jaegertracing/all-in-one:latest
)

0 comments on commit eeefe9d

Please sign in to comment.