Skip to content

Commit

Permalink
Add openinference instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebCourier committed Jul 18, 2024
1 parent 4a23750 commit 40f47f8
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions guardrails_api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ def create_app(
self_endpoint = os.environ.get("SELF_ENDPOINT", f"{host}:{set_port}")
os.environ["SELF_ENDPOINT"] = self_endpoint

register_config(config)

app = Flask(__name__)
app.json = OverrideJsonProvider(app)

Expand All @@ -84,6 +82,8 @@ def create_app(
FlaskInstrumentor().instrument_app(app)
initialize()

register_config(config)

# if no pg_host is set, don't set up postgres
if postgres_is_enabled():
from guardrails_api.clients.postgres_client import PostgresClient
Expand Down
4 changes: 4 additions & 0 deletions guardrails_api/otel/traces.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import (
OTLPSpanExporter as GrpcSpanExporter,
)
from openinference.instrumentation.guardrails import GuardrailsInstrumentor
from guardrails_api.otel.constants import none


Expand Down Expand Up @@ -68,5 +69,8 @@ def initialize_tracer():
for exporter in trace_exporters:
set_span_processors(tracer_provider, exporter, use_batch)

# Instrument with OpenInference
GuardrailsInstrumentor().instrument(tracer_provider=tracer_provider)

# Initialize singleton
get_tracer()
3 changes: 2 additions & 1 deletion guardrails_api/start-dev.sh
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
gunicorn --bind 0.0.0.0:8000 --timeout=5 --threads=10 "guardrails_api.app:create_app()" --reload --capture-output --enable-stdio-inheritance
# TODO: Have to pass the config file to this now or it will blow up.
gunicorn --bind 0.0.0.0:8000 --timeout=5 --workers=1 "guardrails_api.app:create_app()" --reload --capture-output --enable-stdio-inheritance
3 changes: 2 additions & 1 deletion guardrails_api/start.sh
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
gunicorn --bind 0.0.0.0:8000 --timeout=5 --threads=10 "guardrails_api.app:create_app()"
# TODO: Have to pass the config file to this now or it will blow up.
gunicorn --bind 0.0.0.0:8000 --timeout=5 --workers=1 "guardrails_api.app:create_app()"
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ readme = "README.md"
keywords = ["Guardrails", "Guardrails AI", "Guardrails API", "Guardrails API"]
requires-python = ">= 3.8.1"
dependencies = [
"guardrails-ai>=0.5.0a11",
"guardrails-ai>=0.5.0",
"flask>=3.0.3,<4",
"Flask-SQLAlchemy>=3.1.1,<4",
"Flask-Caching>=2.3.0,<3",
Expand All @@ -27,6 +27,7 @@ dependencies = [
"opentelemetry-exporter-otlp-proto-grpc>=1.0.0,<2",
"opentelemetry-exporter-otlp-proto-http>=1.0.0,<2",
"opentelemetry-instrumentation-flask>=0.12b0,<1",
"openinference-instrumentation-guardrails>=0.1.0"
]

[tool.setuptools.dynamic]
Expand Down

0 comments on commit 40f47f8

Please sign in to comment.