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.
- monocle_apptrace/instrumentation/common/__init__.py +7 -5
- monocle_apptrace/instrumentation/common/constants.py +95 -12
- monocle_apptrace/instrumentation/common/instrumentor.py +1 -6
- monocle_apptrace/instrumentation/common/method_wrappers.py +1 -112
- monocle_apptrace/instrumentation/common/scope_wrapper.py +126 -0
- monocle_apptrace/instrumentation/common/span_handler.py +13 -0
- monocle_apptrace/instrumentation/common/utils.py +2 -2
- monocle_apptrace/instrumentation/common/wrapper.py +113 -51
- monocle_apptrace/instrumentation/metamodel/a2a/entities/inference.py +3 -1
- monocle_apptrace/instrumentation/metamodel/adk/_helper.py +24 -0
- monocle_apptrace/instrumentation/metamodel/adk/entities/agent.py +62 -1
- monocle_apptrace/instrumentation/metamodel/adk/entities/tool.py +3 -1
- monocle_apptrace/instrumentation/metamodel/adk/methods.py +9 -2
- monocle_apptrace/instrumentation/metamodel/agents/_helper.py +5 -0
- monocle_apptrace/instrumentation/metamodel/agents/agents_processor.py +30 -8
- monocle_apptrace/instrumentation/metamodel/agents/entities/inference.py +10 -5
- monocle_apptrace/instrumentation/metamodel/agents/methods.py +3 -4
- monocle_apptrace/instrumentation/metamodel/aiohttp/entities/http.py +2 -1
- monocle_apptrace/instrumentation/metamodel/anthropic/_helper.py +3 -3
- monocle_apptrace/instrumentation/metamodel/anthropic/entities/inference.py +2 -1
- monocle_apptrace/instrumentation/metamodel/azfunc/entities/http.py +2 -1
- monocle_apptrace/instrumentation/metamodel/azureaiinference/entities/inference.py +2 -1
- monocle_apptrace/instrumentation/metamodel/botocore/entities/inference.py +2 -1
- monocle_apptrace/instrumentation/metamodel/fastapi/entities/http.py +2 -1
- monocle_apptrace/instrumentation/metamodel/finish_types.py +2 -0
- monocle_apptrace/instrumentation/metamodel/flask/entities/http.py +2 -1
- monocle_apptrace/instrumentation/metamodel/gemini/entities/inference.py +2 -1
- monocle_apptrace/instrumentation/metamodel/gemini/entities/retrieval.py +2 -1
- monocle_apptrace/instrumentation/metamodel/haystack/entities/inference.py +2 -1
- monocle_apptrace/instrumentation/metamodel/haystack/entities/retrieval.py +2 -1
- monocle_apptrace/instrumentation/metamodel/lambdafunc/entities/http.py +2 -1
- monocle_apptrace/instrumentation/metamodel/langchain/_helper.py +2 -2
- monocle_apptrace/instrumentation/metamodel/langchain/entities/inference.py +2 -1
- monocle_apptrace/instrumentation/metamodel/langchain/entities/retrieval.py +2 -1
- monocle_apptrace/instrumentation/metamodel/langgraph/_helper.py +6 -0
- monocle_apptrace/instrumentation/metamodel/langgraph/entities/inference.py +10 -5
- monocle_apptrace/instrumentation/metamodel/langgraph/langgraph_processor.py +8 -4
- monocle_apptrace/instrumentation/metamodel/langgraph/methods.py +2 -0
- monocle_apptrace/instrumentation/metamodel/litellm/entities/inference.py +2 -1
- monocle_apptrace/instrumentation/metamodel/llamaindex/entities/agent.py +9 -4
- monocle_apptrace/instrumentation/metamodel/llamaindex/entities/inference.py +2 -1
- monocle_apptrace/instrumentation/metamodel/llamaindex/entities/retrieval.py +2 -1
- monocle_apptrace/instrumentation/metamodel/mcp/_helper.py +2 -1
- monocle_apptrace/instrumentation/metamodel/mcp/entities/inference.py +3 -1
- monocle_apptrace/instrumentation/metamodel/mcp/methods.py +1 -1
- monocle_apptrace/instrumentation/metamodel/openai/_helper.py +2 -2
- monocle_apptrace/instrumentation/metamodel/openai/entities/inference.py +2 -1
- monocle_apptrace/instrumentation/metamodel/requests/entities/http.py +2 -1
- monocle_apptrace/instrumentation/metamodel/teamsai/entities/inference/teamsai_output_processor.py +2 -1
- {monocle_apptrace-0.5.0.dist-info → monocle_apptrace-0.5.1.dist-info}/METADATA +1 -1
- {monocle_apptrace-0.5.0.dist-info → monocle_apptrace-0.5.1.dist-info}/RECORD +54 -53
- {monocle_apptrace-0.5.0.dist-info → monocle_apptrace-0.5.1.dist-info}/WHEEL +0 -0
- {monocle_apptrace-0.5.0.dist-info → monocle_apptrace-0.5.1.dist-info}/licenses/LICENSE +0 -0
- {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,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":
|
|
8
|
+
"type": SPAN_TYPES.INFERENCE,
|
|
8
9
|
"attributes": [
|
|
9
10
|
[
|
|
10
11
|
{
|
|
@@ -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":
|
|
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":
|
|
6
|
+
"type": SPAN_TYPES.RETRIEVAL,
|
|
6
7
|
"attributes": [
|
|
7
8
|
[
|
|
8
9
|
{
|
|
@@ -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,
|
|
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
|
|
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":
|
|
8
|
+
"type": SPAN_TYPES.INFERENCE_FRAMEWORK,
|
|
8
9
|
"attributes": [
|
|
9
10
|
[
|
|
10
11
|
{
|
|
@@ -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":
|
|
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":
|
|
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":
|
|
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:
|
|
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":
|
|
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
|
-
|
|
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":
|
|
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":
|
|
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":
|
|
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":
|
|
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":
|
|
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":
|
|
8
|
+
"type": SPAN_TYPES.INFERENCE_FRAMEWORK,
|
|
8
9
|
"attributes": [
|
|
9
10
|
[
|
|
10
11
|
{
|
|
@@ -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":
|
|
5
|
+
"type": SPAN_TYPES.AGENTIC_MCP_INVOCATION,
|
|
6
|
+
"subtype": SPAN_SUBTYPES.ROUTING,
|
|
5
7
|
"attributes": [
|
|
6
8
|
[
|
|
7
9
|
{
|
|
@@ -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,
|
|
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
|
|
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":
|
|
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": [
|
monocle_apptrace/instrumentation/metamodel/teamsai/entities/inference/teamsai_output_processor.py
CHANGED
|
@@ -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":
|
|
7
|
+
"type": SPAN_TYPES.INFERENCE_FRAMEWORK,
|
|
7
8
|
"attributes": [
|
|
8
9
|
[
|
|
9
10
|
{
|