monocle-apptrace 0.3.0b5__tar.gz → 0.3.0b6__tar.gz
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-0.3.0b5 → monocle_apptrace-0.3.0b6}/CHANGELOG.md +1 -1
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/PKG-INFO +1 -1
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/pyproject.toml +1 -1
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/exporters/azure/blob_exporter.py +7 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/exporters/okahu/okahu_exporter.py +1 -1
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/common/constants.py +17 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/common/instrumentor.py +54 -45
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/common/span_handler.py +81 -37
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/common/utils.py +55 -6
- monocle_apptrace-0.3.0b6/src/monocle_apptrace/instrumentation/common/wrapper.py +90 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/common/wrapper_method.py +8 -4
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/haystack/entities/inference.py +1 -1
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/haystack/methods.py +2 -1
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/langchain/entities/inference.py +3 -2
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/langchain/methods.py +12 -6
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/llamaindex/entities/inference.py +5 -3
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/llamaindex/methods.py +6 -3
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/openai/_helper.py +31 -7
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/openai/entities/inference.py +1 -1
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/openai/entities/retrieval.py +20 -1
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/openai/methods.py +21 -1
- monocle_apptrace-0.3.0b6/src/monocle_apptrace/instrumentation/metamodel/requests/__init__.py +4 -0
- monocle_apptrace-0.3.0b5/src/monocle_apptrace/instrumentation/common/wrapper.py +0 -94
- monocle_apptrace-0.3.0b5/src/monocle_apptrace/instrumentation/metamodel/requests/__init__.py +0 -2
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/.gitignore +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/CODEOWNERS.md +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/CODE_OF_CONDUCT.md +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/CONTRIBUTING.md +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/COPYRIGHT.template +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/LICENSE +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/MAINTAINER.md +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/Monocle_User_Guide.md +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/Monocle_committer_guide.md +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/Monocle_contributor_guide.md +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/NOTICE +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/README.md +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/SECURITY.md +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/README.md +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/__init__.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/__main__.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/exporters/aws/s3_exporter.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/exporters/aws/s3_exporter_opendal.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/exporters/azure/blob_exporter_opendal.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/exporters/base_exporter.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/exporters/exporter_processor.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/exporters/file_exporter.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/exporters/monocle_exporters.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/__init__.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/common/__init__.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/__init__.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/botocore/__init__.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/botocore/_helper.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/botocore/entities/__init__.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/botocore/entities/inference.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/botocore/handlers/botocore_span_handler.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/botocore/methods.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/flask/__init__.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/flask/_helper.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/flask/methods.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/haystack/__init__.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/haystack/_helper.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/haystack/entities/__init__.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/haystack/entities/retrieval.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/langchain/__init__.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/langchain/_helper.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/langchain/entities/__init__.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/langchain/entities/retrieval.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/langgraph/__init__.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/langgraph/_helper.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/langgraph/entities/__init__.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/langgraph/entities/inference.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/langgraph/methods.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/llamaindex/__init__.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/llamaindex/_helper.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/llamaindex/entities/__init__.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/llamaindex/entities/agent.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/llamaindex/entities/retrieval.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/openai/__init__.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/openai/entities/__init__.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/requests/_helper.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/src/monocle_apptrace/instrumentation/metamodel/requests/methods.py +0 -0
- {monocle_apptrace-0.3.0b5 → monocle_apptrace-0.3.0b6}/tox.ini +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
## Version 0.3.
|
|
1
|
+
## Version 0.3.0b6 (2024-12-10)
|
|
2
2
|
|
|
3
3
|
- Add dev dependency for Mistral AI integration ([#81](https://github.com/monocle2ai/monocle/pull/81))
|
|
4
4
|
- Add VectorStore deployment URL capture support ([#80](https://github.com/monocle2ai/monocle/pull/80))
|
|
@@ -11,6 +11,7 @@ from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult
|
|
|
11
11
|
from typing import Sequence
|
|
12
12
|
from monocle_apptrace.exporters.base_exporter import SpanExporterBase
|
|
13
13
|
import json
|
|
14
|
+
from monocle_apptrace.instrumentation.common.constants import MONOCLE_SDK_VERSION
|
|
14
15
|
logger = logging.getLogger(__name__)
|
|
15
16
|
|
|
16
17
|
class AzureBlobSpanExporter(SpanExporterBase):
|
|
@@ -72,6 +73,12 @@ class AzureBlobSpanExporter(SpanExporterBase):
|
|
|
72
73
|
"""The actual async export logic is run here."""
|
|
73
74
|
# Add spans to the export queue
|
|
74
75
|
for span in spans:
|
|
76
|
+
# Azure blob library has a check to generate it's own span if OpenTelemetry is loaded and Azure trace package is installed (just pip install azure-trace-opentelemetry)
|
|
77
|
+
# With Monocle,OpenTelemetry is always loaded. If the Azure trace package is installed, then it triggers the blob trace generation on every blob operation.
|
|
78
|
+
# Thus, the Monocle span write ends up generating a blob span which again comes back to the exporter .. and would result in an infinite loop.
|
|
79
|
+
# To avoid this, we check if the span has the Monocle SDK version attribute and skip it if it doesn't. That way the blob span genearted by Azure library are not exported.
|
|
80
|
+
if not span.attributes.get(MONOCLE_SDK_VERSION):
|
|
81
|
+
continue # TODO: All exporters to use same base class and check it there
|
|
75
82
|
self.export_queue.append(span)
|
|
76
83
|
if len(self.export_queue) >= self.max_batch_size:
|
|
77
84
|
await self.__export_spans()
|
|
@@ -83,7 +83,7 @@ class OkahuSpanExporter(SpanExporter):
|
|
|
83
83
|
result.text,
|
|
84
84
|
)
|
|
85
85
|
return SpanExportResult.FAILURE
|
|
86
|
-
logger.
|
|
86
|
+
logger.debug("spans successfully exported to okahu")
|
|
87
87
|
return SpanExportResult.SUCCESS
|
|
88
88
|
except ReadTimeout as e:
|
|
89
89
|
logger.warning("Trace export timed out: %s", str(e))
|
|
@@ -37,6 +37,19 @@ service_name_map = {
|
|
|
37
37
|
GITHUB_CODESPACE_SERVICE_NAME: GITHUB_CODESPACE_IDENTIFIER_ENV_NAME
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
|
|
41
|
+
llm_type_map = {
|
|
42
|
+
"sagemakerendpoint": "aws_sagemaker",
|
|
43
|
+
"azureopenai": "azure_openai",
|
|
44
|
+
"openai": "openai",
|
|
45
|
+
"chatopenai": "openai",
|
|
46
|
+
"azurechatopenai": "azure_openai",
|
|
47
|
+
"bedrock": "aws_bedrock",
|
|
48
|
+
"sagemakerllm": "aws_sagemaker",
|
|
49
|
+
"chatbedrock": "aws_bedrock",
|
|
50
|
+
"openaigenerator": "openai",
|
|
51
|
+
}
|
|
52
|
+
|
|
40
53
|
MONOCLE_INSTRUMENTOR = "monocle_apptrace"
|
|
41
54
|
WORKFLOW_TYPE_KEY = "workflow_type"
|
|
42
55
|
DATA_INPUT_KEY = "data.input"
|
|
@@ -52,3 +65,7 @@ MONOCLE_SCOPE_NAME_PREFIX = "monocle.scope."
|
|
|
52
65
|
SCOPE_METHOD_LIST = 'MONOCLE_SCOPE_METHODS'
|
|
53
66
|
SCOPE_METHOD_FILE = 'monocle_scopes.json'
|
|
54
67
|
SCOPE_CONFIG_PATH = 'MONOCLE_SCOPE_CONFIG_PATH'
|
|
68
|
+
TRACE_PROPOGATION_URLS = "MONOCLE_TRACE_PROPAGATATION_URLS"
|
|
69
|
+
WORKFLOW_TYPE_KEY = "monocle.workflow_type"
|
|
70
|
+
WORKFLOW_TYPE_GENERIC = "workflow.generic"
|
|
71
|
+
MONOCLE_SDK_VERSION = "monocle_apptrace.version"
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import logging
|
|
2
|
+
import inspect
|
|
2
3
|
from typing import Collection, Dict, List, Union
|
|
3
4
|
import random
|
|
4
5
|
import uuid
|
|
@@ -14,7 +15,7 @@ from opentelemetry.sdk.trace import Span, TracerProvider
|
|
|
14
15
|
from opentelemetry.sdk.trace.export import BatchSpanProcessor, SpanProcessor
|
|
15
16
|
from opentelemetry.trace import get_tracer
|
|
16
17
|
from wrapt import wrap_function_wrapper
|
|
17
|
-
from opentelemetry.trace.propagation import set_span_in_context
|
|
18
|
+
from opentelemetry.trace.propagation import set_span_in_context, _SPAN_KEY
|
|
18
19
|
from monocle_apptrace.exporters.monocle_exporters import get_monocle_exporter
|
|
19
20
|
from monocle_apptrace.instrumentation.common.span_handler import SpanHandler
|
|
20
21
|
from monocle_apptrace.instrumentation.common.wrapper_method import (
|
|
@@ -22,11 +23,11 @@ from monocle_apptrace.instrumentation.common.wrapper_method import (
|
|
|
22
23
|
WrapperMethod,
|
|
23
24
|
MONOCLE_SPAN_HANDLERS
|
|
24
25
|
)
|
|
25
|
-
from monocle_apptrace.instrumentation.common.wrapper import scope_wrapper
|
|
26
|
+
from monocle_apptrace.instrumentation.common.wrapper import scope_wrapper, ascope_wrapper
|
|
26
27
|
from monocle_apptrace.instrumentation.common.utils import (
|
|
27
|
-
set_scope, remove_scope, http_route_handler, load_scopes
|
|
28
|
+
set_scope, remove_scope, http_route_handler, load_scopes, async_wrapper, http_async_route_handler
|
|
28
29
|
)
|
|
29
|
-
from monocle_apptrace.instrumentation.common.constants import MONOCLE_INSTRUMENTOR
|
|
30
|
+
from monocle_apptrace.instrumentation.common.constants import MONOCLE_INSTRUMENTOR, WORKFLOW_TYPE_KEY
|
|
30
31
|
from functools import wraps
|
|
31
32
|
logger = logging.getLogger(__name__)
|
|
32
33
|
|
|
@@ -67,8 +68,8 @@ class MonocleInstrumentor(BaseInstrumentor):
|
|
|
67
68
|
handler = SpanHandler()
|
|
68
69
|
with tracer.start_as_current_span(span_name) as span:
|
|
69
70
|
response = fn(*args, **kwargs)
|
|
70
|
-
handler.hydrate_span(to_wrap,
|
|
71
|
-
result=response)
|
|
71
|
+
handler.hydrate_span(to_wrap, wrapped=wrapped, instance=instance, args=args, kwargs=kwargs,
|
|
72
|
+
result=response, span=span)
|
|
72
73
|
return response
|
|
73
74
|
|
|
74
75
|
return with_instrumentation
|
|
@@ -93,7 +94,10 @@ class MonocleInstrumentor(BaseInstrumentor):
|
|
|
93
94
|
final_method_list.append(method.to_dict())
|
|
94
95
|
|
|
95
96
|
for method in load_scopes():
|
|
96
|
-
method
|
|
97
|
+
if method.get('async', False):
|
|
98
|
+
method['wrapper_method'] = ascope_wrapper
|
|
99
|
+
else:
|
|
100
|
+
method['wrapper_method'] = scope_wrapper
|
|
97
101
|
final_method_list.append(method)
|
|
98
102
|
|
|
99
103
|
for method_config in final_method_list:
|
|
@@ -191,40 +195,30 @@ def on_processor_start(span: Span, parent_context):
|
|
|
191
195
|
def set_context_properties(properties: dict) -> None:
|
|
192
196
|
attach(set_value(SESSION_PROPERTIES_KEY, properties))
|
|
193
197
|
|
|
194
|
-
|
|
195
|
-
def propagate_trace_id(traceId = "", use_trace_context = False):
|
|
198
|
+
def start_trace():
|
|
196
199
|
try:
|
|
197
|
-
if traceId.startswith("0x"):
|
|
198
|
-
traceId = traceId.lstrip("0x")
|
|
199
200
|
tracer = get_tracer(instrumenting_module_name= MONOCLE_INSTRUMENTOR, tracer_provider= get_tracer_provider())
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
span = tracer.start_span(name = "parent_placeholder_span", context= _parent_span_context)
|
|
206
|
-
updated_span_context = set_span_in_context(span=span, context= _parent_span_context)
|
|
207
|
-
updated_span_context = set_value("root_span_id", span.get_span_context().span_id, updated_span_context)
|
|
208
|
-
token = attach(updated_span_context)
|
|
209
|
-
|
|
210
|
-
span.end()
|
|
211
|
-
tracer.id_generator = initial_id_generator
|
|
201
|
+
span = tracer.start_span(name = "workflow")
|
|
202
|
+
updated_span_context = set_span_in_context(span=span)
|
|
203
|
+
SpanHandler.set_default_monocle_attributes(span)
|
|
204
|
+
SpanHandler.set_workflow_properties(span)
|
|
205
|
+
token = SpanHandler.attach_workflow_type(context=updated_span_context)
|
|
212
206
|
return token
|
|
213
207
|
except:
|
|
214
|
-
logger.warning("Failed to
|
|
215
|
-
|
|
208
|
+
logger.warning("Failed to start trace")
|
|
209
|
+
return None
|
|
216
210
|
|
|
217
|
-
|
|
218
|
-
def propagate_trace_id_from_traceparent():
|
|
219
|
-
propagate_trace_id(use_trace_context = True)
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
def stop_propagate_trace_id(token) -> None:
|
|
211
|
+
def stop_trace(token) -> None:
|
|
223
212
|
try:
|
|
224
|
-
|
|
213
|
+
_parent_span_context = get_current()
|
|
214
|
+
if _parent_span_context is not None:
|
|
215
|
+
parent_span: Span = _parent_span_context.get(_SPAN_KEY, None)
|
|
216
|
+
if parent_span is not None:
|
|
217
|
+
parent_span.end()
|
|
218
|
+
if token is not None:
|
|
219
|
+
SpanHandler.detach_workflow_type(token)
|
|
225
220
|
except:
|
|
226
|
-
logger.warning("Failed to stop
|
|
227
|
-
|
|
221
|
+
logger.warning("Failed to stop trace")
|
|
228
222
|
|
|
229
223
|
def is_valid_trace_id_uuid(traceId: str) -> bool:
|
|
230
224
|
try:
|
|
@@ -248,23 +242,38 @@ def monocle_trace_scope(scope_name: str, scope_value:str = None):
|
|
|
248
242
|
yield
|
|
249
243
|
finally:
|
|
250
244
|
stop_scope(token)
|
|
251
|
-
|
|
245
|
+
|
|
252
246
|
def monocle_trace_scope_method(scope_name: str):
|
|
253
247
|
def decorator(func):
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
result = func
|
|
248
|
+
if inspect.iscoroutinefunction(func):
|
|
249
|
+
@wraps(func)
|
|
250
|
+
async def wrapper(*args, **kwargs):
|
|
251
|
+
result = async_wrapper(func, scope_name, None, *args, **kwargs)
|
|
258
252
|
return result
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
253
|
+
return wrapper
|
|
254
|
+
else:
|
|
255
|
+
@wraps(func)
|
|
256
|
+
def wrapper(*args, **kwargs):
|
|
257
|
+
token = start_scope(scope_name)
|
|
258
|
+
try:
|
|
259
|
+
result = func(*args, **kwargs)
|
|
260
|
+
return result
|
|
261
|
+
finally:
|
|
262
|
+
stop_scope(token)
|
|
263
|
+
return wrapper
|
|
262
264
|
return decorator
|
|
263
265
|
|
|
264
266
|
def monocle_trace_http_route(func):
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
267
|
+
if inspect.iscoroutinefunction(func):
|
|
268
|
+
@wraps(func)
|
|
269
|
+
async def wrapper(*args, **kwargs):
|
|
270
|
+
return http_async_route_handler(func, *args, **kwargs)
|
|
271
|
+
return wrapper
|
|
272
|
+
else:
|
|
273
|
+
@wraps(func)
|
|
274
|
+
def wrapper(*args, **kwargs):
|
|
275
|
+
return http_route_handler(func, *args, **kwargs)
|
|
276
|
+
return wrapper
|
|
268
277
|
|
|
269
278
|
class FixedIdGenerator(id_generator.IdGenerator):
|
|
270
279
|
def __init__(
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
import os
|
|
3
3
|
from importlib.metadata import version
|
|
4
|
-
from opentelemetry.context import
|
|
5
|
-
from opentelemetry.context import get_value
|
|
4
|
+
from opentelemetry.context import get_value, set_value, attach, detach
|
|
6
5
|
from opentelemetry.sdk.trace import Span
|
|
7
6
|
|
|
8
7
|
from monocle_apptrace.instrumentation.common.constants import (
|
|
9
8
|
QUERY,
|
|
10
9
|
service_name_map,
|
|
11
10
|
service_type_map,
|
|
11
|
+
MONOCLE_SDK_VERSION
|
|
12
12
|
)
|
|
13
13
|
from monocle_apptrace.instrumentation.common.utils import set_attribute, get_scopes
|
|
14
|
+
from monocle_apptrace.instrumentation.common.constants import WORKFLOW_TYPE_KEY, WORKFLOW_TYPE_GENERIC
|
|
14
15
|
|
|
15
16
|
logger = logging.getLogger(__name__)
|
|
16
17
|
|
|
@@ -20,8 +21,6 @@ WORKFLOW_TYPE_MAP = {
|
|
|
20
21
|
"haystack": "workflow.haystack"
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
24
|
class SpanHandler:
|
|
26
25
|
|
|
27
26
|
def __init__(self,instrumentor=None):
|
|
@@ -40,18 +39,32 @@ class SpanHandler:
|
|
|
40
39
|
pass
|
|
41
40
|
|
|
42
41
|
def skip_span(self, to_wrap, wrapped, instance, args, kwargs) -> bool:
|
|
42
|
+
# If this is a workflow span type and a workflow span is already generated, then skip generating this span
|
|
43
|
+
if to_wrap.get('span_type') == "workflow" and self.is_workflow_span_active():
|
|
44
|
+
return True
|
|
43
45
|
return False
|
|
44
46
|
|
|
45
47
|
def pre_task_processing(self, to_wrap, wrapped, instance, args,kwargs, span):
|
|
46
|
-
if self.__is_root_span(span):
|
|
47
|
-
try:
|
|
48
|
-
sdk_version = version("monocle_apptrace")
|
|
49
|
-
span.set_attribute("monocle_apptrace.version", sdk_version)
|
|
50
|
-
except Exception as e:
|
|
51
|
-
logger.warning("Exception finding monocle-apptrace version.")
|
|
52
48
|
if "pipeline" in to_wrap['package']:
|
|
53
49
|
set_attribute(QUERY, args[0]['prompt_builder']['question'])
|
|
54
50
|
|
|
51
|
+
@staticmethod
|
|
52
|
+
def set_default_monocle_attributes(span: Span):
|
|
53
|
+
""" Set default monocle attributes for all spans """
|
|
54
|
+
try:
|
|
55
|
+
sdk_version = version("monocle_apptrace")
|
|
56
|
+
span.set_attribute(MONOCLE_SDK_VERSION, sdk_version)
|
|
57
|
+
except Exception as e:
|
|
58
|
+
logger.warning("Exception finding monocle-apptrace version.")
|
|
59
|
+
for scope_key, scope_value in get_scopes().items():
|
|
60
|
+
span.set_attribute(f"scope.{scope_key}", scope_value)
|
|
61
|
+
|
|
62
|
+
@staticmethod
|
|
63
|
+
def set_workflow_properties(span: Span, to_wrap = None):
|
|
64
|
+
""" Set attributes of workflow if this is a root span"""
|
|
65
|
+
SpanHandler.set_workflow_attributes(to_wrap, span)
|
|
66
|
+
SpanHandler.set_app_hosting_identifier_attribute(span)
|
|
67
|
+
|
|
55
68
|
def post_task_processing(self, to_wrap, wrapped, instance, args, kwargs, result, span):
|
|
56
69
|
pass
|
|
57
70
|
|
|
@@ -61,10 +74,8 @@ class SpanHandler:
|
|
|
61
74
|
|
|
62
75
|
def hydrate_attributes(self, to_wrap, wrapped, instance, args, kwargs, result, span):
|
|
63
76
|
span_index = 0
|
|
64
|
-
if
|
|
65
|
-
span_index
|
|
66
|
-
span_index += self.set_app_hosting_identifier_attribute(span, span_index+1)
|
|
67
|
-
|
|
77
|
+
if SpanHandler.is_root_span(span):
|
|
78
|
+
span_index = 2 # root span will have workflow and hosting entities pre-populated
|
|
68
79
|
if 'output_processor' in to_wrap and to_wrap["output_processor"] is not None:
|
|
69
80
|
output_processor=to_wrap['output_processor']
|
|
70
81
|
if 'type' in output_processor:
|
|
@@ -124,46 +135,79 @@ class SpanHandler:
|
|
|
124
135
|
logger.debug(f"Error evaluating accessor for attribute '{attribute_key}': {e}")
|
|
125
136
|
span.add_event(name=event_name, attributes=event_attributes)
|
|
126
137
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
workflow_name = self.get_workflow_name(span=span)
|
|
138
|
+
@staticmethod
|
|
139
|
+
def set_workflow_attributes(to_wrap, span: Span):
|
|
140
|
+
span_index = 1
|
|
141
|
+
workflow_name = SpanHandler.get_workflow_name(span=span)
|
|
132
142
|
if workflow_name:
|
|
133
143
|
span.set_attribute("span.type", "workflow")
|
|
134
144
|
span.set_attribute(f"entity.{span_index}.name", workflow_name)
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if not
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
145
|
+
workflow_type = SpanHandler.get_workflow_type(to_wrap)
|
|
146
|
+
span.set_attribute(f"entity.{span_index}.type", workflow_type)
|
|
147
|
+
|
|
148
|
+
@staticmethod
|
|
149
|
+
def get_workflow_type(to_wrap):
|
|
150
|
+
# workflow type
|
|
151
|
+
workflow_type = WORKFLOW_TYPE_GENERIC
|
|
152
|
+
if to_wrap is not None:
|
|
153
|
+
package_name = to_wrap.get('package')
|
|
154
|
+
for (package, framework_workflow_type) in WORKFLOW_TYPE_MAP.items():
|
|
155
|
+
if (package_name is not None and package in package_name):
|
|
156
|
+
workflow_type = framework_workflow_type
|
|
157
|
+
break
|
|
158
|
+
return workflow_type
|
|
159
|
+
|
|
160
|
+
def set_app_hosting_identifier_attribute(span):
|
|
161
|
+
span_index = 2
|
|
148
162
|
# Search env to indentify the infra service type, if found check env for service name if possible
|
|
163
|
+
span.set_attribute(f"entity.{span_index}.type", f"app_hosting.generic")
|
|
164
|
+
span.set_attribute(f"entity.{span_index}.name", "generic")
|
|
149
165
|
for type_env, type_name in service_type_map.items():
|
|
150
166
|
if type_env in os.environ:
|
|
151
|
-
return_value = 1
|
|
152
167
|
span.set_attribute(f"entity.{span_index}.type", f"app_hosting.{type_name}")
|
|
153
168
|
entity_name_env = service_name_map.get(type_name, "unknown")
|
|
154
169
|
span.set_attribute(f"entity.{span_index}.name", os.environ.get(entity_name_env, "generic"))
|
|
155
|
-
return return_value
|
|
156
170
|
|
|
157
|
-
|
|
171
|
+
@staticmethod
|
|
172
|
+
def get_workflow_name(span: Span) -> str:
|
|
158
173
|
try:
|
|
159
174
|
return get_value("workflow_name") or span.resource.attributes.get("service.name")
|
|
160
175
|
except Exception as e:
|
|
161
176
|
logger.exception(f"Error getting workflow name: {e}")
|
|
162
177
|
return None
|
|
163
178
|
|
|
164
|
-
|
|
179
|
+
@staticmethod
|
|
180
|
+
def is_root_span(curr_span: Span) -> bool:
|
|
165
181
|
try:
|
|
166
182
|
if curr_span is not None and hasattr(curr_span, "parent"):
|
|
167
|
-
return curr_span.parent is None
|
|
183
|
+
return curr_span.parent is None
|
|
168
184
|
except Exception as e:
|
|
169
185
|
logger.warning(f"Error finding root span: {e}")
|
|
186
|
+
|
|
187
|
+
def is_non_workflow_root_span(self, curr_span: Span, to_wrap) -> bool:
|
|
188
|
+
return SpanHandler.is_root_span(curr_span) and to_wrap.get("span_type") != "workflow"
|
|
189
|
+
|
|
190
|
+
def is_workflow_span_active(self):
|
|
191
|
+
return get_value(WORKFLOW_TYPE_KEY) is not None
|
|
192
|
+
|
|
193
|
+
@staticmethod
|
|
194
|
+
def attach_workflow_type(to_wrap=None, context=None):
|
|
195
|
+
token = None
|
|
196
|
+
if to_wrap:
|
|
197
|
+
if to_wrap.get('span_type') == "workflow":
|
|
198
|
+
token = attach(set_value(WORKFLOW_TYPE_KEY,
|
|
199
|
+
SpanHandler.get_workflow_type(to_wrap), context))
|
|
200
|
+
else:
|
|
201
|
+
token = attach(set_value(WORKFLOW_TYPE_KEY, WORKFLOW_TYPE_GENERIC, context))
|
|
202
|
+
return token
|
|
203
|
+
|
|
204
|
+
@staticmethod
|
|
205
|
+
def detach_workflow_type(token):
|
|
206
|
+
if token:
|
|
207
|
+
return detach(token)
|
|
208
|
+
|
|
209
|
+
class NonFrameworkSpanHandler(SpanHandler):
|
|
210
|
+
|
|
211
|
+
# If the language framework is being executed, then skip generating direct openAI spans
|
|
212
|
+
def skip_span(self, to_wrap, wrapped, instance, args, kwargs) -> bool:
|
|
213
|
+
return get_value(WORKFLOW_TYPE_KEY) in WORKFLOW_TYPE_MAP.values()
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import logging, json
|
|
2
2
|
import os
|
|
3
3
|
from typing import Callable, Generic, Optional, TypeVar, Mapping
|
|
4
|
-
|
|
4
|
+
import threading, asyncio
|
|
5
5
|
|
|
6
6
|
from opentelemetry.context import attach, detach, get_current, get_value, set_value, Context
|
|
7
7
|
from opentelemetry.trace import NonRecordingSpan, Span, get_tracer
|
|
@@ -9,7 +9,7 @@ from opentelemetry.trace.propagation import _SPAN_KEY
|
|
|
9
9
|
from opentelemetry.sdk.trace import id_generator, TracerProvider
|
|
10
10
|
from opentelemetry.propagate import inject, extract
|
|
11
11
|
from opentelemetry import baggage
|
|
12
|
-
from monocle_apptrace.instrumentation.common.constants import MONOCLE_SCOPE_NAME_PREFIX, SCOPE_METHOD_FILE, SCOPE_CONFIG_PATH
|
|
12
|
+
from monocle_apptrace.instrumentation.common.constants import MONOCLE_SCOPE_NAME_PREFIX, SCOPE_METHOD_FILE, SCOPE_CONFIG_PATH, llm_type_map
|
|
13
13
|
|
|
14
14
|
T = TypeVar('T')
|
|
15
15
|
U = TypeVar('U')
|
|
@@ -232,13 +232,55 @@ def clear_http_scopes(token:object) -> None:
|
|
|
232
232
|
global http_scopes
|
|
233
233
|
remove_scopes(token)
|
|
234
234
|
|
|
235
|
-
def http_route_handler(
|
|
236
|
-
|
|
235
|
+
def http_route_handler(func, *args, **kwargs):
|
|
236
|
+
if 'req' in kwargs and hasattr(kwargs['req'], 'headers'):
|
|
237
|
+
headers = kwargs['req'].headers
|
|
238
|
+
else:
|
|
239
|
+
headers = None
|
|
240
|
+
token = None
|
|
241
|
+
if headers is not None:
|
|
242
|
+
token = extract_http_headers(headers)
|
|
237
243
|
try:
|
|
238
|
-
result = func(
|
|
244
|
+
result = func(*args, **kwargs)
|
|
239
245
|
return result
|
|
240
246
|
finally:
|
|
241
|
-
|
|
247
|
+
if token is not None:
|
|
248
|
+
clear_http_scopes(token)
|
|
249
|
+
|
|
250
|
+
async def http_async_route_handler(func, *args, **kwargs):
|
|
251
|
+
if 'req' in kwargs and hasattr(kwargs['req'], 'headers'):
|
|
252
|
+
headers = kwargs['req'].headers
|
|
253
|
+
else:
|
|
254
|
+
headers = None
|
|
255
|
+
return async_wrapper(func, None, headers, *args, **kwargs)
|
|
256
|
+
|
|
257
|
+
def run_async_with_scope(method, scope_name, headers, *args, **kwargs):
|
|
258
|
+
token = None
|
|
259
|
+
if scope_name:
|
|
260
|
+
token = set_scope(scope_name)
|
|
261
|
+
elif headers:
|
|
262
|
+
token = extract_http_headers(headers)
|
|
263
|
+
try:
|
|
264
|
+
return asyncio.run(method(*args, **kwargs))
|
|
265
|
+
finally:
|
|
266
|
+
if token:
|
|
267
|
+
remove_scope(token)
|
|
268
|
+
|
|
269
|
+
def async_wrapper(method, scope_name=None, headers=None, *args, **kwargs):
|
|
270
|
+
try:
|
|
271
|
+
run_loop = asyncio.get_running_loop()
|
|
272
|
+
except RuntimeError:
|
|
273
|
+
run_loop = None
|
|
274
|
+
|
|
275
|
+
if run_loop and run_loop.is_running():
|
|
276
|
+
results = []
|
|
277
|
+
thread = threading.Thread(target=lambda: results.append(run_async_with_scope(method, scope_name, headers, *args, **kwargs)))
|
|
278
|
+
thread.start()
|
|
279
|
+
thread.join()
|
|
280
|
+
return_value = results[0] if len(results) > 0 else None
|
|
281
|
+
return return_value
|
|
282
|
+
else:
|
|
283
|
+
return run_async_with_scope(method, scope_name, headers, *args, **kwargs)
|
|
242
284
|
|
|
243
285
|
class Option(Generic[T]):
|
|
244
286
|
def __init__(self, value: Optional[T]):
|
|
@@ -270,6 +312,13 @@ def try_option(func: Callable[..., T], *args, **kwargs) -> Option[T]:
|
|
|
270
312
|
except Exception:
|
|
271
313
|
return Option(None)
|
|
272
314
|
|
|
315
|
+
def get_llm_type(instance):
|
|
316
|
+
try:
|
|
317
|
+
llm_type = llm_type_map.get(type(instance).__name__.lower())
|
|
318
|
+
return llm_type
|
|
319
|
+
except:
|
|
320
|
+
pass
|
|
321
|
+
|
|
273
322
|
def resolve_from_alias(my_map, alias):
|
|
274
323
|
"""Find a alias that is not none from list of aliases"""
|
|
275
324
|
for i in alias:
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# pylint: disable=protected-access
|
|
2
|
+
import logging
|
|
3
|
+
from opentelemetry.trace import Tracer
|
|
4
|
+
from opentelemetry.context import set_value, attach, detach, get_value
|
|
5
|
+
|
|
6
|
+
from monocle_apptrace.instrumentation.common.span_handler import SpanHandler
|
|
7
|
+
from monocle_apptrace.instrumentation.common.utils import (
|
|
8
|
+
get_fully_qualified_class_name,
|
|
9
|
+
with_tracer_wrapper,
|
|
10
|
+
set_scope,
|
|
11
|
+
remove_scope,
|
|
12
|
+
async_wrapper
|
|
13
|
+
)
|
|
14
|
+
from monocle_apptrace.instrumentation.common.constants import WORKFLOW_TYPE_KEY
|
|
15
|
+
logger = logging.getLogger(__name__)
|
|
16
|
+
|
|
17
|
+
def wrapper_processor(async_task: bool, tracer: Tracer, handler: SpanHandler, to_wrap, wrapped, instance, args, kwargs):
|
|
18
|
+
# Some Langchain objects are wrapped elsewhere, so we ignore them here
|
|
19
|
+
if instance.__class__.__name__ in ("AgentExecutor"):
|
|
20
|
+
return wrapped(*args, **kwargs)
|
|
21
|
+
|
|
22
|
+
if hasattr(instance, "name") and instance.name:
|
|
23
|
+
name = f"{to_wrap.get('span_name')}.{instance.name.lower()}"
|
|
24
|
+
elif to_wrap.get("span_name"):
|
|
25
|
+
name = to_wrap.get("span_name")
|
|
26
|
+
else:
|
|
27
|
+
name = get_fully_qualified_class_name(instance)
|
|
28
|
+
|
|
29
|
+
return_value = None
|
|
30
|
+
token = None
|
|
31
|
+
try:
|
|
32
|
+
handler.pre_tracing(to_wrap, wrapped, instance, args, kwargs)
|
|
33
|
+
skip_scan:bool = to_wrap.get('skip_span') or handler.skip_span(to_wrap, wrapped, instance, args, kwargs)
|
|
34
|
+
token = SpanHandler.attach_workflow_type(to_wrap=to_wrap)
|
|
35
|
+
if skip_scan:
|
|
36
|
+
if async_task:
|
|
37
|
+
return_value = async_wrapper(wrapped, None, None, *args, **kwargs)
|
|
38
|
+
else:
|
|
39
|
+
return_value = wrapped(*args, **kwargs)
|
|
40
|
+
else:
|
|
41
|
+
return_value = span_processor(name, async_task, tracer, handler, to_wrap, wrapped, instance, args, kwargs)
|
|
42
|
+
return return_value
|
|
43
|
+
finally:
|
|
44
|
+
handler.detach_workflow_type(token)
|
|
45
|
+
handler.post_tracing(to_wrap, wrapped, instance, args, kwargs, return_value)
|
|
46
|
+
|
|
47
|
+
def span_processor(name: str, async_task: bool, tracer: Tracer, handler: SpanHandler, to_wrap, wrapped, instance, args, kwargs):
|
|
48
|
+
# For singleton spans, eg OpenAI inference generate a workflow span to format the workflow specific attributes
|
|
49
|
+
return_value = None
|
|
50
|
+
with tracer.start_as_current_span(name) as span:
|
|
51
|
+
# Since Spanhandler can be overridden, ensure we set default monocle attributes.
|
|
52
|
+
SpanHandler.set_default_monocle_attributes(span)
|
|
53
|
+
if SpanHandler.is_root_span(span):
|
|
54
|
+
SpanHandler.set_workflow_properties(span, to_wrap)
|
|
55
|
+
if handler.is_non_workflow_root_span(span, to_wrap):
|
|
56
|
+
# This is a direct API call of a non-framework type, call the span_processor recursively for the actual span
|
|
57
|
+
return_value = span_processor(name, async_task, tracer, handler, to_wrap, wrapped, instance, args, kwargs)
|
|
58
|
+
else:
|
|
59
|
+
handler.pre_task_processing(to_wrap, wrapped, instance, args, kwargs, span)
|
|
60
|
+
if async_task:
|
|
61
|
+
return_value = async_wrapper(wrapped, None, None, *args, **kwargs)
|
|
62
|
+
else:
|
|
63
|
+
return_value = wrapped(*args, **kwargs)
|
|
64
|
+
handler.hydrate_span(to_wrap, wrapped, instance, args, kwargs, return_value, span)
|
|
65
|
+
handler.post_task_processing(to_wrap, wrapped, instance, args, kwargs, return_value, span)
|
|
66
|
+
return return_value
|
|
67
|
+
|
|
68
|
+
@with_tracer_wrapper
|
|
69
|
+
def task_wrapper(tracer: Tracer, handler: SpanHandler, to_wrap, wrapped, instance, args, kwargs):
|
|
70
|
+
return wrapper_processor(False, tracer, handler, to_wrap, wrapped, instance, args, kwargs)
|
|
71
|
+
|
|
72
|
+
@with_tracer_wrapper
|
|
73
|
+
async def atask_wrapper(tracer: Tracer, handler: SpanHandler, to_wrap, wrapped, instance, args, kwargs):
|
|
74
|
+
return wrapper_processor(True, tracer, handler, to_wrap, wrapped, instance, args, kwargs)
|
|
75
|
+
|
|
76
|
+
@with_tracer_wrapper
|
|
77
|
+
def scope_wrapper(tracer: Tracer, handler: SpanHandler, to_wrap, wrapped, instance, args, kwargs):
|
|
78
|
+
scope_name = to_wrap.get('scope_name', None)
|
|
79
|
+
if scope_name:
|
|
80
|
+
token = set_scope(scope_name)
|
|
81
|
+
return_value = wrapped(*args, **kwargs)
|
|
82
|
+
if scope_name:
|
|
83
|
+
remove_scope(token)
|
|
84
|
+
return return_value
|
|
85
|
+
|
|
86
|
+
@with_tracer_wrapper
|
|
87
|
+
async def ascope_wrapper(tracer: Tracer, handler: SpanHandler, to_wrap, wrapped, instance, args, kwargs):
|
|
88
|
+
scope_name = to_wrap.get('scope_name', None)
|
|
89
|
+
return_value = async_wrapper(wrapped, scope_name, None, *args, **kwargs)
|
|
90
|
+
return return_value
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# pylint: disable=too-few-public-methods
|
|
2
2
|
from typing import Any, Dict
|
|
3
3
|
from monocle_apptrace.instrumentation.common.wrapper import task_wrapper, scope_wrapper
|
|
4
|
-
from monocle_apptrace.instrumentation.common.span_handler import SpanHandler
|
|
4
|
+
from monocle_apptrace.instrumentation.common.span_handler import SpanHandler, NonFrameworkSpanHandler
|
|
5
5
|
from monocle_apptrace.instrumentation.metamodel.botocore.methods import BOTOCORE_METHODS
|
|
6
6
|
from monocle_apptrace.instrumentation.metamodel.botocore.handlers.botocore_span_handler import BotoCoreSpanHandler
|
|
7
7
|
from monocle_apptrace.instrumentation.metamodel.langchain.methods import (
|
|
@@ -26,13 +26,15 @@ class WrapperMethod:
|
|
|
26
26
|
output_processor : str = None,
|
|
27
27
|
wrapper_method = task_wrapper,
|
|
28
28
|
span_handler = 'default',
|
|
29
|
-
scope_name: str = None
|
|
29
|
+
scope_name: str = None,
|
|
30
|
+
span_type: str = None
|
|
30
31
|
):
|
|
31
32
|
self.package = package
|
|
32
33
|
self.object = object_name
|
|
33
34
|
self.method = method
|
|
34
35
|
self.span_name = span_name
|
|
35
36
|
self.output_processor=output_processor
|
|
37
|
+
self.span_type = span_type
|
|
36
38
|
|
|
37
39
|
self.span_handler:SpanHandler.__class__ = span_handler
|
|
38
40
|
self.scope_name = scope_name
|
|
@@ -51,7 +53,8 @@ class WrapperMethod:
|
|
|
51
53
|
'output_processor': self.output_processor,
|
|
52
54
|
'wrapper_method': self.wrapper_method,
|
|
53
55
|
'span_handler': self.span_handler,
|
|
54
|
-
'scope_name': self.scope_name
|
|
56
|
+
'scope_name': self.scope_name,
|
|
57
|
+
'span_type': self.span_type
|
|
55
58
|
}
|
|
56
59
|
return instance_dict
|
|
57
60
|
|
|
@@ -64,5 +67,6 @@ MONOCLE_SPAN_HANDLERS: Dict[str, SpanHandler] = {
|
|
|
64
67
|
"default": SpanHandler(),
|
|
65
68
|
"botocore_handler": BotoCoreSpanHandler(),
|
|
66
69
|
"flask_handler": FlaskSpanHandler(),
|
|
67
|
-
"request_handler": RequestSpanHandler()
|
|
70
|
+
"request_handler": RequestSpanHandler(),
|
|
71
|
+
"non_framework_handler": NonFrameworkSpanHandler()
|
|
68
72
|
}
|
|
@@ -9,7 +9,7 @@ INFERENCE = {
|
|
|
9
9
|
{
|
|
10
10
|
"_comment": "provider type ,name , deployment , inference_endpoint",
|
|
11
11
|
"attribute": "type",
|
|
12
|
-
"accessor": lambda arguments: 'inference.
|
|
12
|
+
"accessor": lambda arguments: 'inference.azure_openai'
|
|
13
13
|
},
|
|
14
14
|
{
|
|
15
15
|
"attribute": "provider_name",
|