monocle-apptrace 0.4.0b3__py3-none-any.whl → 0.4.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 (35) hide show
  1. monocle_apptrace/instrumentation/__init__.py +2 -1
  2. monocle_apptrace/instrumentation/common/constants.py +3 -0
  3. monocle_apptrace/instrumentation/common/instrumentor.py +1 -1
  4. monocle_apptrace/instrumentation/common/span_handler.py +1 -1
  5. monocle_apptrace/instrumentation/common/utils.py +20 -2
  6. monocle_apptrace/instrumentation/common/wrapper_method.py +5 -1
  7. monocle_apptrace/instrumentation/metamodel/anthropic/_helper.py +29 -4
  8. monocle_apptrace/instrumentation/metamodel/anthropic/entities/inference.py +12 -2
  9. monocle_apptrace/instrumentation/metamodel/azfunc/_helper.py +78 -0
  10. monocle_apptrace/instrumentation/metamodel/azfunc/entities/http.py +51 -0
  11. monocle_apptrace/instrumentation/metamodel/azfunc/methods.py +23 -0
  12. monocle_apptrace/instrumentation/metamodel/azfunc/wrapper.py +23 -0
  13. monocle_apptrace/instrumentation/metamodel/azureaiinference/__init__.py +1 -0
  14. monocle_apptrace/instrumentation/metamodel/azureaiinference/_helper.py +216 -0
  15. monocle_apptrace/instrumentation/metamodel/azureaiinference/entities/inference.py +208 -0
  16. monocle_apptrace/instrumentation/metamodel/azureaiinference/methods.py +23 -0
  17. monocle_apptrace/instrumentation/metamodel/botocore/_helper.py +42 -17
  18. monocle_apptrace/instrumentation/metamodel/botocore/entities/inference.py +11 -3
  19. monocle_apptrace/instrumentation/metamodel/haystack/_helper.py +20 -12
  20. monocle_apptrace/instrumentation/metamodel/haystack/entities/inference.py +10 -2
  21. monocle_apptrace/instrumentation/metamodel/langchain/_helper.py +19 -13
  22. monocle_apptrace/instrumentation/metamodel/langchain/entities/inference.py +10 -2
  23. monocle_apptrace/instrumentation/metamodel/llamaindex/_helper.py +21 -13
  24. monocle_apptrace/instrumentation/metamodel/llamaindex/entities/inference.py +10 -2
  25. monocle_apptrace/instrumentation/metamodel/openai/_helper.py +17 -9
  26. monocle_apptrace/instrumentation/metamodel/openai/entities/inference.py +3 -2
  27. monocle_apptrace/instrumentation/metamodel/teamsai/_helper.py +50 -4
  28. monocle_apptrace/instrumentation/metamodel/teamsai/entities/inference/actionplanner_output_processor.py +32 -12
  29. monocle_apptrace/instrumentation/metamodel/teamsai/methods.py +30 -17
  30. monocle_apptrace/instrumentation/metamodel/teamsai/sample.json +448 -0
  31. {monocle_apptrace-0.4.0b3.dist-info → monocle_apptrace-0.4.1.dist-info}/METADATA +1 -1
  32. {monocle_apptrace-0.4.0b3.dist-info → monocle_apptrace-0.4.1.dist-info}/RECORD +35 -26
  33. {monocle_apptrace-0.4.0b3.dist-info → monocle_apptrace-0.4.1.dist-info}/WHEEL +0 -0
  34. {monocle_apptrace-0.4.0b3.dist-info → monocle_apptrace-0.4.1.dist-info}/licenses/LICENSE +0 -0
  35. {monocle_apptrace-0.4.0b3.dist-info → monocle_apptrace-0.4.1.dist-info}/licenses/NOTICE +0 -0
@@ -1,3 +1,4 @@
1
+ import logging
1
2
  from monocle_apptrace.instrumentation.common.utils import MonocleSpanException
