Skip to main content

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

Manual App Usage Tracking

from dbdemos_tracker import Tracker

# Create tracker for app - Use your repo name as app name
ws = WorkspaceClient()
tracker = Tracker(org_id=ws.get_workspace_id(), demo_name="app-name")

# Track app views in functions
@app.get("/")
def home():
    tracker.track_app_view(user_email="user@databricks.com", app_path="/dashboard")
    return {"message": "Welcome to my demo app"}

FastAPI Middleware

We provide a tool to track all app views out of the box.

Try to filter on the main actions so that we don't have too many views using patterns=["/my/.*/url/to/track", "..."]

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
Tracker.add_tracker_fastapi(app, "app-name"))
# You can also filter to only track some URL:
Tracker.add_tracker_fastapi(app, "app-name", patterns=['/demos/.*/load']))

# Then all your API endpoints will be tracked out of the box
@app.get("/")
def home():
    return {"message": "Welcome to my demo app"}

# 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dbdemos_tracker-0.1.6-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file dbdemos_tracker-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for dbdemos_tracker-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 f200b78c910c4dc598fdb1a2ef3f30a60d1b60dd11d06efcc0ed3b2144babe75
MD5 f14f5dd24e93a94232b73455b4b16587
BLAKE2b-256 381a0fad0f04110df6bb6a113a82074075ffc456322609ba2e3a602f70e42cda

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page