Skip to main content

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

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


Download files

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

Source Distribution

sp_obs-0.5.0.tar.gz (118.4 kB view details)

Uploaded Source

Built Distribution

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

sp_obs-0.5.0-py3-none-any.whl (33.8 kB view details)

Uploaded Python 3

File details

Details for the file sp_obs-0.5.0.tar.gz.

File metadata

  • Download URL: sp_obs-0.5.0.tar.gz
  • Upload date:
  • Size: 118.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sp_obs-0.5.0.tar.gz
Algorithm Hash digest
SHA256 0768ce980e5aecddf66574690f10ab91009b8602cca495992cf9529f9f7694f6
MD5 3677769240cbef99469b6ecb3dc8ec3f
BLAKE2b-256 6d0cc1caef1b8e543c5b653043d4840650e99340690e4bcf89e69fc16272ddef

See more details on using hashes here.

Provenance

The following attestation bundles were made for sp_obs-0.5.0.tar.gz:

Publisher: publish-to-pypi.yml on withspinal/sp-obs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sp_obs-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: sp_obs-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 33.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sp_obs-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 23ab00d9bcfea8d44efc60a746b53dcf739b435e7d8e3d9222b9e7082d742601
MD5 06db5abd335cb1df9066005cab5b51d2
BLAKE2b-256 47266b33d2dc4a36dc39e50e810f8af2bfc2dba42dbe6a8d0981db68289ebd99

See more details on using hashes here.

Provenance

The following attestation bundles were made for sp_obs-0.5.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on withspinal/sp-obs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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