netra-sdk 0.1.31__py3-none-any.whl → 0.1.34__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 +5 -1
- netra/config.py +16 -1
- netra/processors/__init__.py +2 -1
- netra/processors/scrubbing_span_processor.py +178 -0
- netra/span_wrapper.py +15 -20
- netra/tracer.py +107 -3
- netra/version.py +1 -1
- {netra_sdk-0.1.31.dist-info → netra_sdk-0.1.34.dist-info}/METADATA +2 -2
- {netra_sdk-0.1.31.dist-info → netra_sdk-0.1.34.dist-info}/RECORD +11 -10
- {netra_sdk-0.1.31.dist-info → netra_sdk-0.1.34.dist-info}/LICENCE +0 -0
- {netra_sdk-0.1.31.dist-info → netra_sdk-0.1.34.dist-info}/WHEEL +0 -0
netra/__init__.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import atexit
|
|
2
2
|
import logging
|
|
3
3
|
import threading
|
|
4
|
-
from typing import Any, Dict, Optional, Set
|
|
4
|
+
from typing import Any, Dict, List, Optional, Set
|
|
5
5
|
|
|
6
6
|
from opentelemetry import context as context_api
|
|
7
7
|
from opentelemetry import trace
|
|
@@ -56,6 +56,8 @@ class Netra:
|
|
|
56
56
|
enable_root_span: Optional[bool] = None,
|
|
57
57
|
resource_attributes: Optional[Dict[str, Any]] = None,
|
|
58
58
|
environment: Optional[str] = None,
|
|
59
|
+
enable_scrubbing: Optional[bool] = None,
|
|
60
|
+
blocked_spans: Optional[List[str]] = None,
|
|
59
61
|
instruments: Optional[Set[NetraInstruments]] = None,
|
|
60
62
|
block_instruments: Optional[Set[NetraInstruments]] = None,
|
|
61
63
|
) -> None:
|
|
@@ -77,6 +79,8 @@ class Netra:
|
|
|
77
79
|
enable_root_span=enable_root_span,
|
|
78
80
|
resource_attributes=resource_attributes,
|
|
79
81
|
environment=environment,
|
|
82
|
+
enable_scrubbing=enable_scrubbing,
|
|
83
|
+
blocked_spans=blocked_spans,
|
|
80
84
|
)
|
|
81
85
|
|
|
82
86
|
# Configure package logging based on debug mode
|
netra/config.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import os
|
|
3
|
-
from typing import Any, Dict, Optional
|
|
3
|
+
from typing import Any, Dict, List, Optional
|
|
4
4
|
|
|
5
5
|
from opentelemetry.util.re import parse_env_headers
|
|
6
6
|
|
|
@@ -19,6 +19,8 @@ class Config:
|
|
|
19
19
|
- debug_mode: Whether to enable SDK logging; default False (bool)
|
|
20
20
|
- enable_root_span: Whether to create a process root span; default False (bool)
|
|
21
21
|
- resource_attributes: Custom resource attributes dict (e.g., {'env': 'prod', 'version': '1.0.0'})
|
|
22
|
+
- enable_scrubbing: Whether to enable pydantic logfire scrubbing; default False (bool)
|
|
23
|
+
- blocked_spans: List of span names (prefix/suffix patterns) to block from being exported to the tracing backend
|
|
22
24
|
"""
|
|
23
25
|
|
|
24
26
|
# SDK Constants
|
|
@@ -38,6 +40,8 @@ class Config:
|
|
|
38
40
|
enable_root_span: Optional[bool] = None,
|
|
39
41
|
resource_attributes: Optional[Dict[str, Any]] = None,
|
|
40
42
|
environment: Optional[str] = None,
|
|
43
|
+
enable_scrubbing: Optional[bool] = None,
|
|
44
|
+
blocked_spans: Optional[List[str]] = None,
|
|
41
45
|
):
|
|
42
46
|
# Application name: from param, else env
|
|
43
47
|
self.app_name = (
|
|
@@ -134,3 +138,14 @@ class Config:
|
|
|
134
138
|
self.resource_attributes = {}
|
|
135
139
|
else:
|
|
136
140
|
self.resource_attributes = {}
|
|
141
|
+
|
|
142
|
+
# Enable scrubbing with pydantic logfire? Default False.
|
|
143
|
+
if enable_scrubbing is not None:
|
|
144
|
+
self.enable_scrubbing = enable_scrubbing
|
|
145
|
+
else:
|
|
146
|
+
env_scrub = os.getenv("NETRA_ENABLE_SCRUBBING")
|
|
147
|
+
self.enable_scrubbing = True if (env_scrub is not None and env_scrub.lower() in ("1", "true")) else False
|
|
148
|
+
|
|
149
|
+
# Blocked span names/prefix patterns
|
|
150
|
+
if blocked_spans is not None:
|
|
151
|
+
self.blocked_spans = blocked_spans
|
netra/processors/__init__.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from netra.processors.instrumentation_span_processor import InstrumentationSpanProcessor
|
|
2
|
+
from netra.processors.scrubbing_span_processor import ScrubbingSpanProcessor
|
|
2
3
|
from netra.processors.session_span_processor import SessionSpanProcessor
|
|
3
4
|
|
|
4
|
-
__all__ = ["SessionSpanProcessor", "InstrumentationSpanProcessor"]
|
|
5
|
+
__all__ = ["SessionSpanProcessor", "InstrumentationSpanProcessor", "ScrubbingSpanProcessor"]
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import re
|
|
3
|
+
from typing import Any, Dict, Optional, Union
|
|
4
|
+
|
|
5
|
+
from opentelemetry import context as otel_context
|
|
6
|
+
from opentelemetry import trace
|
|
7
|
+
from opentelemetry.sdk.trace import SpanProcessor
|
|
8
|
+
|
|
9
|
+
logger = logging.getLogger(__name__)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ScrubbingSpanProcessor(SpanProcessor): # type: ignore[misc]
|
|
13
|
+
"""OpenTelemetry span processor that scrubs sensitive data from span attributes using pydantic logfire patterns."""
|
|
14
|
+
|
|
15
|
+
# Common patterns for sensitive data detection (based on pydantic logfire scrubbing)
|
|
16
|
+
SENSITIVE_PATTERNS = {
|
|
17
|
+
# API keys first to avoid other patterns interfering
|
|
18
|
+
"api_key": re.compile(
|
|
19
|
+
r"(?:Token:\s*\S{32,})" # scrub entire "Token: <value>" where value is 32+ non-space
|
|
20
|
+
r"|(?:sk-[A-Za-z0-9]{16,})" # scrub only the sk-... token (keep labels like "API Key:")
|
|
21
|
+
),
|
|
22
|
+
"email": re.compile(r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b", re.IGNORECASE),
|
|
23
|
+
"phone": re.compile(r"(?:\+?1[-.\s]?)?\(?[0-9]{3}\)?[-.\s]?[0-9]{3}[-.\s]?[0-9]{4}"),
|
|
24
|
+
# Run credit card BEFORE SSN to avoid SSN partially matching inside card numbers
|
|
25
|
+
"credit_card": re.compile(r"(?<!\d)(?:4\d{15}|5[1-5]\d{14}|3[47]\d{13}|6(?:011|5\d{2})\d{12})(?!\d)"),
|
|
26
|
+
"ssn": re.compile(r"\b\d{3}-?\d{2}-?\d{4}\b"),
|
|
27
|
+
"password": re.compile(r"(?i)(?:password|passwd|pwd|secret|token)\s*[:=]\s*\S+"),
|
|
28
|
+
"bearer_token": re.compile(r"(?i)(?:authorization:\s*)?bearer\s+[A-Za-z0-9\-._~+/]+=*"),
|
|
29
|
+
"authorization": re.compile(r"(?i)authorization\s*:\s*\S+"),
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
# Sensitive attribute keys that should be scrubbed
|
|
33
|
+
SENSITIVE_KEYS = {
|
|
34
|
+
"password",
|
|
35
|
+
"passwd",
|
|
36
|
+
"pwd",
|
|
37
|
+
"secret",
|
|
38
|
+
"token",
|
|
39
|
+
"key",
|
|
40
|
+
"api_key",
|
|
41
|
+
"auth",
|
|
42
|
+
"authorization",
|
|
43
|
+
"bearer",
|
|
44
|
+
"credential",
|
|
45
|
+
"private_key",
|
|
46
|
+
"access_token",
|
|
47
|
+
"refresh_token",
|
|
48
|
+
"session_token",
|
|
49
|
+
"x-api-key",
|
|
50
|
+
"x-auth-token",
|
|
51
|
+
"cookie",
|
|
52
|
+
"set-cookie",
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
def __init__(self): # type: ignore[no-untyped-def]
|
|
56
|
+
"""Initialize the scrubbing span processor."""
|
|
57
|
+
self.scrub_replacement = "[SCRUBBED]"
|
|
58
|
+
|
|
59
|
+
def on_start(self, span: trace.Span, parent_context: Optional[otel_context.Context] = None) -> None:
|
|
60
|
+
"""Process span when it starts - no scrubbing needed here."""
|
|
61
|
+
|
|
62
|
+
def on_end(self, span: trace.Span) -> None:
|
|
63
|
+
"""Scrub sensitive data from span attributes when span ends."""
|
|
64
|
+
try:
|
|
65
|
+
# Get span attributes
|
|
66
|
+
if hasattr(span, "_attributes") and span._attributes:
|
|
67
|
+
scrubbed_attributes = {}
|
|
68
|
+
for key, value in span._attributes.items():
|
|
69
|
+
scrubbed_key, scrubbed_value = self._scrub_key_value(key, value)
|
|
70
|
+
scrubbed_attributes[scrubbed_key] = scrubbed_value
|
|
71
|
+
|
|
72
|
+
# Replace the attributes with scrubbed versions
|
|
73
|
+
span._attributes = scrubbed_attributes
|
|
74
|
+
|
|
75
|
+
except Exception as e:
|
|
76
|
+
logger.exception(f"Error scrubbing span attributes: {e}")
|
|
77
|
+
|
|
78
|
+
def _scrub_key_value(self, key: str, value: Any) -> tuple[str, Any]:
|
|
79
|
+
"""Scrub sensitive data from a key-value pair.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
key: The attribute key
|
|
83
|
+
value: The attribute value
|
|
84
|
+
|
|
85
|
+
Returns:
|
|
86
|
+
Tuple of (scrubbed_key, scrubbed_value)
|
|
87
|
+
"""
|
|
88
|
+
# Check if key itself is sensitive and value is a simple type (string, number, etc.)
|
|
89
|
+
if self._is_sensitive_key(key) and not isinstance(value, (dict, list, tuple)):
|
|
90
|
+
return key, self.scrub_replacement
|
|
91
|
+
|
|
92
|
+
# Scrub value based on its type
|
|
93
|
+
if isinstance(value, str):
|
|
94
|
+
scrubbed_value = self._scrub_string_value(value)
|
|
95
|
+
return key, scrubbed_value
|
|
96
|
+
elif isinstance(value, dict):
|
|
97
|
+
return key, self._scrub_dict_value(value)
|
|
98
|
+
elif isinstance(value, (list, tuple)):
|
|
99
|
+
return key, self._scrub_list_value(value)
|
|
100
|
+
|
|
101
|
+
return key, value
|
|
102
|
+
|
|
103
|
+
def _is_sensitive_key(self, key: str) -> bool:
|
|
104
|
+
"""Check if a key is considered sensitive.
|
|
105
|
+
|
|
106
|
+
Args:
|
|
107
|
+
key: The key to check
|
|
108
|
+
|
|
109
|
+
Returns:
|
|
110
|
+
True if the key is sensitive, False otherwise
|
|
111
|
+
"""
|
|
112
|
+
key_lower = key.lower()
|
|
113
|
+
return any(sensitive_key in key_lower for sensitive_key in self.SENSITIVE_KEYS)
|
|
114
|
+
|
|
115
|
+
def _scrub_string_value(self, value: str) -> str:
|
|
116
|
+
"""Scrub sensitive patterns from a string value.
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
value: The string value to scrub
|
|
120
|
+
|
|
121
|
+
Returns:
|
|
122
|
+
The scrubbed string value
|
|
123
|
+
"""
|
|
124
|
+
scrubbed_value = value
|
|
125
|
+
|
|
126
|
+
# Early catch-all for contiguous 13-19 digit sequences (credit/debit cards)
|
|
127
|
+
scrubbed_value = re.sub(r"(?<!\d)\d{13,19}(?!\d)", self.scrub_replacement, scrubbed_value)
|
|
128
|
+
|
|
129
|
+
for pattern_name, pattern in self.SENSITIVE_PATTERNS.items():
|
|
130
|
+
if pattern.search(scrubbed_value):
|
|
131
|
+
scrubbed_value = pattern.sub(self.scrub_replacement, scrubbed_value)
|
|
132
|
+
|
|
133
|
+
# No extra fallback required now that we pre-scrub 13-19 digit sequences
|
|
134
|
+
|
|
135
|
+
return scrubbed_value
|
|
136
|
+
|
|
137
|
+
def _scrub_dict_value(self, value: Dict[str, Any]) -> Dict[str, Any]:
|
|
138
|
+
"""Recursively scrub sensitive data from a dictionary value.
|
|
139
|
+
|
|
140
|
+
Args:
|
|
141
|
+
value: The dictionary value to scrub
|
|
142
|
+
|
|
143
|
+
Returns:
|
|
144
|
+
The scrubbed dictionary value
|
|
145
|
+
"""
|
|
146
|
+
scrubbed_dict = {}
|
|
147
|
+
for k, v in value.items():
|
|
148
|
+
scrubbed_k, scrubbed_v = self._scrub_key_value(k, v)
|
|
149
|
+
scrubbed_dict[scrubbed_k] = scrubbed_v
|
|
150
|
+
return scrubbed_dict
|
|
151
|
+
|
|
152
|
+
def _scrub_list_value(self, value: Union[list, tuple]) -> Union[list, tuple] | None: # type: ignore[type-arg]
|
|
153
|
+
"""Recursively scrub sensitive data from a list/tuple value.
|
|
154
|
+
|
|
155
|
+
Args:
|
|
156
|
+
value: The list/tuple value to scrub
|
|
157
|
+
|
|
158
|
+
Returns:
|
|
159
|
+
The scrubbed list/tuple value
|
|
160
|
+
"""
|
|
161
|
+
scrubbed_items = []
|
|
162
|
+
for item in value:
|
|
163
|
+
if isinstance(item, str):
|
|
164
|
+
scrubbed_items.append(self._scrub_string_value(item))
|
|
165
|
+
elif isinstance(item, dict):
|
|
166
|
+
scrubbed_items.append(self._scrub_dict_value(item)) # type: ignore[arg-type]
|
|
167
|
+
elif isinstance(item, (list, tuple)):
|
|
168
|
+
scrubbed_items.append(self._scrub_list_value(item)) # type: ignore[arg-type]
|
|
169
|
+
else:
|
|
170
|
+
scrubbed_items.append(item)
|
|
171
|
+
|
|
172
|
+
return type(value)(scrubbed_items)
|
|
173
|
+
|
|
174
|
+
def force_flush(self, timeout_millis: int = 30000) -> None:
|
|
175
|
+
"""Force flush - no-op for scrubbing processor."""
|
|
176
|
+
|
|
177
|
+
def shutdown(self) -> None:
|
|
178
|
+
"""Shutdown - no-op for scrubbing processor."""
|
netra/span_wrapper.py
CHANGED
|
@@ -4,10 +4,8 @@ import time
|
|
|
4
4
|
from datetime import datetime
|
|
5
5
|
from typing import Any, Dict, List, Literal, Optional
|
|
6
6
|
|
|
7
|
-
from opentelemetry import context as context_api
|
|
8
7
|
from opentelemetry import trace
|
|
9
8
|
from opentelemetry.trace import SpanKind, Status, StatusCode
|
|
10
|
-
from opentelemetry.trace.propagation import set_span_in_context
|
|
11
9
|
from pydantic import BaseModel
|
|
12
10
|
|
|
13
11
|
from netra.config import Config
|
|
@@ -72,18 +70,19 @@ class SpanWrapper:
|
|
|
72
70
|
# OpenTelemetry span management
|
|
73
71
|
self.tracer = trace.get_tracer(module_name)
|
|
74
72
|
self.span: Optional[trace.Span] = None
|
|
75
|
-
|
|
73
|
+
# Internal context manager to manage current-span scope safely
|
|
74
|
+
self._span_cm: Optional[Any] = None
|
|
76
75
|
|
|
77
76
|
def __enter__(self) -> "SpanWrapper":
|
|
78
77
|
"""Start the span wrapper, begin time tracking, and create OpenTelemetry span."""
|
|
79
78
|
self.start_time = time.time()
|
|
80
79
|
|
|
81
|
-
# Create OpenTelemetry span
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
self.
|
|
80
|
+
# Create OpenTelemetry span and make it current using OTel's context manager
|
|
81
|
+
# Store the context manager so we can close it in __exit__
|
|
82
|
+
self._span_cm = self.tracer.start_as_current_span(
|
|
83
|
+
name=self.name, kind=SpanKind.CLIENT, attributes=self.attributes
|
|
84
|
+
)
|
|
85
|
+
self.span = self._span_cm.__enter__()
|
|
87
86
|
|
|
88
87
|
# Register with SessionManager for name-based lookup
|
|
89
88
|
try:
|
|
@@ -93,7 +92,6 @@ class SpanWrapper:
|
|
|
93
92
|
except Exception:
|
|
94
93
|
logger.exception("Failed to register span '%s' with SessionManager", self.name)
|
|
95
94
|
|
|
96
|
-
logger.info(f"Started span wrapper: {self.name}")
|
|
97
95
|
return self
|
|
98
96
|
|
|
99
97
|
def __exit__(self, exc_type: Optional[type], exc_val: Optional[Exception], exc_tb: Any) -> Literal[False]:
|
|
@@ -127,22 +125,19 @@ class SpanWrapper:
|
|
|
127
125
|
for key, value in self.attributes.items():
|
|
128
126
|
self.span.set_attribute(key, value)
|
|
129
127
|
|
|
130
|
-
# End OpenTelemetry span
|
|
128
|
+
# End OpenTelemetry span via the context manager (also clears current context)
|
|
131
129
|
if self.span:
|
|
132
130
|
# Unregister from SessionManager before ending span
|
|
133
131
|
try:
|
|
134
132
|
SessionManager.unregister_span(self.name, self.span)
|
|
135
133
|
except Exception:
|
|
136
134
|
logger.exception("Failed to unregister span '%s' from SessionManager", self.name)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
if duration_ms is not None
|
|
144
|
-
else f"Ended span wrapper: {self.name} (Status: {self.status})"
|
|
145
|
-
)
|
|
135
|
+
if self._span_cm is not None:
|
|
136
|
+
try:
|
|
137
|
+
# Delegate to OTel CM to properly end span and restore context
|
|
138
|
+
self._span_cm.__exit__(exc_type, exc_val, exc_tb)
|
|
139
|
+
finally:
|
|
140
|
+
self._span_cm = None
|
|
146
141
|
|
|
147
142
|
# Don't suppress exceptions
|
|
148
143
|
return False
|
netra/tracer.py
CHANGED
|
@@ -5,16 +5,18 @@ including exporter setup and span processor configuration.
|
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
7
|
import logging
|
|
8
|
-
from typing import Any, Dict
|
|
8
|
+
from typing import Any, Dict, List, Sequence
|
|
9
9
|
|
|
10
10
|
from opentelemetry import trace
|
|
11
11
|
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
|
|
12
12
|
from opentelemetry.sdk.resources import DEPLOYMENT_ENVIRONMENT, SERVICE_NAME, Resource
|
|
13
|
-
from opentelemetry.sdk.trace import TracerProvider
|
|
13
|
+
from opentelemetry.sdk.trace import ReadableSpan, TracerProvider
|
|
14
14
|
from opentelemetry.sdk.trace.export import (
|
|
15
15
|
BatchSpanProcessor,
|
|
16
16
|
ConsoleSpanExporter,
|
|
17
17
|
SimpleSpanProcessor,
|
|
18
|
+
SpanExporter,
|
|
19
|
+
SpanExportResult,
|
|
18
20
|
)
|
|
19
21
|
|
|
20
22
|
from netra.config import Config
|
|
@@ -22,6 +24,96 @@ from netra.config import Config
|
|
|
22
24
|
logger = logging.getLogger(__name__)
|
|
23
25
|
|
|
24
26
|
|
|
27
|
+
class FilteringSpanExporter(SpanExporter): # type: ignore[misc]
|
|
28
|
+
"""
|
|
29
|
+
SpanExporter wrapper that filters out spans by name.
|
|
30
|
+
|
|
31
|
+
Matching rules:
|
|
32
|
+
- Exact match: pattern "Foo" blocks span.name == "Foo".
|
|
33
|
+
- Prefix match: pattern ending with '*' (e.g., "CloudSpanner.*") blocks spans whose
|
|
34
|
+
names start with the prefix before '*', e.g., "CloudSpanner.", "CloudSpanner.Query".
|
|
35
|
+
- Suffix match: pattern starting with '*' (e.g., "*.Query") blocks spans whose
|
|
36
|
+
names end with the suffix after '*', e.g., "DB.Query", "Search.Query".
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
def __init__(self, exporter: SpanExporter, patterns: Sequence[str]) -> None:
|
|
40
|
+
self._exporter = exporter
|
|
41
|
+
# Normalize once for efficient checks
|
|
42
|
+
exact: List[str] = []
|
|
43
|
+
prefixes: List[str] = []
|
|
44
|
+
suffixes: List[str] = []
|
|
45
|
+
for p in patterns:
|
|
46
|
+
if not p:
|
|
47
|
+
continue
|
|
48
|
+
if p.endswith("*") and not p.startswith("*"):
|
|
49
|
+
prefixes.append(p[:-1])
|
|
50
|
+
elif p.startswith("*") and not p.endswith("*"):
|
|
51
|
+
suffixes.append(p[1:])
|
|
52
|
+
else:
|
|
53
|
+
exact.append(p)
|
|
54
|
+
self._exact = set(exact)
|
|
55
|
+
self._prefixes = prefixes
|
|
56
|
+
self._suffixes = suffixes
|
|
57
|
+
|
|
58
|
+
def export(self, spans: Sequence[ReadableSpan]) -> SpanExportResult:
|
|
59
|
+
filtered: List[ReadableSpan] = []
|
|
60
|
+
for s in spans:
|
|
61
|
+
name = getattr(s, "name", None)
|
|
62
|
+
if name is None:
|
|
63
|
+
filtered.append(s)
|
|
64
|
+
continue
|
|
65
|
+
# Only apply blocked span patterns to root-level spans (no valid parent)
|
|
66
|
+
parent = getattr(s, "parent", None)
|
|
67
|
+
# Determine if the span has a valid parent. SpanContext.is_valid may be a property or method.
|
|
68
|
+
has_valid_parent = False
|
|
69
|
+
if parent is not None:
|
|
70
|
+
is_valid_attr = getattr(parent, "is_valid", None)
|
|
71
|
+
if callable(is_valid_attr):
|
|
72
|
+
try:
|
|
73
|
+
has_valid_parent = bool(is_valid_attr())
|
|
74
|
+
except Exception:
|
|
75
|
+
has_valid_parent = False
|
|
76
|
+
else:
|
|
77
|
+
has_valid_parent = bool(is_valid_attr)
|
|
78
|
+
|
|
79
|
+
is_root_span = parent is None or not has_valid_parent
|
|
80
|
+
|
|
81
|
+
if is_root_span:
|
|
82
|
+
# Apply name-based blocking only for root spans
|
|
83
|
+
if name in self._exact:
|
|
84
|
+
continue
|
|
85
|
+
blocked = False
|
|
86
|
+
for pref in self._prefixes:
|
|
87
|
+
if name.startswith(pref):
|
|
88
|
+
blocked = True
|
|
89
|
+
break
|
|
90
|
+
if not blocked and self._suffixes:
|
|
91
|
+
for suf in self._suffixes:
|
|
92
|
+
if name.endswith(suf):
|
|
93
|
+
blocked = True
|
|
94
|
+
break
|
|
95
|
+
if not blocked:
|
|
96
|
+
filtered.append(s)
|
|
97
|
+
else:
|
|
98
|
+
# Do not block child spans based on name
|
|
99
|
+
filtered.append(s)
|
|
100
|
+
if not filtered:
|
|
101
|
+
return SpanExportResult.SUCCESS
|
|
102
|
+
return self._exporter.export(filtered)
|
|
103
|
+
|
|
104
|
+
def shutdown(self) -> None:
|
|
105
|
+
try:
|
|
106
|
+
self._exporter.shutdown()
|
|
107
|
+
except Exception:
|
|
108
|
+
pass
|
|
109
|
+
|
|
110
|
+
def force_flush(self, timeout_millis: int = 30000) -> Any:
|
|
111
|
+
try:
|
|
112
|
+
return self._exporter.force_flush(timeout_millis)
|
|
113
|
+
except Exception:
|
|
114
|
+
return True
|
|
115
|
+
|
|
116
|
+
|
|
25
117
|
class Tracer:
|
|
26
118
|
"""
|
|
27
119
|
Configures Netra's OpenTelemetry tracer with OTLP exporter (or Console exporter as fallback)
|
|
@@ -65,12 +157,24 @@ class Tracer:
|
|
|
65
157
|
endpoint=self._format_endpoint(self.cfg.otlp_endpoint),
|
|
66
158
|
headers=self.cfg.headers,
|
|
67
159
|
)
|
|
160
|
+
# Wrap exporter with filtering if blocked span patterns are provided
|
|
161
|
+
try:
|
|
162
|
+
patterns = getattr(self.cfg, "blocked_spans", None)
|
|
163
|
+
if patterns:
|
|
164
|
+
exporter = FilteringSpanExporter(exporter, patterns)
|
|
165
|
+
logger.info("Enabled FilteringSpanExporter with %d pattern(s)", len(patterns))
|
|
166
|
+
except Exception as e:
|
|
167
|
+
logger.warning("Failed to enable FilteringSpanExporter: %s", e)
|
|
68
168
|
# Add span processors: first instrumentation wrapper, then session processor
|
|
69
|
-
from netra.processors import InstrumentationSpanProcessor, SessionSpanProcessor
|
|
169
|
+
from netra.processors import InstrumentationSpanProcessor, ScrubbingSpanProcessor, SessionSpanProcessor
|
|
70
170
|
|
|
71
171
|
provider.add_span_processor(InstrumentationSpanProcessor())
|
|
72
172
|
provider.add_span_processor(SessionSpanProcessor())
|
|
73
173
|
|
|
174
|
+
# Add scrubbing processor if enabled
|
|
175
|
+
if self.cfg.enable_scrubbing:
|
|
176
|
+
provider.add_span_processor(ScrubbingSpanProcessor()) # type: ignore[no-untyped-call]
|
|
177
|
+
|
|
74
178
|
# Install appropriate span processor
|
|
75
179
|
if self.cfg.disable_batch:
|
|
76
180
|
provider.add_span_processor(SimpleSpanProcessor(exporter))
|
netra/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.1.
|
|
1
|
+
__version__ = "0.1.34"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: netra-sdk
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.34
|
|
4
4
|
Summary: A Python SDK for AI application observability that provides OpenTelemetry-based monitoring, tracing, and PII protection for LLM and vector database applications. Enables easy instrumentation, session tracking, and privacy-focused data collection for AI systems in production environments.
|
|
5
5
|
License: Apache-2.0
|
|
6
6
|
Keywords: netra,tracing,observability,sdk,ai,llm,vector,database
|
|
@@ -72,7 +72,7 @@ Requires-Dist: presidio-anonymizer (==2.2.358) ; extra == "presidio"
|
|
|
72
72
|
Requires-Dist: stanza (>=1.10.1,<2.0.0) ; extra == "presidio"
|
|
73
73
|
Requires-Dist: traceloop-sdk (>=0.40.7,<0.43.0)
|
|
74
74
|
Requires-Dist: transformers (==4.51.3) ; extra == "presidio"
|
|
75
|
-
Project-URL:
|
|
75
|
+
Project-URL: Changelog, https://github.com/KeyValueSoftwareSystems/netra-sdk-py/blob/main/CHANGELOG.md
|
|
76
76
|
Project-URL: Documentation, https://github.com/KeyValueSoftwareSystems/netra-sdk-py/blob/main/README.md
|
|
77
77
|
Project-URL: Homepage, https://github.com/KeyValueSoftwareSystems/netra-sdk-py
|
|
78
78
|
Project-URL: Repository, https://github.com/KeyValueSoftwareSystems/netra-sdk-py
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
netra/__init__.py,sha256=
|
|
1
|
+
netra/__init__.py,sha256=bBnv8InguoqBleHuA5KNU145eozdPOooxQrIMaKgJ5c,10942
|
|
2
2
|
netra/anonymizer/__init__.py,sha256=KeGPPZqKVZbtkbirEKYTYhj6aZHlakjdQhD7QHqBRio,133
|
|
3
3
|
netra/anonymizer/anonymizer.py,sha256=IcrYkdwWrFauGWUeAW-0RwrSUM8VSZCFNtoywZhvIqU,3778
|
|
4
4
|
netra/anonymizer/base.py,sha256=ytPxHCUD2OXlEY6fNTuMmwImNdIjgj294I41FIgoXpU,5946
|
|
5
5
|
netra/anonymizer/fp_anonymizer.py,sha256=_6svIYmE0eejdIMkhKBUWCNjGtGimtrGtbLvPSOp8W4,6493
|
|
6
|
-
netra/config.py,sha256
|
|
6
|
+
netra/config.py,sha256=51m8R0NoOrw58gMV7arOniEuFdJ7EIu3PNdFtIQ5xfg,6893
|
|
7
7
|
netra/decorators.py,sha256=yuQP02sdvTRIYkv-myNcP8q7dmPq3ME1AJZxJtryayI,8720
|
|
8
8
|
netra/exceptions/__init__.py,sha256=uDgcBxmC4WhdS7HRYQk_TtJyxH1s1o6wZmcsnSHLAcM,174
|
|
9
9
|
netra/exceptions/injection.py,sha256=ke4eUXRYUFJkMZgdSyPPkPt5PdxToTI6xLEBI0hTWUQ,1332
|
|
@@ -40,15 +40,16 @@ netra/instrumentation/pydantic_ai/wrappers.py,sha256=6cfIRvELBS4d9G9TttNYcHGueNI
|
|
|
40
40
|
netra/instrumentation/weaviate/__init__.py,sha256=EOlpWxobOLHYKqo_kMct_7nu26x1hr8qkeG5_h99wtg,4330
|
|
41
41
|
netra/instrumentation/weaviate/version.py,sha256=PiCZHjonujPbnIn0KmD3Yl68hrjPRG_oKe5vJF3mmG8,24
|
|
42
42
|
netra/pii.py,sha256=Rn4SjgTJW_aw9LcbjLuMqF3fKd9b1ndlYt1CaK51Ge0,33125
|
|
43
|
-
netra/processors/__init__.py,sha256=
|
|
43
|
+
netra/processors/__init__.py,sha256=TLVBKk4Bli7MOyHTy_F-4NSm0thzIcJcZAVVNoq6gK8,333
|
|
44
44
|
netra/processors/instrumentation_span_processor.py,sha256=Ef5FTr8O5FLHcIkBAW3ueU1nlkV2DuOi-y5iIwHzldQ,4252
|
|
45
|
+
netra/processors/scrubbing_span_processor.py,sha256=dJ86Ncmjvmrhm_uAdGTwcGvRpZbVVWqD9AOFwEMWHZY,6701
|
|
45
46
|
netra/processors/session_span_processor.py,sha256=qcsBl-LnILWefsftI8NQhXDGb94OWPc8LvzhVA0JS_c,2432
|
|
46
47
|
netra/scanner.py,sha256=kyDpeZiscCPb6pjuhS-sfsVj-dviBFRepdUWh0sLoEY,11554
|
|
47
48
|
netra/session_manager.py,sha256=AoQa-k4dFcq7PeOD8G8DNzhLzL1JrHUW6b_y8mRyTQo,10255
|
|
48
|
-
netra/span_wrapper.py,sha256=
|
|
49
|
-
netra/tracer.py,sha256=
|
|
50
|
-
netra/version.py,sha256=
|
|
51
|
-
netra_sdk-0.1.
|
|
52
|
-
netra_sdk-0.1.
|
|
53
|
-
netra_sdk-0.1.
|
|
54
|
-
netra_sdk-0.1.
|
|
49
|
+
netra/span_wrapper.py,sha256=IygQX78xQRlL_Z1MfKfUbv0okihx92qNClnRlYFtRNc,8004
|
|
50
|
+
netra/tracer.py,sha256=FJO8Cine-WL9K_4wn6RVjQOgX6c1JCp_8QowUbRSVHk,7718
|
|
51
|
+
netra/version.py,sha256=79r5jd-MqbhXLbIBDVBqUJvhvcucjkaId96r46KF18I,23
|
|
52
|
+
netra_sdk-0.1.34.dist-info/LICENCE,sha256=8B_UoZ-BAl0AqiHAHUETCgd3I2B9yYJ1WEQtVb_qFMA,11359
|
|
53
|
+
netra_sdk-0.1.34.dist-info/METADATA,sha256=Wmf0VwjOEEmgtJcNuhmsFlgDlAT2e9RxXbY73TQl-CU,28210
|
|
54
|
+
netra_sdk-0.1.34.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
55
|
+
netra_sdk-0.1.34.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|