Skip to content

armgit / burr

Public Imported from GitHub
0

Build applications that make decisions (chatbots, agents, simulations, etc...). Monitor, trace, persist, and execute on your own infrastructure.

Automatically instruments demo apps, adds to install target

elijahbenizzy9518985367a0
diff --git a/examples/email-assistant/server.py b/examples/email-assistant/server.py
index 2f2cc739..1cc41f95 100644
--- a/examples/email-assistant/server.py
+++ b/examples/email-assistant/server.py
@@ -23,6 +23,15 @@ app = FastAPI()
router = APIRouter()
+try:
+ from opentelemetry.instrumentation.openai import OpenAIInstrumentor
+
+ OpenAIInstrumentor().instrument()
+ opentelemetry_available = True
+except ImportError:
+ opentelemetry_available = False
+
+
# we want to render this after every response
class EmailAssistantState(pydantic.BaseModel):
app_id: str
@@ -73,7 +82,10 @@ def _get_application(project_id: str, app_id: str) -> Application:
builder = (
ApplicationBuilder()
.with_graph(graph)
- .with_tracker(tracker := LocalTrackingClient(project=project_id))
+ .with_tracker(
+ tracker := LocalTrackingClient(project=project_id),
+ use_otel_tracing=opentelemetry_available,
+ )
.with_identifiers(app_id=app_id)
.initialize_from(
tracker,
diff --git a/examples/multi-modal-chatbot/server.py b/examples/multi-modal-chatbot/server.py
index 344e819a..c535a1b6 100644
--- a/examples/multi-modal-chatbot/server.py
+++ b/examples/multi-modal-chatbot/server.py
@@ -27,6 +27,14 @@ router = APIRouter()
graph = chat_application.graph
+try:
+ from opentelemetry.instrumentation.openai import OpenAIInstrumentor
+
+ OpenAIInstrumentor().instrument()
+ opentelemetry_available = True
+except ImportError:
+ opentelemetry_available = False
+
class ChatItem(pydantic.BaseModel):
"""Pydantic model for a chat item. This is used to render the chat history."""
@@ -50,7 +58,7 @@ def _get_application(project_id: str, app_id: str) -> Application:
default_state={"chat_history": []},
default_entrypoint="prompt",
)
- .with_tracker(tracker)
+ .with_tracker(tracker, use_otel_tracing=opentelemetry_available)
.with_identifiers(app_id=app_id)
.build()
)
diff --git a/examples/streaming-fastapi/server.py b/examples/streaming-fastapi/server.py
index 51a1b15e..93ce3941 100644
--- a/examples/streaming-fastapi/server.py
+++ b/examples/streaming-fastapi/server.py
@@ -30,6 +30,15 @@ router = APIRouter()
graph = chat_application.graph
+try:
+ from opentelemetry.instrumentation.openai import OpenAIInstrumentor
+
+ OpenAIInstrumentor().instrument()
+ opentelemetry_available = True
+except ImportError:
+ opentelemetry_available = False
+
+
class ChatItem(pydantic.BaseModel):
"""Pydantic model for a chat item. This is used to render the chat history."""
@@ -52,7 +61,7 @@ def _get_application(project_id: str, app_id: str) -> Application:
default_state={"chat_history": []},
default_entrypoint="prompt",
)
- .with_tracker(tracker)
+ .with_tracker(tracker, use_otel_tracing=opentelemetry_available)
.with_identifiers(app_id=app_id)
.build()
)
diff --git a/pyproject.toml b/pyproject.toml
index a009c196..dcd79cb2 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -154,12 +154,17 @@ tracking = [
]
learn = [
- "burr[tracking,streamlit,graphviz,hamilton, cli]"
+ "burr[tracking,streamlit,graphviz,hamilton,cli,inappexamples]"
]
start = [
"burr[learn]"
]
+inappexamples = [
+ "opentelemetry-api",
+ "opentelemetry-sdk",
+ 'opentelemetry-instrumentation-openai',
+]
# All the bloatware from various LLM demos
# In the future most people will be relying on simple APIs, not this
@@ -169,9 +174,7 @@ examples = [
"langchain",
"langchain-community",
"langchain-openai",
- "opentelemetry-api",
- "opentelemetry-sdk",
- 'opentelemetry-instrumentation-openai',
+ "burr[inappexamples]"
]
# just install everything for developers