A tracking library for Databricks demo analytics.
Project description
dbdemos-tracker
A Python library for tracking Databricks demo analytics.
Installation
pip install dbdemos-tracker
Usage
Basic Demo Tracking
from dbdemos_tracker import Tracker
### App Usage Tracking
```python
from dbdemos_tracker import Tracker
# Create tracker for app
tracker = Tracker("your-workspace-id")
# Track app views
tracker.track_app_view("user@databricks.com", "app-name", "/dashboard")
FastAPI Middleware
from fastapi import FastAPI
from dbdemos_tracker import Tracker
app = FastAPI()
# Add middleware to track all requests automatically
app.middleware("http")(Tracker.create_fastapi_middleware("app-name"))
# Or with a custom workspace client
from databricks.sdk import WorkspaceClient
workspace_client = WorkspaceClient()
app.middleware("http")(Tracker.create_fastapi_middleware("app-name", workspace_client))
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int):
return {"item_id": item_id}
Complete Example:
from fastapi import FastAPI
from dbdemos_tracker import Tracker
# Create FastAPI app
app = FastAPI(title="My Demo App")
# Add tracking middleware - this will track ALL requests automatically
app.middleware("http")(Tracker.create_fastapi_middleware("app-name"))
# Your API endpoints
@app.get("/")
def home():
return {"message": "Welcome to my demo app"}
@app.post("/data")
def process_data(data: dict):
# This request will be automatically tracked
return {"processed": data}
@app.get("/users/{user_id}")
def get_user(user_id: str):
# This request will also be automatically tracked
return {"user_id": user_id, "name": "John Doe"}
# Run with: uvicorn main:app --reload
Streamlit Integration
EXPERIMENTAL - NOT TESTED - REACH OUT FOR HELP ON #field-demos
Automatic Interceptor (Recommended):
import streamlit as st
from dbdemos_tracker import Tracker
# Setup automatic tracking - call this once at the top of your app
Tracker.setup_streamlit_interceptor("app-name")
# Your Streamlit app - all interactions are automatically tracked!
st.title("My Demo App")
# These will be automatically tracked:
if st.button("Process Data"):
st.write("Data processed!")
name = st.text_input("Enter your name")
age = st.slider("Age", 0, 100, 25)
option = st.selectbox("Choose option", ["A", "B", "C"])
enabled = st.checkbox("Enable feature")
# Set user email for tracking (optional)
st.session_state.user_email = "user@databricks.com"
Manual Tracking (if needed):
# Track specific interactions manually
Tracker.track_streamlit_app("app-name")
Configuration
Disable Tracking
# Disable tracking globally
Tracker.enable_tracker = False
# Re-enable when needed
Tracker.enable_tracker = True
Email Filtering
The tracker automatically filters emails to only track Databricks email addresses (@databricks.com). Non-Databricks emails are ignored for privacy.
Test Workspace
Tracking is automatically disabled for test workspace ID 1660015457675682.
Features
- Track demo usage analytics
- Configurable tracking enable/disable
- Automatic Databricks email filtering
- Error handling with timeout protection
- FastAPI middleware for automatic request tracking
- Streamlit integration for app interaction tracking
- Support for both notebook and app path tracking
- User hash generation for privacy
License
Databricks License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dbdemos_tracker-0.1.3-py3-none-any.whl.
File metadata
- Download URL: dbdemos_tracker-0.1.3-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e76d39e8546ba18eb10893fccba0bfc014bf601e65b1c66a05d49394349441c8
|
|
| MD5 |
962952e08a0efcdeb175d8164404476a
|
|
| BLAKE2b-256 |
06fab3c444b475d404c612a69a59555c94bcebe94f747ef00521e132b50e30cf
|