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

You can 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())

From the perspective of tracking worker execution, the following approach is equivalent to the above one:

from bridgic.traces.opik import start_opik_trace

start_opik_trace(project_name="my-project")

However, start_opik_trace is a higher-level function that encapsulates the functionality of the first approach. As the framework may add tracking for more important phases in the future, start_opik_trace will provide a unified interface for all tracking capabilities, making it the recommended approach for most use cases.

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.1.tar.gz (7.5 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.1-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for bridgic_traces_opik-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e2efd9ca64399f8820acb3d5931313e0be96c9fc4549a9a3a2e6b94ea5d5333a
MD5 2b7a9eacdbc266e7809c2ea260d067f1
BLAKE2b-256 bc894d8d65b4b4143b1ca3b1ac83d4edb4ff3e5c795f87889e0f8a7054d6517b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bridgic_traces_opik-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2e653a5b7f337f8a07c547939c6474d4df298df1985b141c8178ce859c802287
MD5 d050a900150e809035d1132cdefbe950
BLAKE2b-256 d19a1b328c1da2b13b7d0e458b6e95dfc59c9abf3ab3908d7e6cff2b484fa8a5

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