The SGP Tracing SDK provides a convenient way to instrument your Python applications with tracing capabilities, allowing you to generate, manage, and send spans to the Scale GP platform. This enables detailed monitoring and debugging of your workflows.

Python SDK tracing is currently only available in the Beta SDK.

Installation

First, install the scale-gp-beta package using pip:

pip install --pre scale-gp-beta

Initialisation

Before you can create any traces or spans, you must initialize the tracing SDK. It’s best practice to do this once at your application’s entry point.

You have two primary options for initialization:

Initialize with an SGPClient

This method gives you full control over the SGPClient’s configuration (e.g., base_url, timeout).

import scale_gp_beta.lib.tracing as tracing
from scale_gp_beta import SGPClient

# Replace with your actual API Key and Account ID
client = SGPClient(api_key="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID")
tracing.init(client=client)

Initialize using Environment Variables

If you have set the SGP_API_KEY and SGP_ACCOUNT_ID environment variables, you can omit passing a client. The SDK will automatically attempt to create a default SGPClient for you.

export SGP_API_KEY="sk-your-api-key"
export SGP_ACCOUNT_ID="your-account-id"

Then, in your Python code:

import scale_gp_beta.lib.tracing as tracing

# The SDK will automatically find SGP_API_KEY and SGP_ACCOUNT_ID
# from your environment variables.
tracing.init()

Disabling Tracing

You can control whether tracing data is collected and exported. This is useful for development, testing, or specific environments where tracing is not desired.

Environment Variable

export DISABLE_SCALE_TRACING=true

Programmatically

Pass the disabled=True parameter directly to the init() function. This will override the environment variable setting.

import scale_gp_beta.lib.tracing as tracing
from scale_gp_beta import SGPClient

# Tracing will be disabled, regardless of environment variables
tracing.init(client=SGPClient(api_key="...", account_id="..."), disabled=True)