Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ requires-python = ">=3.9"

[project.optional-dependencies]
dev = [
"openai==1.60.0",
"openai>=1.60.0",
"openai-agents>=0.0.3",
"anthropic",
"chromadb",
"qdrant-client",
Expand Down
2 changes: 2 additions & 0 deletions src/langtrace_python_sdk/instrumentation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from .mistral import MistralInstrumentation
from .ollama import OllamaInstrumentor
from .openai import OpenAIInstrumentation
from .openai_agents import OpenAIAgentsInstrumentation
from .phidata import PhiDataInstrumentation
from .pinecone import PineconeInstrumentation
from .pymongo import PyMongoInstrumentation
Expand Down Expand Up @@ -64,4 +65,5 @@
"PhiDataInstrumentation",
"AgnoInstrumentation",
"CleanLabInstrumentation",
"OpenAIAgentsInstrumentation",
]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Copyright (c) 2024 Scale3 Labs
Copyright (c) 2025 Scale3 Labs

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -14,13 +14,16 @@
limitations under the License.
"""

from typing import Collection

from importlib_metadata import version as v
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.trace import get_tracer
from wrapt import wrap_function_wrapper as _W
from typing import Collection
from importlib_metadata import version as v

from .patch import patch_agent, patch_memory


class AgnoInstrumentation(BaseInstrumentor):
def instrumentation_dependencies(self) -> Collection[str]:
return ["agno >= 1.1.4"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .instrumentation import OpenAIAgentsInstrumentation

__all__ = [
"OpenAIAgentsInstrumentation",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""
Copyright (c) 2025 Scale3 Labs
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

import importlib.metadata
import logging
from typing import Any, Collection, Optional

from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.trace import TracerProvider, get_tracer
from wrapt import wrap_function_wrapper

from langtrace_python_sdk.instrumentation.openai_agents.patch import \
get_new_response

logging.basicConfig(level=logging.FATAL)


class OpenAIAgentsInstrumentation(BaseInstrumentor): # type: ignore

def instrumentation_dependencies(self) -> Collection[str]:
return ["openai-agents >= 0.0.3", "trace-attributes >= 4.0.5"]

def _instrument(self, **kwargs: Any) -> None:
tracer_provider: Optional[TracerProvider] = kwargs.get("tracer_provider")
tracer = get_tracer(__name__, "", tracer_provider)
version: str = importlib.metadata.version("openai")

# TODO(Karthik): This is adding a lot of noise to the trace.
# wrap_function_wrapper(
# "agents.run",
# "Runner._get_handoffs",
# get_handoffs(version, tracer),
# )

wrap_function_wrapper(
"agents.run",
"Runner._get_new_response",
get_new_response(version, tracer),
)

def _uninstrument(self, **kwargs: Any) -> None:
pass
Loading