monocle-apptrace 0.1.1__py3-none-any.whl → 0.3.0__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/__init__.py +1 -0
- monocle_apptrace/__main__.py +19 -0
- monocle_apptrace/exporters/aws/s3_exporter.py +181 -0
- monocle_apptrace/exporters/aws/s3_exporter_opendal.py +137 -0
- monocle_apptrace/exporters/azure/blob_exporter.py +146 -0
- monocle_apptrace/exporters/azure/blob_exporter_opendal.py +162 -0
- monocle_apptrace/exporters/base_exporter.py +48 -0
- monocle_apptrace/exporters/exporter_processor.py +144 -0
- monocle_apptrace/exporters/file_exporter.py +16 -0
- monocle_apptrace/exporters/monocle_exporters.py +55 -0
- monocle_apptrace/exporters/okahu/okahu_exporter.py +117 -0
- monocle_apptrace/instrumentation/__init__.py +1 -0
- monocle_apptrace/instrumentation/common/__init__.py +2 -0
- monocle_apptrace/instrumentation/common/constants.py +70 -0
- monocle_apptrace/instrumentation/common/instrumentor.py +362 -0
- monocle_apptrace/instrumentation/common/span_handler.py +220 -0
- monocle_apptrace/instrumentation/common/utils.py +356 -0
- monocle_apptrace/instrumentation/common/wrapper.py +92 -0
- monocle_apptrace/instrumentation/common/wrapper_method.py +72 -0
- monocle_apptrace/instrumentation/metamodel/__init__.py +0 -0
- monocle_apptrace/instrumentation/metamodel/botocore/__init__.py +0 -0
- monocle_apptrace/instrumentation/metamodel/botocore/_helper.py +95 -0
- monocle_apptrace/instrumentation/metamodel/botocore/entities/__init__.py +0 -0
- monocle_apptrace/instrumentation/metamodel/botocore/entities/inference.py +65 -0
- monocle_apptrace/instrumentation/metamodel/botocore/handlers/botocore_span_handler.py +26 -0
- monocle_apptrace/instrumentation/metamodel/botocore/methods.py +16 -0
- monocle_apptrace/instrumentation/metamodel/flask/__init__.py +0 -0
- monocle_apptrace/instrumentation/metamodel/flask/_helper.py +29 -0
- monocle_apptrace/instrumentation/metamodel/flask/methods.py +13 -0
- monocle_apptrace/instrumentation/metamodel/haystack/__init__.py +0 -0
- monocle_apptrace/instrumentation/metamodel/haystack/_helper.py +127 -0
- monocle_apptrace/instrumentation/metamodel/haystack/entities/__init__.py +0 -0
- monocle_apptrace/instrumentation/metamodel/haystack/entities/inference.py +76 -0
- monocle_apptrace/instrumentation/metamodel/haystack/entities/retrieval.py +61 -0
- monocle_apptrace/instrumentation/metamodel/haystack/methods.py +43 -0
- monocle_apptrace/instrumentation/metamodel/langchain/__init__.py +0 -0
- monocle_apptrace/instrumentation/metamodel/langchain/_helper.py +127 -0
- monocle_apptrace/instrumentation/metamodel/langchain/entities/__init__.py +0 -0
- monocle_apptrace/instrumentation/metamodel/langchain/entities/inference.py +72 -0
- monocle_apptrace/instrumentation/metamodel/langchain/entities/retrieval.py +58 -0
- monocle_apptrace/{metamodel/maps/lang_chain_methods.json → instrumentation/metamodel/langchain/methods.py} +48 -43
- monocle_apptrace/instrumentation/metamodel/langgraph/__init__.py +0 -0
- monocle_apptrace/instrumentation/metamodel/langgraph/_helper.py +48 -0
- monocle_apptrace/instrumentation/metamodel/langgraph/entities/__init__.py +0 -0
- monocle_apptrace/instrumentation/metamodel/langgraph/entities/inference.py +56 -0
- monocle_apptrace/instrumentation/metamodel/langgraph/methods.py +14 -0
- monocle_apptrace/instrumentation/metamodel/llamaindex/__init__.py +0 -0
- monocle_apptrace/instrumentation/metamodel/llamaindex/_helper.py +172 -0
- monocle_apptrace/instrumentation/metamodel/llamaindex/entities/__init__.py +0 -0
- monocle_apptrace/instrumentation/metamodel/llamaindex/entities/agent.py +47 -0
- monocle_apptrace/instrumentation/metamodel/llamaindex/entities/inference.py +73 -0
- monocle_apptrace/instrumentation/metamodel/llamaindex/entities/retrieval.py +57 -0
- monocle_apptrace/instrumentation/metamodel/llamaindex/methods.py +101 -0
- monocle_apptrace/instrumentation/metamodel/openai/__init__.py +0 -0
- monocle_apptrace/instrumentation/metamodel/openai/_helper.py +112 -0
- monocle_apptrace/instrumentation/metamodel/openai/entities/__init__.py +0 -0
- monocle_apptrace/instrumentation/metamodel/openai/entities/inference.py +71 -0
- monocle_apptrace/instrumentation/metamodel/openai/entities/retrieval.py +43 -0
- monocle_apptrace/instrumentation/metamodel/openai/methods.py +45 -0
- monocle_apptrace/instrumentation/metamodel/requests/__init__.py +4 -0
- monocle_apptrace/instrumentation/metamodel/requests/_helper.py +31 -0
- monocle_apptrace/instrumentation/metamodel/requests/methods.py +12 -0
- {monocle_apptrace-0.1.1.dist-info → monocle_apptrace-0.3.0.dist-info}/METADATA +23 -2
- monocle_apptrace-0.3.0.dist-info/RECORD +68 -0
- {monocle_apptrace-0.1.1.dist-info → monocle_apptrace-0.3.0.dist-info}/WHEEL +1 -1
- monocle_apptrace/constants.py +0 -22
- monocle_apptrace/haystack/__init__.py +0 -9
- monocle_apptrace/haystack/wrap_node.py +0 -27
- monocle_apptrace/haystack/wrap_openai.py +0 -44
- monocle_apptrace/haystack/wrap_pipeline.py +0 -62
- monocle_apptrace/instrumentor.py +0 -124
- monocle_apptrace/langchain/__init__.py +0 -6
- monocle_apptrace/llamaindex/__init__.py +0 -15
- monocle_apptrace/metamodel/README.md +0 -47
- monocle_apptrace/metamodel/entities/README.md +0 -54
- monocle_apptrace/metamodel/entities/entity_types.json +0 -157
- monocle_apptrace/metamodel/entities/entity_types.py +0 -51
- monocle_apptrace/metamodel/maps/haystack_methods.json +0 -25
- monocle_apptrace/metamodel/maps/llama_index_methods.json +0 -70
- monocle_apptrace/metamodel/spans/README.md +0 -121
- monocle_apptrace/metamodel/spans/span_example.json +0 -140
- monocle_apptrace/metamodel/spans/span_format.json +0 -55
- monocle_apptrace/utils.py +0 -93
- monocle_apptrace/wrap_common.py +0 -311
- monocle_apptrace/wrapper.py +0 -24
- monocle_apptrace-0.1.1.dist-info/RECORD +0 -29
- {monocle_apptrace-0.1.1.dist-info → monocle_apptrace-0.3.0.dist-info}/licenses/LICENSE +0 -0
- {monocle_apptrace-0.1.1.dist-info → monocle_apptrace-0.3.0.dist-info}/licenses/NOTICE +0 -0
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
# Monocle Span format
|
|
2
|
-
Monocle generates [traces](../../../../Monocle_User_Guide.md#traces) which comprises of [spans](../../../../Monocle_User_Guide.md#spans). Note that Monocle trace is [OpenTelemetry format](https://opentelemetry.io/docs/concepts/signals/traces/) compatible. Each span is essentially a step in the execution that interacts with one of more GenAI technology components. This document explains the [span format](./span_format.json) that Monocle generates for GenAI application tracing.
|
|
3
|
-
|
|
4
|
-
Per the OpenTelemetry convention, each span contains an attribute section and event section. In Monocle generated trace, the attribute sections includes details of GenAI entities used in the span. The event section includes the input, output and metadata related to the execution of that span.
|
|
5
|
-
|
|
6
|
-
## Attributes
|
|
7
|
-
The attribute sections includes details of GenAI entities used in the span. For each entity used in the span in includes the entity name and entity type. For every type of entity, there are required and optional attributes listed below.
|
|
8
|
-
### Json format
|
|
9
|
-
```json
|
|
10
|
-
attributes:
|
|
11
|
-
"span.type": "Monocle-span-type",
|
|
12
|
-
"entity.count": "count-of-entities",
|
|
13
|
-
|
|
14
|
-
"entity.<index>.name": "Monocle-Entity-name",
|
|
15
|
-
"entity.<index>.type": "MonocleEntity.<entity-type>"
|
|
16
|
-
...
|
|
17
|
-
```
|
|
18
|
-
The ```entity.count``` indicates total number of entities used in the given span. For each entity, the details are captured in ```entity.<index>.X```. For example,
|
|
19
|
-
```json
|
|
20
|
-
"attributes": {
|
|
21
|
-
"span.type": "Inference",
|
|
22
|
-
"entity.count": 2,
|
|
23
|
-
"entity.1.name": "AzureOpenAI",
|
|
24
|
-
"entity.1.type": "Inference.Azure_oai",
|
|
25
|
-
"entity.2.name": "gpt-35-turbo",
|
|
26
|
-
"entity.2.type": "Model.LLM",
|
|
27
|
-
"entity.2.model_name": "gpt-35-turbo",
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
### Entity type specific attributes
|
|
31
|
-
#### MonocleEntity.Workflow
|
|
32
|
-
| Name | Description | Values | Required |
|
|
33
|
-
| - | - | - | - |
|
|
34
|
-
| name | Entity name generated by Monocle | Name String | Required |
|
|
35
|
-
| type | Monocle Entity type | MonocleEntity.Workflow | Required |
|
|
36
|
-
| optional-attribute | Additional attribute specific to entity | | Optional |
|
|
37
|
-
|
|
38
|
-
### MonocleEntity.Model
|
|
39
|
-
| Name | Description | Values | Required |
|
|
40
|
-
| - | - | - | - |
|
|
41
|
-
| name | Entity name generated by Monocle | Name String | Required |
|
|
42
|
-
| type | Monocle Entity type | MonocleEntity.Model | Required |
|
|
43
|
-
| model_name | Name of model | String | Required |
|
|
44
|
-
| optional-attribute | Additional attribute specific to entity | | Optional |
|
|
45
|
-
|
|
46
|
-
### MonocleEntity.AppHosting
|
|
47
|
-
| Name | Description | Values | Required |
|
|
48
|
-
| - | - | - | - |
|
|
49
|
-
| name | Entity name generated by Monocle | Name String | Required |
|
|
50
|
-
| type | Monocle Entity type | MonocleEntity.AppHosting | Required |
|
|
51
|
-
| optional-attribute | Additional attribute specific to entity | | Optional |
|
|
52
|
-
|
|
53
|
-
### MonocleEntity.Inference
|
|
54
|
-
| Name | Description | Values | Required |
|
|
55
|
-
| - | - | - | - |
|
|
56
|
-
| name | Entity name generated by Monocle | Name String | Required |
|
|
57
|
-
| type | Monocle Entity type | MonocleEntity.Inference | Required |
|
|
58
|
-
| optional-attribute | Additional attribute specific to entity | | Optional |
|
|
59
|
-
|
|
60
|
-
### MonocleEntity.VectorDB
|
|
61
|
-
| Name | Description | Values | Required |
|
|
62
|
-
| - | - | - | - |
|
|
63
|
-
| name | Entity name generated by Monocle | Name String | Required |
|
|
64
|
-
| type | Monocle Entity type | MonocleEntity.VectorDB | Required |
|
|
65
|
-
| optional-attribute | Additional attribute specific to entity | | Optional |
|
|
66
|
-
|
|
67
|
-
## Events
|
|
68
|
-
The event section includes the input, output and metadata generated by that span execution. For each type of span, there are required and option input, output and metadata items listed below. If there's no data genearated in the space, the events will be an empty array.
|
|
69
|
-
|
|
70
|
-
### Json format
|
|
71
|
-
```json
|
|
72
|
-
"events" : [
|
|
73
|
-
{
|
|
74
|
-
"name": "data.input",
|
|
75
|
-
"timestamp": "UTC timestamp",
|
|
76
|
-
"attributes": {
|
|
77
|
-
"input_attribute": "value"
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
"name": "data.output",
|
|
82
|
-
"timestamp": "UTC timestamp",
|
|
83
|
-
"attributes": {
|
|
84
|
-
"output_attribute": "value"
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
"name": "metadata",
|
|
89
|
-
"timestamp": "UTC timestamp",
|
|
90
|
-
"attributes": {
|
|
91
|
-
"metadata_attribute": "value"
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
]
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
## Span types and events
|
|
98
|
-
The ```span.type``` captured in ```attributes``` section of the span dectates the format of the ```events```
|
|
99
|
-
### SpanType.Retrieval
|
|
100
|
-
| Name | Description | Values | Required |
|
|
101
|
-
| - | - | - | - |
|
|
102
|
-
| name | event name | data.input or data.output or metadata | Required |
|
|
103
|
-
| timestamp | timestap when the event occurred | UTC timestamp | Required |
|
|
104
|
-
| attributes | input/output/metadata attributes generated in span | Dictionary | Required |
|
|
105
|
-
|
|
106
|
-
### SpanType.Inference
|
|
107
|
-
| Name | Description | Values | Required |
|
|
108
|
-
| - | - | - | - |
|
|
109
|
-
| name | event name | data.input or data.output or metadata | Required |
|
|
110
|
-
| timestamp | timestap when the event occurred | UTC timestamp | Required |
|
|
111
|
-
| attributes | input/output/metadata attributes generated in span | Dictionary | Required |
|
|
112
|
-
|
|
113
|
-
### SpanType.Workflow
|
|
114
|
-
| Name | Description | Values | Required |
|
|
115
|
-
| - | - | - | - |
|
|
116
|
-
| name | event name | data.input or data.output or metadata | Required |
|
|
117
|
-
| timestamp | timestap when the event occurred | UTC timestamp | Required |
|
|
118
|
-
| attributes | input/output/metadata attributes generated in span | Dictionary | Required |
|
|
119
|
-
|
|
120
|
-
### SpanType.Internal
|
|
121
|
-
Events will be empty
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "llamaindex.retrieve",
|
|
3
|
-
"context": {
|
|
4
|
-
"trace_id": "0x93cd0bf865b3ffcc3cf9c075dc3e3797",
|
|
5
|
-
"span_id": "0x5d3f839e900bda24",
|
|
6
|
-
"trace_state": "[]"
|
|
7
|
-
},
|
|
8
|
-
"kind": "SpanKind.CLIENT",
|
|
9
|
-
"parent_id": "0x7a63d63e42ccac60",
|
|
10
|
-
"start_time": "2024-09-09T14:38:45.237182Z",
|
|
11
|
-
"end_time": "2024-09-09T14:38:45.620112Z",
|
|
12
|
-
"status": {
|
|
13
|
-
"status_code": "OK"
|
|
14
|
-
},
|
|
15
|
-
"attributes": {
|
|
16
|
-
"span.type": "Retrieval",
|
|
17
|
-
"entity.count": 2,
|
|
18
|
-
"entity.1.name": "ChromaVectorStore",
|
|
19
|
-
"entity.1.type": "vectorstore.chroma",
|
|
20
|
-
"entity.1.embedding-model-name": "BAAI/bge-small-en-v1.5",
|
|
21
|
-
"entity.2.name": "BAAI/bge-small-en-v1.5",
|
|
22
|
-
"entity.2.type": "model.embedding",
|
|
23
|
-
"entity.2.model_name": "BAAI/bge-small-en-v1.5"
|
|
24
|
-
},
|
|
25
|
-
"events": [
|
|
26
|
-
{
|
|
27
|
-
"name": "data.input",
|
|
28
|
-
"timestamp": "timestamp",
|
|
29
|
-
"attributes": {
|
|
30
|
-
"context_input": "question: What is an americano?"
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
"name": "data.output",
|
|
35
|
-
"timestamp": "timestamp",
|
|
36
|
-
"attributes": {
|
|
37
|
-
"context_output": "Coffee is a hot drink made from the roasted and ground seeds (coffee beans) of a tropical shrub\nA latte consists of one or more shots of espresso, served in a glass (or sometimes a cup), into which hot steamed milk is added\nAmericano is a type of coffee drink prepared by diluting an espresso shot with hot water at a 1:3 to 1:4 ratio, resulting in a drink that retains the complex flavors of espresso, but in a lighter way"
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
],
|
|
42
|
-
"links": [],
|
|
43
|
-
"resource": {
|
|
44
|
-
"attributes": {
|
|
45
|
-
"service.name": "coffee-bot"
|
|
46
|
-
},
|
|
47
|
-
"schema_url": ""
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
"name": "llamaindex.openai",
|
|
52
|
-
"context": {
|
|
53
|
-
"trace_id": "0x93cd0bf865b3ffcc3cf9c075dc3e3797",
|
|
54
|
-
"span_id": "0x8b6363e1937a4d7b",
|
|
55
|
-
"trace_state": "[]"
|
|
56
|
-
},
|
|
57
|
-
"kind": "SpanKind.CLIENT",
|
|
58
|
-
"parent_id": "0x7a63d63e42ccac60",
|
|
59
|
-
"start_time": "2024-09-09T14:38:45.622174Z",
|
|
60
|
-
"end_time": "2024-09-09T14:38:46.514120Z",
|
|
61
|
-
"status": {
|
|
62
|
-
"status_code": "OK"
|
|
63
|
-
},
|
|
64
|
-
"attributes": {
|
|
65
|
-
"span.type": "inference",
|
|
66
|
-
"entity.count": 2,
|
|
67
|
-
"entity.1.name": "AzureOpenAI",
|
|
68
|
-
"entity.1.type": "inference.azure_oai",
|
|
69
|
-
"entity.1.provider_name": "openai.azure.com",
|
|
70
|
-
"entity.1.deployment": "kshitiz-gpt",
|
|
71
|
-
"entity.1.inference_endpoint": "https://okahu-openai-dev.openai.azure.com/",
|
|
72
|
-
|
|
73
|
-
"entity.2.name": "gpt-35-turbo",
|
|
74
|
-
"entity.2.type": "model.llm",
|
|
75
|
-
"entity.2.model_name": "gpt-35-turbo"
|
|
76
|
-
},
|
|
77
|
-
"events": [
|
|
78
|
-
{
|
|
79
|
-
"name": "data.input",
|
|
80
|
-
"timestamp": "timestamp",
|
|
81
|
-
"attributes": {
|
|
82
|
-
"question": "What is an americano?",
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
"name": "data.output",
|
|
87
|
-
"timestamp": "timestamp",
|
|
88
|
-
"attributes": {
|
|
89
|
-
"response": "An americano is a type of coffee drink that is made by diluting an espresso shot with hot water at a 1:3 to 1:4 ratio, resulting in a drink that retains the complex flavors of espresso, but in a lighter way.",
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
"name": "metadata",
|
|
94
|
-
"timestamp": "timestamp",
|
|
95
|
-
"attributes": {
|
|
96
|
-
"temperature": 0.1,
|
|
97
|
-
"completion_tokens": 52,
|
|
98
|
-
"prompt_tokens": 233,
|
|
99
|
-
"total_tokens": 285
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
],
|
|
103
|
-
"links": [],
|
|
104
|
-
"resource": {
|
|
105
|
-
"attributes": {
|
|
106
|
-
"service.name": "coffee-bot"
|
|
107
|
-
},
|
|
108
|
-
"schema_url": ""
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
{
|
|
112
|
-
"name": "llamaindex.query",
|
|
113
|
-
"context": {
|
|
114
|
-
"trace_id": "0x93cd0bf865b3ffcc3cf9c075dc3e3797",
|
|
115
|
-
"span_id": "0x7a63d63e42ccac60",
|
|
116
|
-
"trace_state": "[]"
|
|
117
|
-
},
|
|
118
|
-
"kind": "SpanKind.CLIENT",
|
|
119
|
-
"parent_id": null,
|
|
120
|
-
"start_time": "2024-09-09T14:38:45.236627Z",
|
|
121
|
-
"end_time": "2024-09-09T14:38:46.514442Z",
|
|
122
|
-
"status": {
|
|
123
|
-
"status_code": "OK"
|
|
124
|
-
},
|
|
125
|
-
"attributes": {
|
|
126
|
-
"span.type": "workflow",
|
|
127
|
-
"entity.count": 1,
|
|
128
|
-
"entity.1.name": "coffee-bot",
|
|
129
|
-
"entity.1.type": "workflow.llama_index"
|
|
130
|
-
},
|
|
131
|
-
"events": [
|
|
132
|
-
],
|
|
133
|
-
"links": [],
|
|
134
|
-
"resource": {
|
|
135
|
-
"attributes": {
|
|
136
|
-
"service.name": "coffee-bot"
|
|
137
|
-
},
|
|
138
|
-
"schema_url": ""
|
|
139
|
-
}
|
|
140
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "span-name",
|
|
3
|
-
"context": {
|
|
4
|
-
"trace_id": "trace-id",
|
|
5
|
-
"span_id": "span-id",
|
|
6
|
-
"trace_state": "[]"
|
|
7
|
-
},
|
|
8
|
-
"kind": "SpanKind.CLIENT",
|
|
9
|
-
"parent_id": "parent-id or None (for root span)",
|
|
10
|
-
"start_time": "UTC timestamp",
|
|
11
|
-
"end_time": "UTC timestamp",
|
|
12
|
-
"status": {
|
|
13
|
-
"status_code": "OK or Error"
|
|
14
|
-
},
|
|
15
|
-
"attributes": {
|
|
16
|
-
"description": "List of AI component entities used in this span, eg Model, Inference hosting service. Needs to be one of the supported entity types.",
|
|
17
|
-
|
|
18
|
-
"span.type": "Monocle-span-type",
|
|
19
|
-
"entity.count": "count-of-entities",
|
|
20
|
-
|
|
21
|
-
"entity.<index>.name": "Monocle-Entity-name",
|
|
22
|
-
"entity.<index>.type": "Monocle-Entity-Type",
|
|
23
|
-
"entity.<index>.<attribute>": "Value"
|
|
24
|
-
},
|
|
25
|
-
"events" : [
|
|
26
|
-
{
|
|
27
|
-
"name": "data.input",
|
|
28
|
-
"timestamp": "UTC timestamp",
|
|
29
|
-
"attributes": {
|
|
30
|
-
"input_attribute": "value"
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
"name": "data.output",
|
|
35
|
-
"timestamp": "UTC timestamp",
|
|
36
|
-
"attributes": {
|
|
37
|
-
"output_attribute": "value"
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
"name": "metadata",
|
|
42
|
-
"timestamp": "UTC timestamp",
|
|
43
|
-
"attributes": {
|
|
44
|
-
"metadata_attribute": "value"
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
],
|
|
48
|
-
"links": [],
|
|
49
|
-
"resource": {
|
|
50
|
-
"attributes": {
|
|
51
|
-
"service.name": "top-workflow-name"
|
|
52
|
-
},
|
|
53
|
-
"schema_url": ""
|
|
54
|
-
}
|
|
55
|
-
}
|
monocle_apptrace/utils.py
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import logging
|
|
2
|
-
import json
|
|
3
|
-
from importlib import import_module
|
|
4
|
-
import os
|
|
5
|
-
from opentelemetry.trace import Span
|
|
6
|
-
from monocle_apptrace.constants import azure_service_map, aws_service_map
|
|
7
|
-
|
|
8
|
-
embedding_model_context = {}
|
|
9
|
-
|
|
10
|
-
def set_span_attribute(span, name, value):
|
|
11
|
-
if value is not None:
|
|
12
|
-
if value != "":
|
|
13
|
-
span.set_attribute(name, value)
|
|
14
|
-
|
|
15
|
-
def dont_throw(func):
|
|
16
|
-
"""
|
|
17
|
-
A decorator that wraps the passed in function and logs exceptions instead of throwing them.
|
|
18
|
-
|
|
19
|
-
@param func: The function to wrap
|
|
20
|
-
@return: The wrapper function
|
|
21
|
-
"""
|
|
22
|
-
# Obtain a logger specific to the function's module
|
|
23
|
-
logger = logging.getLogger(func.__module__)
|
|
24
|
-
# pylint: disable=inconsistent-return-statements
|
|
25
|
-
def wrapper(*args, **kwargs):
|
|
26
|
-
try:
|
|
27
|
-
return func(*args, **kwargs)
|
|
28
|
-
except Exception as ex:
|
|
29
|
-
logger.warning("Failed to execute %s, error: %s", func.__name__, str(ex))
|
|
30
|
-
return wrapper
|
|
31
|
-
|
|
32
|
-
def with_tracer_wrapper(func):
|
|
33
|
-
"""Helper for providing tracer for wrapper functions."""
|
|
34
|
-
|
|
35
|
-
def _with_tracer(tracer, to_wrap):
|
|
36
|
-
def wrapper(wrapped, instance, args, kwargs):
|
|
37
|
-
return func(tracer, to_wrap, wrapped, instance, args, kwargs)
|
|
38
|
-
|
|
39
|
-
return wrapper
|
|
40
|
-
|
|
41
|
-
return _with_tracer
|
|
42
|
-
|
|
43
|
-
def resolve_from_alias(my_map, alias):
|
|
44
|
-
"""Find a alias that is not none from list of aliases"""
|
|
45
|
-
|
|
46
|
-
for i in alias:
|
|
47
|
-
if i in my_map.keys():
|
|
48
|
-
return my_map[i]
|
|
49
|
-
return None
|
|
50
|
-
|
|
51
|
-
def load_wrapper_from_config(config_file_path: str, module_name: str = None):
|
|
52
|
-
wrapper_methods = []
|
|
53
|
-
with open(config_file_path, encoding='UTF-8') as config_file:
|
|
54
|
-
json_data = json.load(config_file)
|
|
55
|
-
wrapper_methods = json_data["wrapper_methods"]
|
|
56
|
-
for wrapper_method in wrapper_methods:
|
|
57
|
-
wrapper_method["wrapper"] = get_wrapper_method(
|
|
58
|
-
wrapper_method["wrapper_package"], wrapper_method["wrapper_method"])
|
|
59
|
-
if "span_name_getter_method" in wrapper_method :
|
|
60
|
-
wrapper_method["span_name_getter"] = get_wrapper_method(
|
|
61
|
-
wrapper_method["span_name_getter_package"],
|
|
62
|
-
wrapper_method["span_name_getter_method"])
|
|
63
|
-
return wrapper_methods
|
|
64
|
-
|
|
65
|
-
def get_wrapper_method(package_name: str, method_name: str):
|
|
66
|
-
wrapper_module = import_module("monocle_apptrace." + package_name)
|
|
67
|
-
return getattr(wrapper_module, method_name)
|
|
68
|
-
|
|
69
|
-
def update_span_with_infra_name(span: Span, span_key: str):
|
|
70
|
-
for key,val in azure_service_map.items():
|
|
71
|
-
if key in os.environ:
|
|
72
|
-
span.set_attribute(span_key, val)
|
|
73
|
-
for key,val in aws_service_map.items():
|
|
74
|
-
if key in os.environ:
|
|
75
|
-
span.set_attribute(span_key, val)
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
def set_embedding_model(model_name: str):
|
|
79
|
-
"""
|
|
80
|
-
Sets the embedding model in the global context.
|
|
81
|
-
|
|
82
|
-
@param model_name: The name of the embedding model to set
|
|
83
|
-
"""
|
|
84
|
-
embedding_model_context['embedding_model'] = model_name
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
def get_embedding_model() -> str:
|
|
88
|
-
"""
|
|
89
|
-
Retrieves the embedding model from the global context.
|
|
90
|
-
|
|
91
|
-
@return: The name of the embedding model, or 'unknown' if not set
|
|
92
|
-
"""
|
|
93
|
-
return embedding_model_context.get('embedding_model', 'unknown')
|