Skip to main content

Opik observability integration for Bridgic.

Project description

Opik Observability Integration

This package integrates Opik tracing with the Bridgic framework, providing worker granularity tracing implementation.

Installation

# Automatically install the Opik package
pip install bridgic-traces-opik

Prerequisites

Before using OpikTraceCallback, you need to configure Opik. You can choose between two options:

The recommended way to configure the Python SDK is to run the opik configure command. It prompts you to enter your API key and, if applicable, the Opik instance URL so requests are routed and authenticated correctly. All details are saved to a configuration file.

If you are using the Cloud version of the platform, you can configure the SDK by running:

import opik

opik.configure(use_local=False)

You can also configure the SDK by calling configure from the command line:

opik configure

If you are self-hosting the platform, you can configure the SDK by running:

import opik

opik.configure(use_local=True)

or from the command line:

opik configure --use_local

Both variants of configure prompt you for the required information and save it to ~/.opik.config. When using the command-line version, you can pass the -y or --yes flag to automatically approve any confirmation prompts:

opik configure --yes

Once configured, you can start using OpikTraceCallback in your Bridgic applications.

Usage

The OpikTraceCallback can be configured in two ways:

Method 1: Per-Automa Scope with RunningOptions

Apply the callback only to a single automa by configuring it through RunningOptions. In this mode, every worker instantiated by that automa receives its own callback instance, while other automa remain unaffected.

from bridgic.core.automa import GraphAutoma, RunningOptions, worker
from bridgic.core.automa.worker import WorkerCallbackBuilder
from bridgic.traces.opik import OpikTraceCallback
import asyncio

class MyAutoma(GraphAutoma):
    @worker(is_start=True)
    async def step1(self):
        return "hello"
    
    @worker(dependencies=["step1"], is_output=True)
    async def step2(self, step1: str):
        return f"{step1} world"

async def main():
    builder = WorkerCallbackBuilder(
        OpikTraceCallback, 
        init_kwargs={"project_name": "my-project"}
    )
    running_options = RunningOptions(callback_builders=[builder])
    automa = MyAutoma(running_options=running_options)
    result = await automa.arun()
    print(result)

asyncio.run(main())

Method 2: Global Scope with GlobalSetting

Register the callback at the global level through GlobalSetting to make it effective for every automa in the runtime. Each worker, regardless of which automa creates it, is instrumented with the same callback configuration.

from bridgic.core.automa import GraphAutoma, worker
from bridgic.core.automa.worker import WorkerCallbackBuilder
from bridgic.core.config import GlobalSetting
from bridgic.traces.opik import OpikTraceCallback
import asyncio

# Configure global callback
GlobalSetting.set(callback_builders=[WorkerCallbackBuilder(
    OpikTraceCallback, 
    init_kwargs={"project_name": "my-project"}
)])

class MyAutoma(GraphAutoma):
    @worker(is_start=True)
    async def step1(self):
        return "hello"
    
    @worker(dependencies=["step1"], is_output=True)
    async def step2(self, step1: str):
        return f"{step1} world"

async def main():
    automa = MyAutoma()  # Automatically uses global callback
    result = await automa.arun()
    print(result)

asyncio.run(main())

Parameters

  • project_name (Optional[str]): The project name for Opik tracing. If None, uses the default project name configured in Opik.

Features

  • Worker-level tracing: Each worker execution is traced as a separate span
  • Nested automa support: Properly handles nested automa instances with hierarchical tracing
  • Error tracking: Captures and reports errors during worker execution
  • Execution metadata: Tracks execution duration, start/end times, and other metadata
  • Concurrent execution: Supports tracing multiple concurrent automa executions

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

bridgic_traces_opik-0.1.0.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

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

bridgic_traces_opik-0.1.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file bridgic_traces_opik-0.1.0.tar.gz.

File metadata

  • Download URL: bridgic_traces_opik-0.1.0.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.6

File hashes

Hashes for bridgic_traces_opik-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e78e8ffcec0eeac2ec7dc6e25bbbd45893ea237cf038869c93d48317e54cceab
MD5 85a5912bdda3df2a94664805a91af0c5
BLAKE2b-256 74f729f2513833ecca4081941afb27040f31f70087ce79b1887b0a7a7c267edf

See more details on using hashes here.

File details

Details for the file bridgic_traces_opik-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for bridgic_traces_opik-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3114c75caad5e13581f50978e84e588d4cefeca48bf20aeb980ab7ae0842c35f
MD5 e1f99591ba9995c10fb84e616d00c5ca
BLAKE2b-256 d27f3ca39af176a610592e5038792a7f9426d49f5e660acc47334bac1127cd91

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