monocle-apptrace 0.5.0__py3-none-any.whl → 0.5.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of monocle-apptrace might be problematic. Click here for more details.

Files changed (54) hide show
  1. monocle_apptrace/instrumentation/common/__init__.py +7 -5
  2. monocle_apptrace/instrumentation/common/constants.py +95 -12
  3. monocle_apptrace/instrumentation/common/instrumentor.py +1 -6
  4. monocle_apptrace/instrumentation/common/method_wrappers.py +1 -112
  5. monocle_apptrace/instrumentation/common/scope_wrapper.py +126 -0
  6. monocle_apptrace/instrumentation/common/span_handler.py +13 -0
  7. monocle_apptrace/instrumentation/common/utils.py +2 -2
  8. monocle_apptrace/instrumentation/common/wrapper.py +113 -51
  9. monocle_apptrace/instrumentation/metamodel/a2a/entities/inference.py +3 -1
  10. monocle_apptrace/instrumentation/metamodel/adk/_helper.py +24 -0
  11. monocle_apptrace/instrumentation/metamodel/adk/entities/agent.py +62 -1
  12. monocle_apptrace/instrumentation/metamodel/adk/entities/tool.py +3 -1
  13. monocle_apptrace/instrumentation/metamodel/adk/methods.py +9 -2
  14. monocle_apptrace/instrumentation/metamodel/agents/_helper.py +5 -0
  15. monocle_apptrace/instrumentation/metamodel/agents/agents_processor.py +30 -8
  16. monocle_apptrace/instrumentation/metamodel/agents/entities/inference.py +10 -5
  17. monocle_apptrace/instrumentation/metamodel/agents/methods.py +3 -4
  18. monocle_apptrace/instrumentation/metamodel/aiohttp/entities/http.py +2 -1
  19. monocle_apptrace/instrumentation/metamodel/anthropic/_helper.py +3 -3
  20. monocle_apptrace/instrumentation/metamodel/anthropic/entities/inference.py +2 -1
  21. monocle_apptrace/instrumentation/metamodel/azfunc/entities/http.py +2 -1
  22. monocle_apptrace/instrumentation/metamodel/azureaiinference/entities/inference.py +2 -1
  23. monocle_apptrace/instrumentation/metamodel/botocore/entities/inference.py +2 -1
  24. monocle_apptrace/instrumentation/metamodel/fastapi/entities/http.py +2 -1
  25. monocle_apptrace/instrumentation/metamodel/finish_types.py +2 -0
  26. monocle_apptrace/instrumentation/metamodel/flask/entities/http.py +2 -1
  27. monocle_apptrace/instrumentation/metamodel/gemini/entities/inference.py +2 -1
  28. monocle_apptrace/instrumentation/metamodel/gemini/entities/retrieval.py +2 -1
  29. monocle_apptrace/instrumentation/metamodel/haystack/entities/inference.py +2 -1
  30. monocle_apptrace/instrumentation/metamodel/haystack/entities/retrieval.py +2 -1
  31. monocle_apptrace/instrumentation/metamodel/lambdafunc/entities/http.py +2 -1
  32. monocle_apptrace/instrumentation/metamodel/langchain/_helper.py +2 -2
  33. monocle_apptrace/instrumentation/metamodel/langchain/entities/inference.py +2 -1
  34. monocle_apptrace/instrumentation/metamodel/langchain/entities/retrieval.py +2 -1
  35. monocle_apptrace/instrumentation/metamodel/langgraph/_helper.py +6 -0
  36. monocle_apptrace/instrumentation/metamodel/langgraph/entities/inference.py +10 -5
  37. monocle_apptrace/instrumentation/metamodel/langgraph/langgraph_processor.py +8 -4
  38. monocle_apptrace/instrumentation/metamodel/langgraph/methods.py +2 -0
  39. monocle_apptrace/instrumentation/metamodel/litellm/entities/inference.py +2 -1
  40. monocle_apptrace/instrumentation/metamodel/llamaindex/entities/agent.py +9 -4
  41. monocle_apptrace/instrumentation/metamodel/llamaindex/entities/inference.py +2 -1
  42. monocle_apptrace/instrumentation/metamodel/llamaindex/entities/retrieval.py +2 -1
  43. monocle_apptrace/instrumentation/metamodel/mcp/_helper.py +2 -1
  44. monocle_apptrace/instrumentation/metamodel/mcp/entities/inference.py +3 -1
  45. monocle_apptrace/instrumentation/metamodel/mcp/methods.py +1 -1
  46. monocle_apptrace/instrumentation/metamodel/openai/_helper.py +2 -2
  47. monocle_apptrace/instrumentation/metamodel/openai/entities/inference.py +2 -1
  48. monocle_apptrace/instrumentation/metamodel/requests/entities/http.py +2 -1
  49. monocle_apptrace/instrumentation/metamodel/teamsai/entities/inference/teamsai_output_processor.py +2 -1
  50. {monocle_apptrace-0.5.0.dist-info → monocle_apptrace-0.5.1.dist-info}/METADATA +1 -1
  51. {monocle_apptrace-0.5.0.dist-info → monocle_apptrace-0.5.1.dist-info}/RECORD +54 -53
  52. {monocle_apptrace-0.5.0.dist-info → monocle_apptrace-0.5.1.dist-info}/WHEEL +0 -0
  53. {monocle_apptrace-0.5.0.dist-info → monocle_apptrace-0.5.1.dist-info}/licenses/LICENSE +0 -0
  54. {monocle_apptrace-0.5.0.dist-info → monocle_apptrace-0.5.1.dist-info}/licenses/NOTICE +0 -0
