Skip to main content
GitHub

Configuration

Configure the Risicare SDK for your application.

Configure the Risicare SDK to connect to your project and customize tracing behavior.

JavaScript SDK?

For JavaScript/TypeScript configuration, see the JS Configuration guide.

Basic Setup

import risicare
 
risicare.init(
    api_key="rsk-...",              # Or use RISICARE_API_KEY env var
    service_name="my-agent",        # Identify your service
    environment="production",       # Environment name
)

API Key = Project

Your API key is scoped to the project it was created under (visible in Settings → General). No separate project_id is needed — the gateway resolves it from your key.

project_id is deprecated

Passing project_id to init() emits a DeprecationWarning in Python (or console.warn in JavaScript). The parameter is ignored by the gateway and will be removed in v1.0. Use service_name and environment for within-project organization instead.

Configuration Options

Required

OptionTypeDescription
api_keystrYour Risicare API key. Starts with rsk-. Each key is scoped to one project.

Optional

OptionTypeDefaultDescription
endpointstr"https://app.risicare.ai"Gateway endpoint URL
environmentstr"development"Environment name (development, staging, production)
service_namestrNoneService name for within-project organization
service_versionstrNoneService version for traces
enabledboolTrueEnable/disable tracing globally
trace_contentboolTrueCapture prompt/completion content
sample_ratefloat1.0Sampling rate (0.0-1.0, clamped)
batch_sizeint100Spans per batch export (clamped to 1–10,000)
batch_timeout_msint1000Milliseconds between batch exports
auto_patchboolTruePatch ThreadPoolExecutor, ProcessPoolExecutor, and asyncio.create_task for automatic context propagation
debugboolFalseEnable debug logging (see detail below)
exporterslist[SpanExporter]NoneCustom span exporters (default: HTTP exporter when api_key is provided)
metadatadict{}Global metadata attached to all spans
otlp_endpointstrNoneOTLP/HTTP export endpoint
otlp_headersdictNoneOTLP export headers
otel_bridgeboolFalseEnable OpenTelemetry bridge

Content truncation

When trace_content=True, captured prompt and completion text is truncated to 10,000 characters per field. Content exceeding this limit is cut with a "... [truncated]" marker. This limit is not configurable — it's a hardcoded safety bound to prevent oversized spans.

auto_patch monkey-patches at import time

When auto_patch=True (default), init() monkey-patches all detected LLM provider libraries (OpenAI, Anthropic, etc.) via import hooks. For precise control over which providers are instrumented, set auto_patch=False and call instrument_already_imported() or install_import_hooks() selectively.

What debug=True enables

  • Console exporter: Adds a ConsoleExporter that prints every span to stderr as it's exported
  • Orphan trace warnings: Logs a warning when an LLM call has no parent span (each call becomes its own trace — a common Tier 1 mistake)
  • Initialization logging: Reports patching status (ThreadPoolExecutor, asyncio.create_task), endpoint, and service name on startup
  • HTTP export errors: Logs failed export requests, timeouts, and non-2xx responses (normally silent)

Environment Variables

All configuration can be set via environment variables:

export RISICARE_API_KEY="rsk-..."
export RISICARE_ENDPOINT="https://app.risicare.ai"
export RISICARE_ENVIRONMENT="production"
export RISICARE_SERVICE_NAME="my-agent"
export RISICARE_TRACING="true"
export RISICARE_TRACE_CONTENT="true"
export RISICARE_SAMPLE_RATE="1.0"
export RISICARE_SERVICE_NAME="my-service"
export RISICARE_SERVICE_VERSION="1.0.0"
export RISICARE_DEBUG="false"
export RISICARE_OTLP_ENDPOINT="https://otel-collector:4318"
export RISICARE_OTLP_HEADERS="key1=value1,key2=value2"
export RISICARE_OTEL_BRIDGE="false"
VariableMaps To
RISICARE_API_KEYapi_key
RISICARE_ENDPOINTendpoint
RISICARE_ENVIRONMENTenvironment
RISICARE_SERVICE_NAMEservice_name
RISICARE_SERVICE_VERSIONservice_version
RISICARE_TRACINGenabled
RISICARE_TRACE_CONTENTtrace_content
RISICARE_SAMPLE_RATEsample_rate
RISICARE_DEBUGdebug
RISICARE_OTLP_ENDPOINTotlp_endpoint
RISICARE_OTLP_HEADERSotlp_headers
RISICARE_OTEL_BRIDGEotel_bridge

Zero-Code Instrumentation

Set RISICARE_TRACING=true to enable auto-instrumentation without any code changes.

Advanced Configuration

Custom Endpoint

For self-hosted deployments:

risicare.init(
    api_key="rsk-...",
    endpoint="https://your-risicare-instance.com",
)

Sampling

Control trace sampling rate:

risicare.init(
    api_key="rsk-...",
    sample_rate=0.1,  # Sample 10% of traces
)

Programmatic Control

Check Status

if risicare.is_enabled():
    print("Tracing is active")

Flush Pending Spans

# Force export all pending spans
client = risicare.get_client()
client.flush()

Shutdown

# Graceful shutdown - flushes and closes connections
risicare.shutdown(timeout_ms=5000)  # default: 5000ms

shutdown() waits up to timeout_ms for the batch processor thread to drain, then performs a final flush and closes HTTP connections. An atexit handler calls shutdown() automatically on normal exit — explicit calls are only needed when you want to flush mid-process (e.g., serverless functions, before a long non-tracing phase).

Shutdown may block on network issues

If the exporter is mid-request when shutdown() runs, the thread join blocks for up to timeout_ms. In latency-sensitive paths, reduce the timeout: risicare.shutdown(timeout_ms=1000).

Auto-Instrumentation Management

Control which libraries are automatically instrumented:

from risicare import (
    install_import_hooks,
    remove_import_hooks,
    instrument_already_imported,
    is_instrumented,
    get_instrumented_modules,
    get_supported_modules,
)
 
# See which libraries can be auto-instrumented
get_supported_modules()
# {'openai', 'anthropic', 'cohere', 'google.generativeai', 'mistralai', ...}
 
# Check what's currently instrumented
get_instrumented_modules()
# {'openai', 'anthropic'}
 
# Check a specific library
is_instrumented("openai")  # True
 
# Instrument libraries that were imported before risicare.init()
count = instrument_already_imported()
# Returns number of newly instrumented modules
 
# Remove all import hooks (stops future auto-instrumentation)
remove_import_hooks()
 
# Re-install import hooks
install_import_hooks()

Configuration Precedence

Configuration is resolved in this order (highest to lowest priority):

  1. Explicit init() parameters
  2. Environment variables
  3. Default values

Next Steps