Skip to content

Commit e7e0633

Browse files
fix: add OCI tracer to init (#498)
* fix: add OCI tracer to init * Update src/openlayer/lib/__init__.py --------- Co-authored-by: Vinícius Mello <[email protected]>
1 parent adb54b8 commit e7e0633

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

src/openlayer/lib/__init__.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"trace_async_openai",
1212
"trace_async",
1313
"trace_bedrock",
14+
"trace_oci",
1415
]
1516

1617
# ---------------------------------- Tracing --------------------------------- #
@@ -95,11 +96,40 @@ def trace_bedrock(client):
9596
try:
9697
import boto3
9798
except ImportError:
98-
raise ImportError("boto3 is required for Bedrock tracing. Install with: pip install boto3")
99+
raise ImportError(
100+
"boto3 is required for Bedrock tracing. Install with: pip install boto3"
101+
)
99102

100103
from .integrations import bedrock_tracer
101104

102105
# Check if it's a boto3 client for bedrock-runtime service
103-
if not hasattr(client, "_service_model") or client._service_model.service_name != "bedrock-runtime":
104-
raise ValueError("Invalid client. Please provide a boto3 bedrock-runtime client.")
106+
if (
107+
not hasattr(client, "_service_model")
108+
or client._service_model.service_name != "bedrock-runtime"
109+
):
110+
raise ValueError(
111+
"Invalid client. Please provide a boto3 bedrock-runtime client."
112+
)
105113
return bedrock_tracer.trace_bedrock(client)
114+
115+
116+
117+
def trace_oci_genai(client, estimate_tokens: bool = True):
118+
"""Trace OCI GenAI chat completions.
119+
120+
Args:
121+
client: OCI GenAI client.
122+
estimate_tokens: Whether to estimate tokens when not available. Defaults to True.
123+
"""
124+
# pylint: disable=import-outside-toplevel
125+
try:
126+
import oci
127+
except ImportError:
128+
raise ImportError("oci is required for OCI GenAI tracing. Install with: pip install oci")
129+
130+
from .integrations import oci_tracer
131+
132+
if not isinstance(client, oci.generative_ai_inference.GenerativeAiInferenceClient):
133+
raise ValueError("Invalid client. Please provide an OCI GenAI client.")
134+
135+
return oci_tracer.trace_oci_genai(client, estimate_tokens=estimate_tokens)

0 commit comments

Comments
 (0)