@@ -11,6 +11,7 @@ class FinishType(Enum):
11
11
  TRUNCATED = "truncated"
12
12
  CONTENT_FILTER = "content_filter"
13
13
  ERROR = "error"
14
+ TOOL_CALL_ERROR = "tool_call_error"
14
15
  REFUSAL = "refusal"
15
16
  RATE_LIMITED = "rate_limited"
16
17
 
@@ -39,6 +40,7 @@ GEMINI_FINISH_REASON_MAPPING = {
39
40
  "MAX_TOKENS": FinishType.TRUNCATED.value,
40
41
  "SAFETY": FinishType.CONTENT_FILTER.value,
41
42
  "RECITATION": FinishType.CONTENT_FILTER.value,
43
+ "MALFORMED_FUNCTION_CALL": FinishType.TOOL_CALL_ERROR.value,
42
44
  "OTHER": FinishType.ERROR.value,
43
45
  "FINISH_REASON_UNSPECIFIED": None
44
46
  }
@@ -1,6 +1,7 @@
1
+ from monocle_apptrace.instrumentation.common.constants import SPAN_TYPES
1
2
  from monocle_apptrace.instrumentation.metamodel.flask import _helper
2
3
  FLASK_HTTP_PROCESSOR = {
3
- "type": "http.process",
4
+ "type": SPAN_TYPES.HTTP_PROCESS,
4
5
  "attributes": [
5
6
  [
6
7
  {
@@ -1,10 +1,11 @@
1
+ from monocle_apptrace.instrumentation.common.constants import SPAN_TYPES
1
2
  from monocle_apptrace.instrumentation.metamodel.gemini import (
2
3
  _helper,
3
4
  )
4
5
  from monocle_apptrace.instrumentation.common.utils import get_error_message
5
6
 
6
7
  INFERENCE = {
7
- "type": "inference",
8
+ "type": SPAN_TYPES.INFERENCE,
8
9
  "attributes": [
9
10
  [
10
11
  {
@@ -1,9 +1,10 @@
1
+ from monocle_apptrace.instrumentation.common.constants import SPAN_TYPES
1
2
  from monocle_apptrace.instrumentation.metamodel.gemini import (
2
3
  _helper,
3
4
  )
4
5
 
5
6
  RETRIEVAL = {
6
- "type": "retrieval",
7
+ "type": SPAN_TYPES.RETRIEVAL,
7
8
  "attributes": [
8
9
  [
9
10
  {
@@ -1,10 +1,11 @@
1
+ from monocle_apptrace.instrumentation.common.constants import SPAN_TYPES
1
2
  from monocle_apptrace.instrumentation.metamodel.haystack import (
2
3
  _helper,
3
4
  )
4
5
  from monocle_apptrace.instrumentation.common.utils import get_error_message, get_llm_type
5
6
 
6
7
  INFERENCE = {
7
- "type": "inference.framework",
8
+ "type": SPAN_TYPES.INFERENCE_FRAMEWORK,
8
9
  "attributes": [
9
10
  [
10
11
  {
@@ -1,8 +1,9 @@
1
+ from monocle_apptrace.instrumentation.common.constants import SPAN_TYPES
1
2
  from monocle_apptrace.instrumentation.metamodel.haystack import (_helper, )
2
3
  from monocle_apptrace.instrumentation.common.utils import get_attribute
3
4
 
4
5
  RETRIEVAL = {
5
- "type": "retrieval",
6
+ "type": SPAN_TYPES.RETRIEVAL,
6
7
  "attributes": [
7
8
  [
8
9
  {
@@ -1,6 +1,7 @@
1
+ from monocle_apptrace.instrumentation.common.constants import SPAN_TYPES
1
2
  from monocle_apptrace.instrumentation.metamodel.lambdafunc import _helper
2
3
  LAMBDA_HTTP_PROCESSOR = {
3
- "type": "http.process",
4
+ "type": SPAN_TYPES.HTTP_PROCESS,
4
5
  "attributes": [
5
6
  [
6
7
  {
@@ -5,7 +5,7 @@ and assistant messages from various input formats.
5
5
 
6
6
  import logging
7
7
  from opentelemetry.context import get_value
8
- from monocle_apptrace.instrumentation.common.constants import AGENT_PREFIX_KEY, INFERENCE_AGENT_DELEGATION, INFERENCE_COMMUNICATION, INFERENCE_TOOL_CALL
8
+ from monocle_apptrace.instrumentation.common.constants import AGENT_PREFIX_KEY, INFERENCE_AGENT_DELEGATION, INFERENCE_TURN_END, INFERENCE_TOOL_CALL
9
9
  from monocle_apptrace.instrumentation.common.utils import (
10
10
  Option,
11
11
  get_json_dumps,
@@ -57,7 +57,7 @@ def agent_inference_type(arguments):
57
57
  return INFERENCE_AGENT_DELEGATION
58
58
  else:
59
59
  return INFERENCE_TOOL_CALL
60
- return INFERENCE_COMMUNICATION
60
+ return INFERENCE_TURN_END
61
61
 
62
62
  except Exception as e:
63
63
  logger.warning("Warning: Error occurred in agent_inference_type: %s", str(e))
@@ -1,10 +1,11 @@
1
+ from monocle_apptrace.instrumentation.common.constants import SPAN_TYPES
1
2
  from monocle_apptrace.instrumentation.metamodel.langchain import (
2
3
  _helper,
3
4
  )
4
5
  from monocle_apptrace.instrumentation.common.utils import get_error_message, resolve_from_alias, get_llm_type, get_status, get_status_code
5
6
 
6
7
  INFERENCE = {
7
- "type": "inference.framework",
8
+ "type": SPAN_TYPES.INFERENCE_FRAMEWORK,
8
9
  "attributes": [
9
10
  [
10
11
  {
@@ -1,9 +1,10 @@
1
+ from monocle_apptrace.instrumentation.common.constants import SPAN_TYPES
1
2
  from monocle_apptrace.instrumentation.metamodel.langchain import (
2
3
  _helper,
3
4
  )
4
5
 
5
6
  RETRIEVAL = {
6
- "type": "retrieval",
7
+ "type": SPAN_TYPES.RETRIEVAL,
7
8
  "attributes": [
8
9
  [
9
10
  {
@@ -76,6 +76,12 @@ def get_name(instance):
76
76
  def get_agent_name(instance) -> str:
77
77
  return get_name(instance)
78
78
 
79
+ def get_tool_type(span):
80
+ if (span.attributes.get("is_mcp", False)):
81
+ return "tool.mcp"
82
+ else:
83
+ return "tool.langgraph"
84
+
79
85
  def get_tool_name(instance) -> str:
80
86
  return get_name(instance)
81
87
 
@@ -1,9 +1,11 @@
1
+ from monocle_apptrace.instrumentation.common.constants import AGENT_REQUEST_SPAN_NAME, SPAN_SUBTYPES, SPAN_TYPES
1
2
  from monocle_apptrace.instrumentation.metamodel.langgraph import (
2
3
  _helper
3
4
  )
4
5
 
5
6
  AGENT = {
6
- "type": "agentic.invocation",
7
+ "type": SPAN_TYPES.AGENTIC_INVOCATION,
8
+ "subtype": SPAN_SUBTYPES.ROUTING,
7
9
  "attributes": [
8
10
  [
9
11
  {
@@ -48,7 +50,8 @@ AGENT = {
48
50
  }
49
51
 
50
52
  AGENT_REQUEST = {
51
- "type": "agentic.request",
53
+ "type": AGENT_REQUEST_SPAN_NAME,
54
+ "subtype": SPAN_SUBTYPES.PLANNING,
52
55
  "attributes": [
53
56
  [
54
57
  {
@@ -83,13 +86,14 @@ AGENT_REQUEST = {
83
86
  }
84
87
 
85
88
  TOOLS = {
86
- "type": "agentic.tool.invocation",
89
+ "type": SPAN_TYPES.AGENTIC_TOOL_INVOCATION,
90
+ "subtype": SPAN_SUBTYPES.ROUTING,
87
91
  "attributes": [
88
92
  [
89
93
  {
90
94
  "_comment": "tool type",
91
95
  "attribute": "type",
92
- "accessor": lambda arguments:'tool.langgraph'
96
+ "accessor": lambda arguments: _helper.get_tool_type(arguments['span'])
93
97
  },
94
98
  {
95
99
  "_comment": "name of the tool",
@@ -140,7 +144,8 @@ TOOLS = {
140
144
  }
141
145
 
142
146
  AGENT_DELEGATION = {
143
- "type": "agentic.delegation",
147
+ "type": SPAN_TYPES.AGENTIC_DELEGATION,
148
+ "subtype": SPAN_SUBTYPES.ROUTING,
144
149
  "attributes": [
145
150
  [
146
151
  {
@@ -1,19 +1,23 @@
1
- from opentelemetry.context import set_value, attach, detach
2
- from monocle_apptrace.instrumentation.common.constants import AGENT_PREFIX_KEY
1
+ from opentelemetry.context import set_value, attach, detach, get_value
2
+ from monocle_apptrace.instrumentation.common.constants import AGENT_PREFIX_KEY, SCOPE_NAME
3
3
  from monocle_apptrace.instrumentation.common.span_handler import SpanHandler
4
4
  from monocle_apptrace.instrumentation.metamodel.langgraph._helper import (
5
5
  DELEGATION_NAME_PREFIX, get_name, is_root_agent_name, is_delegation_tool, LANGGRAPTH_AGENT_NAME_KEY
6
-
7
6
  )
8
7
  from monocle_apptrace.instrumentation.metamodel.langgraph.entities.inference import (
9
8
  AGENT_DELEGATION, AGENT_REQUEST
10
9
  )
10
+ from monocle_apptrace.instrumentation.common.scope_wrapper import start_scope, stop_scope
11
11
 
12
12
  class LanggraphAgentHandler(SpanHandler):
13
13
  def pre_tracing(self, to_wrap, wrapped, instance, args, kwargs):
14
14
  context = set_value(LANGGRAPTH_AGENT_NAME_KEY, get_name(instance))
15
15
  context = set_value(AGENT_PREFIX_KEY, DELEGATION_NAME_PREFIX, context)
16
- return attach(context)
16
+ scope_name = AGENT_REQUEST.get("type")
17
+ if scope_name is not None and is_root_agent_name(instance) and get_value(scope_name, context) is None:
18
+ return start_scope(scope_name, scope_value=None, context=context)
19
+ else:
20
+ return attach(context)
17
21
 
18
22
  def post_tracing(self, to_wrap, wrapped, instance, args, kwargs, result, token):
19
23
  if token is not None:
@@ -11,6 +11,7 @@ LANGGRAPH_METHODS = [
11
11
  "method": "invoke",
12
12
  "wrapper_method": task_wrapper,
13
13
  "span_handler": "langgraph_agent_handler",
14
+ "scope_name": "agent.invocation",
14
15
  "output_processor": AGENT,
15
16
  },
16
17
  {
@@ -19,6 +20,7 @@ LANGGRAPH_METHODS = [
19
20
  "method": "ainvoke",
20
21
  "wrapper_method": atask_wrapper,
21
22
  "span_handler": "langgraph_agent_handler",
23
+ "scope_name": "agent.invocation",
22
24
  "output_processor": AGENT,
23
25
  },
24
26
  {
@@ -1,3 +1,4 @@
1
+ from monocle_apptrace.instrumentation.common.constants import SPAN_TYPES
1
2
  from monocle_apptrace.instrumentation.metamodel.litellm import (
2
3
  _helper,
3
4
  )
@@ -7,7 +8,7 @@ from monocle_apptrace.instrumentation.common.utils import (
7
8
  get_llm_type,
8
9
  )
9
10
  INFERENCE = {
10
- "type": "inference",
11
+ "type": SPAN_TYPES.INFERENCE,
11
12
  "attributes": [
12
13
  [
13
14
  {
@@ -1,9 +1,11 @@
1
+ from monocle_apptrace.instrumentation.common.constants import AGENT_REQUEST_SPAN_NAME, SPAN_SUBTYPES, SPAN_TYPES
1
2
  from monocle_apptrace.instrumentation.metamodel.llamaindex import (
2
3
  _helper,
3
4
  )
4
5
 
5
6
  AGENT = {
6
- "type": "agentic.invocation",
7
+ "type": SPAN_TYPES.AGENTIC_INVOCATION,
8
+ "subtype": SPAN_SUBTYPES.ROUTING,
7
9
  "attributes": [
8
10
  [
9
11
  {
@@ -49,7 +51,8 @@ AGENT = {
49
51
  }
50
52
 
51
53
  AGENT_REQUEST = {
52
- "type": "agentic.request",
54
+ "type": AGENT_REQUEST_SPAN_NAME,
55
+ "subtype": SPAN_SUBTYPES.PLANNING,
53
56
  "attributes": [
54
57
  [
55
58
  {
@@ -84,7 +87,8 @@ AGENT_REQUEST = {
84
87
  }
85
88
 
86
89
  TOOLS = {
87
- "type": "agentic.tool.invocation",
90
+ "type": SPAN_TYPES.AGENTIC_TOOL_INVOCATION,
91
+ "subtype": SPAN_SUBTYPES.ROUTING,
88
92
  "attributes": [
89
93
  [
90
94
  {
@@ -141,7 +145,8 @@ TOOLS = {
141
145
  }
142
146
 
143
147
  AGENT_DELEGATION = {
144
- "type": "agentic.delegation",
148
+ "type": SPAN_TYPES.AGENTIC_DELEGATION,
149
+ "subtype": SPAN_SUBTYPES.ROUTING,
145
150
  "attributes": [
146
151
  [
147
152
  {
@@ -1,10 +1,11 @@
1
+ from monocle_apptrace.instrumentation.common.constants import SPAN_TYPES
1
2
  from monocle_apptrace.instrumentation.metamodel.llamaindex import (
2
3
  _helper,
3
4
  )
4
5
  from monocle_apptrace.instrumentation.common.utils import get_error_message, resolve_from_alias, get_llm_type, get_status, get_status_code
5
6
 
6
7
  INFERENCE = {
7
- "type": "inference.framework",
8
+ "type": SPAN_TYPES.INFERENCE_FRAMEWORK,
8
9
  "attributes": [
9
10
  [
10
11
  {
@@ -1,9 +1,10 @@
1
+ from monocle_apptrace.instrumentation.common.constants import SPAN_TYPES
1
2
  from monocle_apptrace.instrumentation.metamodel.llamaindex import (
2
3
  _helper,
3
4
  )
4
5
 
5
6
  RETRIEVAL = {
6
- "type": "retrieval",
7
+ "type": SPAN_TYPES.RETRIEVAL,
7
8
  "attributes": [
8
9
  [
9
10
  {
@@ -37,7 +37,8 @@ def get_output_text(arguments):
37
37
 
38
38
  def get_name(arguments):
39
39
  """Get the name of the tool from the instance."""
40
-
40
+ if 'parent_span' in arguments:
41
+ arguments['parent_span'].set_attribute("is_mcp", True)
41
42
  args = arguments["args"]
42
43
  if (
43
44
  args
@@ -1,7 +1,9 @@
1
+ from monocle_apptrace.instrumentation.common.constants import SPAN_SUBTYPES, SPAN_TYPES
1
2
  from monocle_apptrace.instrumentation.metamodel.mcp import _helper
2
3
 
3
4
  TOOLS = {
4
- "type": "agentic.mcp.invocation",
5
+ "type": SPAN_TYPES.AGENTIC_MCP_INVOCATION,
6
+ "subtype": SPAN_SUBTYPES.ROUTING,
5
7
  "attributes": [
6
8
  [
7
9
  {
@@ -17,5 +17,5 @@ MCP_METHODS = [
17
17
  "object": "",
18
18
  "method": "convert_mcp_tool_to_langchain_tool",
19
19
  "wrapper_method": _helper.langchain_mcp_wrapper,
20
- },
20
+ }
21
21
  ]
@@ -19,7 +19,7 @@ from monocle_apptrace.instrumentation.metamodel.finish_types import (
19
19
  map_openai_finish_reason_to_finish_type,
20
20
  OPENAI_FINISH_REASON_MAPPING
21
21
  )
22
- from monocle_apptrace.instrumentation.common.constants import AGENT_PREFIX_KEY, CHILD_ERROR_CODE, INFERENCE_AGENT_DELEGATION, INFERENCE_COMMUNICATION, INFERENCE_TOOL_CALL
22
+ from monocle_apptrace.instrumentation.common.constants import AGENT_PREFIX_KEY, CHILD_ERROR_CODE, INFERENCE_AGENT_DELEGATION, INFERENCE_TURN_END, INFERENCE_TOOL_CALL
23
23
 
24
24
  logger = logging.getLogger(__name__)
25
25
 
@@ -315,4 +315,4 @@ def agent_inference_type(arguments):
315
315
  if tool_name and agent_prefix and tool_name.startswith(agent_prefix):
316
316
  return INFERENCE_AGENT_DELEGATION
317
317
  return INFERENCE_TOOL_CALL
318
- return INFERENCE_COMMUNICATION
318
+ return INFERENCE_TURN_END
@@ -2,6 +2,7 @@ import logging
2
2
  import random
3
3
  import time
4
4
  from types import SimpleNamespace
5
+ from monocle_apptrace.instrumentation.common.constants import SPAN_TYPES
5
6
  from monocle_apptrace.instrumentation.metamodel.openai import (
6
7
  _helper,
7
8
  )
@@ -165,7 +166,7 @@ def process_stream(to_wrap, response, span_processor):
165
166
 
166
167
 
167
168
  INFERENCE = {
168
- "type": "inference",
169
+ "type": SPAN_TYPES.INFERENCE,
169
170
  "is_auto_close": lambda kwargs: kwargs.get("stream", False) is False,
170
171
  "response_processor": process_stream,
171
172
  "attributes": [
@@ -1,6 +1,7 @@
1
+ from monocle_apptrace.instrumentation.common.constants import SPAN_TYPES
1
2
  from monocle_apptrace.instrumentation.metamodel.requests import _helper
2
3
  REQUEST_HTTP_PROCESSOR = {
3
- "type": "http.send",
4
+ "type": SPAN_TYPES.HTTP_SEND,
4
5
  "attributes": [
5
6
  [
6
7
  {
@@ -1,9 +1,10 @@
1
+ from monocle_apptrace.instrumentation.common.constants import SPAN_TYPES
1
2
  from monocle_apptrace.instrumentation.metamodel.teamsai import (
2
3
  _helper,
3
4
  )
4
5
  from monocle_apptrace.instrumentation.common.utils import get_error_message, get_llm_type
5
6
  TEAMAI_OUTPUT_PROCESSOR = {
6
- "type": "inference.framework",
7
+ "type": SPAN_TYPES.INFERENCE_FRAMEWORK,
7
8
  "attributes": [
8
9
  [
9
10
  {
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: monocle_apptrace
3
- Version: 0.5.0
3
+ Version: 0.5.1
4
4
  Summary: package with monocle genAI tracing
5
5
  Project-URL: Homepage, https://github.com/monocle2ai/monocle
6
6
  Project-URL: Issues, https://github.com/monocle2ai/monocle/issues