netra-sdk 0.1.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 netra-sdk might be problematic. Click here for more details.
- netra/__init__.py +148 -0
- netra/anonymizer/__init__.py +7 -0
- netra/anonymizer/anonymizer.py +79 -0
- netra/anonymizer/base.py +159 -0
- netra/anonymizer/fp_anonymizer.py +182 -0
- netra/config.py +111 -0
- netra/decorators.py +167 -0
- netra/exceptions/__init__.py +6 -0
- netra/exceptions/injection.py +33 -0
- netra/exceptions/pii.py +46 -0
- netra/input_scanner.py +142 -0
- netra/instrumentation/__init__.py +257 -0
- netra/instrumentation/aiohttp/__init__.py +378 -0
- netra/instrumentation/aiohttp/version.py +1 -0
- netra/instrumentation/cohere/__init__.py +446 -0
- netra/instrumentation/cohere/version.py +1 -0
- netra/instrumentation/google_genai/__init__.py +506 -0
- netra/instrumentation/google_genai/config.py +5 -0
- netra/instrumentation/google_genai/utils.py +31 -0
- netra/instrumentation/google_genai/version.py +1 -0
- netra/instrumentation/httpx/__init__.py +545 -0
- netra/instrumentation/httpx/version.py +1 -0
- netra/instrumentation/instruments.py +78 -0
- netra/instrumentation/mistralai/__init__.py +545 -0
- netra/instrumentation/mistralai/config.py +5 -0
- netra/instrumentation/mistralai/utils.py +30 -0
- netra/instrumentation/mistralai/version.py +1 -0
- netra/instrumentation/weaviate/__init__.py +121 -0
- netra/instrumentation/weaviate/version.py +1 -0
- netra/pii.py +757 -0
- netra/processors/__init__.py +4 -0
- netra/processors/session_span_processor.py +55 -0
- netra/processors/span_aggregation_processor.py +365 -0
- netra/scanner.py +104 -0
- netra/session.py +185 -0
- netra/session_manager.py +96 -0
- netra/tracer.py +99 -0
- netra/version.py +1 -0
- netra_sdk-0.1.0.dist-info/LICENCE +201 -0
- netra_sdk-0.1.0.dist-info/METADATA +573 -0
- netra_sdk-0.1.0.dist-info/RECORD +42 -0
- netra_sdk-0.1.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"""OpenTelemetry Weaviate instrumentation"""
|
|
2
|
+
|
|
3
|
+
import importlib
|
|
4
|
+
import logging
|
|
5
|
+
from typing import Collection, Optional
|
|
6
|
+
|
|
7
|
+
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
|
|
8
|
+
from opentelemetry.instrumentation.utils import unwrap
|
|
9
|
+
from opentelemetry.instrumentation.weaviate.config import Config
|
|
10
|
+
from opentelemetry.instrumentation.weaviate.version import __version__
|
|
11
|
+
from opentelemetry.instrumentation.weaviate.wrapper import _wrap
|
|
12
|
+
from opentelemetry.trace import get_tracer
|
|
13
|
+
from wrapt import wrap_function_wrapper
|
|
14
|
+
|
|
15
|
+
logger = logging.getLogger(__name__)
|
|
16
|
+
|
|
17
|
+
_instruments = ("weaviate-client >= 3.26.0, <5",)
|
|
18
|
+
|
|
19
|
+
WRAPPED_METHODS = [
|
|
20
|
+
{
|
|
21
|
+
"module": "weaviate.collections.collections",
|
|
22
|
+
"object": "_Collections",
|
|
23
|
+
"method": "get",
|
|
24
|
+
"span_name": "db.weaviate.collections.get",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"module": "weaviate.collections.collections",
|
|
28
|
+
"object": "_Collections",
|
|
29
|
+
"method": "create",
|
|
30
|
+
"span_name": "db.weaviate.collections.create",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"module": "weaviate.collections.collections",
|
|
34
|
+
"object": "_Collections",
|
|
35
|
+
"method": "create_from_dict",
|
|
36
|
+
"span_name": "db.weaviate.collections.create_from_dict",
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"module": "weaviate.collections.collections",
|
|
40
|
+
"object": "_Collections",
|
|
41
|
+
"method": "delete",
|
|
42
|
+
"span_name": "db.weaviate.collections.delete",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"module": "weaviate.collections.collections",
|
|
46
|
+
"object": "_Collections",
|
|
47
|
+
"method": "delete_all",
|
|
48
|
+
"span_name": "db.weaviate.collections.delete_all",
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"module": "weaviate.collections.data",
|
|
52
|
+
"object": "_DataCollection",
|
|
53
|
+
"method": "insert",
|
|
54
|
+
"span_name": "db.weaviate.collections.data.insert",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"module": "weaviate.collections.data",
|
|
58
|
+
"object": "_DataCollection",
|
|
59
|
+
"method": "replace",
|
|
60
|
+
"span_name": "db.weaviate.collections.data.replace",
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"module": "weaviate.collections.data",
|
|
64
|
+
"object": "_DataCollection",
|
|
65
|
+
"method": "update",
|
|
66
|
+
"span_name": "db.weaviate.collections.data.update",
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"module": "weaviate.collections.batch.collection",
|
|
70
|
+
"object": "_BatchCollection",
|
|
71
|
+
"method": "add_object",
|
|
72
|
+
"span_name": "db.weaviate.collections.batch.add_object",
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"module": "weaviate.collections.grpc.query",
|
|
76
|
+
"object": "_QueryGRPC",
|
|
77
|
+
"method": "get",
|
|
78
|
+
"span_name": "db.weaviate.collections.query.get",
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"module": "weaviate.client",
|
|
82
|
+
"object": "WeaviateClient",
|
|
83
|
+
"method": "graphql_raw_query",
|
|
84
|
+
"span_name": "db.weaviate.client.graphql_raw_query",
|
|
85
|
+
},
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class WeaviateInstrumentor(BaseInstrumentor): # type: ignore[misc]
|
|
90
|
+
"""An instrumentor for Weaviate's client library."""
|
|
91
|
+
|
|
92
|
+
def __init__(self, exception_logger: Optional[logging.Logger] = None):
|
|
93
|
+
super().__init__()
|
|
94
|
+
Config.exception_logger = exception_logger
|
|
95
|
+
|
|
96
|
+
def instrumentation_dependencies(self) -> Collection[str]:
|
|
97
|
+
return _instruments
|
|
98
|
+
|
|
99
|
+
def _instrument(self, **kwargs): # type: ignore[no-untyped-def]
|
|
100
|
+
tracer_provider = kwargs.get("tracer_provider")
|
|
101
|
+
tracer = get_tracer(__name__, __version__, tracer_provider)
|
|
102
|
+
for wrapped_method in WRAPPED_METHODS:
|
|
103
|
+
wrap_module = wrapped_method.get("module")
|
|
104
|
+
wrap_object = wrapped_method.get("object")
|
|
105
|
+
wrap_method = wrapped_method.get("method")
|
|
106
|
+
module = importlib.import_module(wrap_module) # type: ignore[arg-type]
|
|
107
|
+
if getattr(module, wrap_object, None): # type: ignore[arg-type]
|
|
108
|
+
wrap_function_wrapper(
|
|
109
|
+
wrap_module,
|
|
110
|
+
f"{wrap_object}.{wrap_method}",
|
|
111
|
+
_wrap(tracer, wrapped_method),
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
def _uninstrument(self, **kwargs): # type: ignore[no-untyped-def]
|
|
115
|
+
for wrapped_method in WRAPPED_METHODS:
|
|
116
|
+
wrap_module = wrapped_method.get("module")
|
|
117
|
+
wrap_object = wrapped_method.get("object")
|
|
118
|
+
module = importlib.import_module(wrap_module) # type: ignore[arg-type]
|
|
119
|
+
wrapped = getattr(module, wrap_object, None) # type: ignore[arg-type]
|
|
120
|
+
if wrapped:
|
|
121
|
+
unwrap(wrapped, wrapped_method.get("method"))
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = " 4.15.3"
|