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:
- To use the hosted version, you need to create a Comet account and grab your API Key.
- To run the Opik platform locally, see the installation guide for more information.
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):
await asyncio.sleep(1)
return "hello"
@worker(dependencies=["step1"], is_output=True)
async def step2(self, step1: str):
await asyncio.sleep(1)
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)
if __name__ == "__main__":
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):
await asyncio.sleep(1)
return "hello"
@worker(dependencies=["step1"], is_output=True)
async def step2(self, step1: str):
await asyncio.sleep(1)
return f"{step1} world"
async def main():
automa = MyAutoma() # Automatically uses global callback
result = await automa.arun()
print(result)
if __name__ == "__main__":
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.
Release files for bridgic-traces-opik 0.1.2.post1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| bridgic_traces_opik-0.1.2.post1.tar.gz | 7.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bridgic_traces_opik-0.1.2.post1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.3 kB
Release files / bridgic_traces_opik-0.1.2.post1.tar.gz
| Download URL | bridgic_traces_opik-0.1.2.post1.tar.gz |
|---|---|
| Size | 7.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
46af860c0a3189792299004a87782c122e86c5385a595b8a667132908dfe8205
|
|
BLAKE2b-256 checksum How to use checksums |
3f0a2a6adb8da98d0e42f8acbbaa311036800fa8f0feb4122e6851607cbf773e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.6
|
Release files / bridgic_traces_opik-0.1.2.post1-py3-none-any.whl
| Download URL | bridgic_traces_opik-0.1.2.post1-py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ccaf669e23a72f204c5e8a22cc98a76669ba09a2cbad1f2b6f4e925cb22f2cdd
|
|
BLAKE2b-256 checksum How to use checksums |
564aa90f71d9a815150c999ea4ff71d9ab43147af213caeabc1f966ab7e1d2f3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.6
|