sandbox-notebookllamalm/src/notebookllama/instrumentation_init.py
DJP 2292f8a511 Transform NotebookLlaMa to enterprise multi-user NotebookLM clone
Major Changes:
- Implemented notebook-first architecture (multi-document collections)
- Added user authentication and multi-tenancy
- Created comprehensive database schema (7 tables)
- Built complete notebook management system
- Implemented notebook-level chat across multiple documents
- Added podcast generation from notebooks
- Implemented notebook sharing with permissions
- Fixed MCP server crashes by bypassing for document processing
- Added all enterprise features requested

New Features:
- User login/signup with bcrypt password hashing
- Create/edit/delete notebooks
- Upload multiple PDFs to notebooks
- Add documents to existing notebooks
- Chat across all documents in a notebook
- Generate podcasts from entire notebooks
- Share notebooks with other users
- View shared notebooks
- Persistent chat history per notebook
- Document summaries, Q&A, and highlights

Technical Improvements:
- PostgreSQL database with SQLAlchemy ORM
- Connection pooling and proper cleanup
- Bypassed buggy MCP server for document processing
- Direct LlamaCloud API calls for reliability
- Proper CASCADE deletes
- Session management
- Error handling and logging

Documentation:
- ENTERPRISE_SETUP.md - Setup guide
- IMPLEMENTATION_SUMMARY.md - Technical details
- SIMPLIFIED_PLAN.md - Architecture overview
- CURRENT_STATUS.md - Status and known issues
- FINAL_README.md - User guide

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-01 17:28:06 -04:00

46 lines
1.4 KiB
Python

"""Global instrumentation initialization - initialize once"""
import os
from dotenv import load_dotenv
from instrumentation import OtelTracesSqlEngine
from llama_index.observability.otel import LlamaIndexOpenTelemetry
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
load_dotenv()
# Global singletons
_instrumentor = None
_sql_engine = None
def get_instrumentor():
"""Get or create the global instrumentor"""
global _instrumentor
if _instrumentor is None:
span_exporter = OTLPSpanExporter("http://0.0.0.0:4318/v1/traces")
_instrumentor = LlamaIndexOpenTelemetry(
service_name_or_resource="agent.traces",
span_exporter=span_exporter,
debug=False # Set to False to reduce noise
)
_instrumentor.start_registering()
return _instrumentor
def get_sql_engine():
"""Get or create the global SQL engine for traces"""
global _sql_engine
if _sql_engine is None:
_sql_engine = OtelTracesSqlEngine(
engine_url=f"postgresql+psycopg2://{os.getenv('pgql_user')}:{os.getenv('pgql_psw')}@localhost:5432/{os.getenv('pgql_db')}",
table_name="agent_traces",
service_name="agent.traces",
)
return _sql_engine
# Initialize on import
try:
get_instrumentor()
except Exception as e:
print(f"Warning: Failed to initialize instrumentation: {e}")