2
3
  from monocle_apptrace.instrumentation.common.utils import (
3
4
  Option,
@@ -7,6 +8,9 @@ from monocle_apptrace.instrumentation.common.utils import (
7
8
  get_exception_message,
8
9
  get_exception_status_code
9
10
  )
11
+
12
+ logger = logging.getLogger(__name__)
13
+
10
14
  def capture_input(arguments):
11
15
  """
12
16
  Captures the input from Teams AI state.
@@ -18,6 +22,7 @@ def capture_input(arguments):
18
22
  try:
19
23
  # Get the memory object from kwargs
20
24
  kwargs = arguments.get("kwargs", {})
25
+ messages = []
21
26
 
22
27
  # If memory exists, try to get the input from temp
23
28
  if "memory" in kwargs:
@@ -29,14 +34,20 @@ def capture_input(arguments):
29
34
  if temp and hasattr(temp, "get"):
30
35
  input_value = temp.get("input")
31
36
  if input_value:
32
- return str(input_value)
33
-
37
+ messages.append({'user': str(input_value)})
38
+ system_prompt = ""
39
+ try:
40
+ system_prompt = kwargs.get("template").prompt.sections[0].sections[0].template
41
+ messages.append({'system': system_prompt})
42
+ except Exception as e:
43
+ print(f"Debug - Error accessing system prompt: {str(e)}")
44
+
34
45
  # Try alternative path through context if memory path fails
35
46
  context = kwargs.get("context")
36
47
  if hasattr(context, "activity") and hasattr(context.activity, "text"):
37
- return str(context.activity.text)
48
+ messages.append({'user': str(context.activity.text)})
38
49
 
39
- return "No input found in memory or context"
50
+ return [str(message) for message in messages]
40
51
  except Exception as e:
41
52
  print(f"Debug - Arguments structure: {str(arguments)}")
42
53
  print(f"Debug - kwargs: {str(kwargs)}")
@@ -59,6 +70,41 @@ def capture_prompt_info(arguments):
59
70
  except Exception as e:
60
71
  return f"Error capturing prompt: {str(e)}"
61
72
 
73
+ def capture_prompt_template_info(arguments):
74
+ """Captures prompt information from ActionPlanner state"""
75
+ try:
76
+ kwargs = arguments.get("kwargs", {})
77
+ prompt = kwargs.get("prompt")
78
+
79
+ if hasattr(prompt,"prompt") and prompt.prompt is not None:
80
+ if "_text" in prompt.prompt.__dict__:
81
+ prompt_template = prompt.prompt.__dict__.get("_text", None)
82
+ return prompt_template
83
+ elif "_sections" in prompt.prompt.__dict__ and prompt.prompt._sections is not None:
84
+ sections = prompt.prompt._sections[0].__dict__.get("_sections", None)
85
+ if sections is not None and "_template" in sections[0].__dict__:
86
+ return sections[0].__dict__.get("_template", None)
87
+
88
+
89
+ return "No prompt information found"
90
+ except Exception as e:
91
+ return f"Error capturing prompt: {str(e)}"
92
+
93
+ def status_check(arguments):
94
+ if hasattr(arguments["result"], "error") and arguments["result"].error is not None:
95
+ error_msg:str = arguments["result"].error
96
+ error_code:str = arguments["result"].status if hasattr(arguments["result"], "status") else "unknown"
97
+ raise MonocleSpanException(f"Error: {error_code} - {error_msg}")
98
+
99
+ def get_prompt_template(arguments):
100
+ pass
101
+ return {
102
+ "prompt_template_name": capture_prompt_info(arguments),
103
+ "prompt_template": capture_prompt_template_info(arguments),
104
+ "prompt_template_description": get_nested_value(arguments.get("kwargs", {}), ["prompt", "config", "description"]),
105
+ "prompt_template_type": get_nested_value(arguments.get("kwargs", {}), ["prompt", "config", "type"])
106
+ }
107
+
62
108
  def get_status_code(arguments):
63
109
  if arguments["exception"] is not None:
64
110
  return get_exception_status_code(arguments)
@@ -28,22 +28,42 @@ ACTIONPLANNER_OUTPUT_PROCESSOR = {
28
28
  {
29
29
  "attribute": "tokenizer",
30
30
  "accessor": lambda arguments: arguments["instance"]._options.tokenizer.__class__.__name__ if hasattr(arguments["instance"], "_options") else "GPTTokenizer"
31
- },
32
- {
33
- "attribute": "prompt_name",
34
- "accessor": _helper.capture_prompt_info
35
- },
36
- {
37
- "attribute": "validator",
38
- "accessor": lambda arguments: arguments["kwargs"].get("validator").__class__.__name__ if arguments.get("kwargs", {}).get("validator") else "DefaultResponseValidator"
39
- },
40
- {
41
- "attribute": "memory_type",
42
- "accessor": lambda arguments: arguments["kwargs"].get("memory").__class__.__name__ if arguments.get("kwargs", {}).get("memory") else "unknown"
43
31
  }
44
32
  ]
45
33
  ],
46
34
  "events": [
35
+ {
36
+ "name": "data.input",
37
+ "_comment": "input configuration to ActionPlanner",
38
+ "attributes": [
39
+ {
40
+ "_comment": "execution metadata",
41
+ "accessor": lambda arguments: _helper.get_prompt_template(arguments)
42
+ },
43
+ {
44
+ "attribute": "validator",
45
+ "accessor": lambda arguments: arguments["kwargs"].get("validator").__class__.__name__ if arguments.get("kwargs", {}).get("validator") else "DefaultResponseValidator"
46
+ },
47
+ {
48
+ "attribute": "memory_type",
49
+ "accessor": lambda arguments: arguments["kwargs"].get("memory").__class__.__name__ if arguments.get("kwargs", {}).get("memory") else "unknown"
50
+ }
51
+ ]
52
+ },
53
+ {
54
+ "name": "data.output",
55
+ "_comment": "output from ActionPlanner",
56
+ "attributes": [
57
+ {
58
+ "attribute": "status",
59
+ "accessor": lambda arguments: _helper.status_check(arguments)
60
+ },
61
+ {
62
+ "attribute": "response",
63
+ "accessor": lambda arguments: arguments["result"].message.content if hasattr(arguments["result"], "message") else str(arguments["result"])
64
+ }
65
+ ]
66
+ },
47
67
  {
48
68
  "name": "metadata",
49
69
  "attributes": [
@@ -9,31 +9,44 @@ from monocle_apptrace.instrumentation.metamodel.teamsai.entities.inference.teams
9
9
  )
10
10
  from monocle_apptrace.instrumentation.metamodel.teamsai.entities.inference.actionplanner_output_processor import (
11
11
  ACTIONPLANNER_OUTPUT_PROCESSOR,
12
- )
13
-
14
-
12
+ )
15
13
  def get_id(args, kwargs):
16
14
  """
17
15
  Extracts the ID from the context.
18
16
  """
19
17
  scopes: dict[str, dict[str:str]] = {}
20
18
  context = kwargs.get("context")
21
- if context and context.activity and context.activity.conversation.id:
22
- conversation_id = context.activity.conversation.id or ""
23
- user_aad_object_id = context.activity.from_property.aad_object_id or ""
24
- user_teams_id = context.activity.from_property.id or ""
19
+ if context and context.activity and context.activity.channel_id:
25
20
  channel_id = context.activity.channel_id or ""
26
- recipient_id = context.activity.recipient.id or ""
27
- recipient_aad_object_id = context.activity.recipient.aad_object_id or ""
28
- scopes[f"teams.conversation.conversation.id"] = conversation_id
29
- scopes[f"teams.user.from_property.aad_object_id"] = user_aad_object_id
30
- scopes[f"teams.user.from_property.id"] = user_teams_id
31
21
  scopes[f"teams.channel.channel_id"] = channel_id
32
- scopes[f"teams.channel.recipient.id"] = recipient_id
33
- scopes[f"teams.channel.recipient.aad_object_id"] = recipient_aad_object_id
22
+ if channel_id == "msteams":
23
+ scopes[f"msteams.activity.type"] = context.activity.type or ""
34
24
 
35
- return scopes
25
+ if hasattr(context.activity,"conversation"):
26
+ scopes[f"msteams.conversation.id"] = context.activity.conversation.id or ""
27
+ scopes[f"msteams.conversation.type"] = context.activity.conversation.conversation_type or ""
28
+ scopes[f"msteams.conversation.name"] = context.activity.conversation.name or ""
36
29
 
30
+ if hasattr(context.activity,"from_property"):
31
+ scopes[f"msteams.user.from_property.id"] = context.activity.from_property.id or ""
32
+ scopes[f"msteams.user.from_property.name"] = context.activity.from_property.name or ""
33
+ scopes[f"msteams.user.from_property.role"] = context.activity.from_property.role or ""
34
+
35
+ if hasattr(context.activity,"recipient"):
36
+ scopes[f"msteams.recipient.id"] = context.activity.recipient.id or ""
37
+
38
+ if hasattr(context.activity,"channel_data"):
39
+ if "tenant" in context.activity.channel_data:
40
+ scopes[f"msteams.channel_data.tenant.id"] = context.activity.channel_data['tenant']['id'] or ""
41
+ if "team" in context.activity.channel_data:
42
+ scopes[f"msteams.channel_data.team.id"] = context.activity.channel_data['team']['id'] or ""
43
+ if "name" in context.activity.channel_data['team']:
44
+ scopes[f"msteams.channel_data.team.name"] = context.activity.channel_data['team']['name'] or ""
45
+ if "channel" in context.activity.channel_data:
46
+ scopes[f"msteams.channel_data.channel.id"] = context.activity.channel_data['channel']['id'] or ""
47
+ if "name" in context.activity.channel_data['channel']:
48
+ scopes[f"msteams.channel_data.channel.name"] = context.activity.channel_data['channel']['name'] or ""
49
+ return scopes
37
50
 
38
51
  TEAMAI_METHODS = [
39
52
  {
@@ -55,6 +68,6 @@ TEAMAI_METHODS = [
55
68
  "object": "ActionPlanner",
56
69
  "method": "complete_prompt",
57
70
  "scope_values": get_id,
58
- "wrapper_method": ascopes_wrapper,
59
- },
71
+ "wrapper_method": ascopes_wrapper,
72
+ }
60
73
  ]