Observability integration with Spinal
Project description
sp-obs
SP-OBS is Spinal's cost tracking library built on top of OpenTelemetry. It works by automatically instrumenting HTTP libraries (httpx, requests) and attaching a processor to existing OpenTelemetry setups. This dual approach allows it to integrate seamlessly with existing observability frameworks while selectively forwarding AI/LLM operations and billing events to Spinal's platform.
Features
- Seamlessly integrates with existing OpenTelemetry setups
- Works with Logfire, vanilla OpenTelemetry, or any OTEL-compatible framework
- Automatic instrumentation of httpx and requests libraries
- Adds user and workflow context to spans for better tracking
- Selective span processing - only sends relevant AI/billing spans
- Built-in data scrubbing for sensitive information
Installation
pip install sp-obs
Quick Start
import sp_obs
# Configure with your API key
sp_obs.configure(api_key="your-api-key")
# That's it! AI calls are now tracked automatically
Adding Context
Use tags to add business context to your AI operations:
# Context manager (recommended)
with sp_obs.tag(user_id="user-123", workflow_id="chat-session"):
# All AI calls here will be tagged
response = openai_client.chat.completions.create(...)
# Or set tags globally
sp_obs.tag(user_id="user-123", workflow_id="chat-session")
Supported Providers
- OpenAI - GPT-4, GPT-3.5, DALL-E, Whisper, Embeddings
- Anthropic - Claude 3 (Opus, Sonnet, Haiku), Claude 2
- ElevenLabs - Text-to-speech
- Perplexity - Online LLMs with search
- Deepgram - Speech-to-text
- SerpAPI - Search results
- ScrapingBee - Web scraping
- Firecrawl - Web crawling
Billing Events
Track custom billing events:
sp_obs.add_billing_event(
success=True,
user_id="user-123",
amount=99.99,
currency="USD"
)
Environment Variables
SPINAL_API_KEY- Your API keySPINAL_TRACING_ENDPOINT- Custom endpoint (default: https://cloud.withspinal.com)
Advanced Configuration
Batch Processing
Control how spans are batched and exported:
sp_obs.configure(
api_key="your-api-key",
max_queue_size=2048, # Max buffered spans before dropping
max_export_batch_size=512, # Spans per batch
schedule_delay_millis=5000, # Export interval (ms)
export_timeout_millis=30000 # Export timeout (ms)
)
Data Scrubbing
Automatically redact sensitive information from spans:
from sp_obs import DefaultScrubber, NoOpScrubber
# Use default scrubber (removes tokens, keys, passwords)
sp_obs.configure(
api_key="your-api-key",
scrubber=DefaultScrubber()
)
# Disable scrubbing
sp_obs.configure(
api_key="your-api-key",
scrubber=NoOpScrubber()
)
# Custom scrubber
class CustomScrubber:
def scrub_attributes(self, attributes: dict) -> dict:
# Your scrubbing logic
return attributes
sp_obs.configure(
api_key="your-api-key",
scrubber=CustomScrubber()
)
Additional Options
sp_obs.configure(
api_key="your-api-key",
endpoint="https://custom.endpoint.com", # Custom endpoint
headers={"X-Custom": "header"}, # Additional headers
timeout=10, # Request timeout (seconds)
set_global_tracer=False # Disable if using another tracer
)
License
MIT
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 Distribution
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 sp_obs-0.4.0.tar.gz.
File metadata
- Download URL: sp_obs-0.4.0.tar.gz
- Upload date:
- Size: 66.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d46dd6cd14e68ee31a1f7aa89d86f01cc1659c298542fe57f68c056abb4a7cda
|
|
| MD5 |
ab5131dcb8d780aca75ce500ac5ac40e
|
|
| BLAKE2b-256 |
abf17f6ebef3e2011dbb517c2b3eee52521765005375ed131da3aab62254dfd1
|
Provenance
The following attestation bundles were made for sp_obs-0.4.0.tar.gz:
Publisher:
publish-to-pypi.yml on withspinal/sp-obs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sp_obs-0.4.0.tar.gz -
Subject digest:
d46dd6cd14e68ee31a1f7aa89d86f01cc1659c298542fe57f68c056abb4a7cda - Sigstore transparency entry: 538884124
- Sigstore integration time:
-
Permalink:
withspinal/sp-obs@8047ed5d71cd23d085c7f9a5333e31e14006b06b -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/withspinal
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@8047ed5d71cd23d085c7f9a5333e31e14006b06b -
Trigger Event:
push
-
Statement type:
File details
Details for the file sp_obs-0.4.0-py3-none-any.whl.
File metadata
- Download URL: sp_obs-0.4.0-py3-none-any.whl
- Upload date:
- Size: 29.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4008c05d734e4043fb37cc6fe0e7f93be67f6511a98c4aa7ea31cc909fb5bf39
|
|
| MD5 |
b23b011787ccdf9c69778546f1ced1c6
|
|
| BLAKE2b-256 |
fb6ec4863d564bcabff080b5ed54cff5366fa85beb6aa4e5565b661eaac5b0f9
|
Provenance
The following attestation bundles were made for sp_obs-0.4.0-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on withspinal/sp-obs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sp_obs-0.4.0-py3-none-any.whl -
Subject digest:
4008c05d734e4043fb37cc6fe0e7f93be67f6511a98c4aa7ea31cc909fb5bf39 - Sigstore transparency entry: 538884278
- Sigstore integration time:
-
Permalink:
withspinal/sp-obs@8047ed5d71cd23d085c7f9a5333e31e14006b06b -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/withspinal
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@8047ed5d71cd23d085c7f9a5333e31e14006b06b -
Trigger Event:
push
-
Statement type: