Skip to content
Closed
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
18 changes: 9 additions & 9 deletions agentops/instrumentation/google_adk/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def _extract_llm_attributes(llm_request_dict: dict, llm_response: Any) -> dict:
attributes[SpanAttributes.LLM_RESPONSE_ID] = response_dict["id"]

except Exception as e:
logger.debug(f"Failed to extract response attributes: {e}")
logger.warning(f"Failed to extract response attributes: {e}")

return attributes

Expand Down Expand Up @@ -647,7 +647,7 @@ def _patch(module_name: str, object_name: str, method_name: str, wrapper_functio
obj = getattr(module, object_name)
wrapt.wrap_function_wrapper(obj, method_name, wrapper_function(agentops_tracer))
_wrapped_methods.append((obj, method_name))
logger.debug(f"Successfully wrapped {module_name}.{object_name}.{method_name}")

except Exception as e:
logger.warning(f"Could not wrap {module_name}.{object_name}.{method_name}: {e}")

Expand All @@ -658,14 +658,14 @@ def _patch_module_function(module_name: str, function_name: str, wrapper_functio
module = __import__(module_name, fromlist=[function_name])
wrapt.wrap_function_wrapper(module, function_name, wrapper_function(agentops_tracer))
_wrapped_methods.append((module, function_name))
logger.debug(f"Successfully wrapped {module_name}.{function_name}")

except Exception as e:
logger.warning(f"Could not wrap {module_name}.{function_name}: {e}")


def patch_adk(agentops_tracer):
"""Apply all patches to Google ADK modules."""
logger.debug("Applying Google ADK patches for AgentOps instrumentation")
logger.info("Applying Google ADK patches for AgentOps instrumentation")

# First, disable ADK's own tracer by replacing it with our NoOpTracer
noop_tracer = NoOpTracer()
Expand All @@ -674,7 +674,7 @@ def patch_adk(agentops_tracer):

# Replace the tracer with our no-op version
adk_telemetry.tracer = noop_tracer
logger.debug("Replaced ADK's tracer with NoOpTracer")

except Exception as e:
logger.warning(f"Failed to replace ADK tracer: {e}")

Expand All @@ -694,7 +694,7 @@ def patch_adk(agentops_tracer):
module = sys.modules[module_name]
if hasattr(module, "tracer"):
module.tracer = noop_tracer
logger.debug(f"Replaced tracer in {module_name}")

except Exception as e:
logger.warning(f"Failed to replace tracer in {module_name}: {e}")

Expand Down Expand Up @@ -739,15 +739,15 @@ def patch_adk(agentops_tracer):

def unpatch_adk():
"""Remove all patches from Google ADK modules."""
logger.debug("Removing Google ADK patches")
logger.info("Removing Google ADK patches")

# Restore ADK's tracer
try:
import google.adk.telemetry as adk_telemetry
from opentelemetry import trace

adk_telemetry.tracer = trace.get_tracer("gcp.vertex.agent")
logger.debug("Restored ADK's built-in tracer")

except Exception as e:
logger.warning(f"Failed to restore ADK tracer: {e}")

Expand All @@ -757,7 +757,7 @@ def unpatch_adk():
if hasattr(getattr(obj, method_name), "__wrapped__"):
original = getattr(obj, method_name).__wrapped__
setattr(obj, method_name, original)
logger.debug(f"Successfully unwrapped {obj}.{method_name}")

except Exception as e:
logger.warning(f"Failed to unwrap {obj}.{method_name}: {e}")

Expand Down