netra-sdk 0.1.0__tar.gz → 0.1.1__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 netra-sdk might be problematic. Click here for more details.
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/LICENCE +1 -1
- netra_sdk-0.1.0/README.md → netra_sdk-0.1.1/PKG-INFO +198 -29
- netra_sdk-0.1.0/PKG-INFO → netra_sdk-0.1.1/README.md +118 -64
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/config.py +1 -1
- netra_sdk-0.1.1/netra/instrumentation/__init__.py +1155 -0
- netra_sdk-0.1.1/netra/instrumentation/instruments.py +170 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/session.py +49 -17
- netra_sdk-0.1.1/netra/version.py +1 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/pyproject.toml +46 -1
- netra_sdk-0.1.0/netra/instrumentation/__init__.py +0 -257
- netra_sdk-0.1.0/netra/instrumentation/instruments.py +0 -78
- netra_sdk-0.1.0/netra/version.py +0 -1
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/__init__.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/anonymizer/__init__.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/anonymizer/anonymizer.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/anonymizer/base.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/anonymizer/fp_anonymizer.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/decorators.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/exceptions/__init__.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/exceptions/injection.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/exceptions/pii.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/input_scanner.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/instrumentation/aiohttp/__init__.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/instrumentation/aiohttp/version.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/instrumentation/cohere/__init__.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/instrumentation/cohere/version.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/instrumentation/google_genai/__init__.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/instrumentation/google_genai/config.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/instrumentation/google_genai/utils.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/instrumentation/google_genai/version.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/instrumentation/httpx/__init__.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/instrumentation/httpx/version.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/instrumentation/mistralai/__init__.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/instrumentation/mistralai/config.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/instrumentation/mistralai/utils.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/instrumentation/mistralai/version.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/instrumentation/weaviate/__init__.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/instrumentation/weaviate/version.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/pii.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/processors/__init__.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/processors/session_span_processor.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/processors/span_aggregation_processor.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/scanner.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/session_manager.py +0 -0
- {netra_sdk-0.1.0 → netra_sdk-0.1.1}/netra/tracer.py +0 -0
|
@@ -198,4 +198,4 @@
|
|
|
198
198
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
199
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
200
|
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
|
201
|
+
limitations under the License.
|
|
@@ -1,3 +1,82 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: netra-sdk
|
|
3
|
+
Version: 0.1.1
|
|
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
|
+
License: Apache-2.0
|
|
6
|
+
Keywords: netra,tracing,observability,sdk,ai,llm,vector,database
|
|
7
|
+
Author: Sooraj Thomas
|
|
8
|
+
Author-email: sooraj@keyvalue.systems
|
|
9
|
+
Requires-Python: >=3.10,<3.13
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Framework :: OpenTelemetry
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Provides-Extra: llm-guard
|
|
21
|
+
Requires-Dist: llm-guard (>=0.3.16,<0.4.0) ; extra == "llm-guard"
|
|
22
|
+
Requires-Dist: opentelemetry-api (>=1.34.0,<2.0.0)
|
|
23
|
+
Requires-Dist: opentelemetry-instrumentation-aio-pika (>=0.55b1,<1.0.0)
|
|
24
|
+
Requires-Dist: opentelemetry-instrumentation-aiohttp-client (>=0.55b1,<1.0.0)
|
|
25
|
+
Requires-Dist: opentelemetry-instrumentation-aiohttp-server (>=0.55b1,<1.0.0)
|
|
26
|
+
Requires-Dist: opentelemetry-instrumentation-aiokafka (>=0.55b1,<1.0.0)
|
|
27
|
+
Requires-Dist: opentelemetry-instrumentation-aiopg (>=0.55b1,<1.0.0)
|
|
28
|
+
Requires-Dist: opentelemetry-instrumentation-asyncclick (>=0.55b1,<1.0.0)
|
|
29
|
+
Requires-Dist: opentelemetry-instrumentation-asyncio (>=0.55b1,<1.0.0)
|
|
30
|
+
Requires-Dist: opentelemetry-instrumentation-asyncpg (>=0.55b1,<1.0.0)
|
|
31
|
+
Requires-Dist: opentelemetry-instrumentation-aws-lambda (>=0.55b1,<1.0.0)
|
|
32
|
+
Requires-Dist: opentelemetry-instrumentation-boto (>=0.55b1,<1.0.0)
|
|
33
|
+
Requires-Dist: opentelemetry-instrumentation-boto3sqs (>=0.55b1,<1.0.0)
|
|
34
|
+
Requires-Dist: opentelemetry-instrumentation-botocore (>=0.55b1,<1.0.0)
|
|
35
|
+
Requires-Dist: opentelemetry-instrumentation-cassandra (>=0.55b1,<1.0.0)
|
|
36
|
+
Requires-Dist: opentelemetry-instrumentation-celery (>=0.55b1,<1.0.0)
|
|
37
|
+
Requires-Dist: opentelemetry-instrumentation-click (>=0.55b1,<1.0.0)
|
|
38
|
+
Requires-Dist: opentelemetry-instrumentation-confluent-kafka (>=0.55b1,<1.0.0)
|
|
39
|
+
Requires-Dist: opentelemetry-instrumentation-django (>=0.55b1,<1.0.0)
|
|
40
|
+
Requires-Dist: opentelemetry-instrumentation-elasticsearch (>=0.55b1,<1.0.0)
|
|
41
|
+
Requires-Dist: opentelemetry-instrumentation-falcon (>=0.55b1,<1.0.0)
|
|
42
|
+
Requires-Dist: opentelemetry-instrumentation-fastapi (>=0.55b1,<1.0.0)
|
|
43
|
+
Requires-Dist: opentelemetry-instrumentation-flask (>=0.55b1,<1.0.0)
|
|
44
|
+
Requires-Dist: opentelemetry-instrumentation-grpc (>=0.55b1,<1.0.0)
|
|
45
|
+
Requires-Dist: opentelemetry-instrumentation-httpx (>=0.55b1,<1.0.0)
|
|
46
|
+
Requires-Dist: opentelemetry-instrumentation-jinja2 (>=0.55b1,<1.0.0)
|
|
47
|
+
Requires-Dist: opentelemetry-instrumentation-kafka-python (>=0.55b1,<1.0.0)
|
|
48
|
+
Requires-Dist: opentelemetry-instrumentation-logging (>=0.55b1,<1.0.0)
|
|
49
|
+
Requires-Dist: opentelemetry-instrumentation-mysql (>=0.55b1,<1.0.0)
|
|
50
|
+
Requires-Dist: opentelemetry-instrumentation-mysqlclient (>=0.55b1,<1.0.0)
|
|
51
|
+
Requires-Dist: opentelemetry-instrumentation-pika (>=0.55b1,<1.0.0)
|
|
52
|
+
Requires-Dist: opentelemetry-instrumentation-psycopg (>=0.55b1,<1.0.0)
|
|
53
|
+
Requires-Dist: opentelemetry-instrumentation-psycopg2 (>=0.55b1,<1.0.0)
|
|
54
|
+
Requires-Dist: opentelemetry-instrumentation-pymemcache (>=0.55b1,<1.0.0)
|
|
55
|
+
Requires-Dist: opentelemetry-instrumentation-pymongo (>=0.55b1,<1.0.0)
|
|
56
|
+
Requires-Dist: opentelemetry-instrumentation-pymssql (>=0.55b1,<1.0.0)
|
|
57
|
+
Requires-Dist: opentelemetry-instrumentation-pymysql (>=0.55b1,<1.0.0)
|
|
58
|
+
Requires-Dist: opentelemetry-instrumentation-pyramid (>=0.55b1,<1.0.0)
|
|
59
|
+
Requires-Dist: opentelemetry-instrumentation-redis (>=0.55b1,<1.0.0)
|
|
60
|
+
Requires-Dist: opentelemetry-instrumentation-remoulade (>=0.55b1,<1.0.0)
|
|
61
|
+
Requires-Dist: opentelemetry-instrumentation-requests (>=0.55b1,<1.0.0)
|
|
62
|
+
Requires-Dist: opentelemetry-instrumentation-sqlalchemy (>=0.55b1,<1.0.0)
|
|
63
|
+
Requires-Dist: opentelemetry-instrumentation-sqlite3 (>=0.55b1,<1.0.0)
|
|
64
|
+
Requires-Dist: opentelemetry-instrumentation-starlette (>=0.55b1,<1.0.0)
|
|
65
|
+
Requires-Dist: opentelemetry-instrumentation-system-metrics (>=0.55b1,<1.0.0)
|
|
66
|
+
Requires-Dist: opentelemetry-instrumentation-threading (>=0.55b1,<1.0.0)
|
|
67
|
+
Requires-Dist: opentelemetry-instrumentation-tornado (>=0.55b1,<1.0.0)
|
|
68
|
+
Requires-Dist: opentelemetry-instrumentation-tortoiseorm (>=0.55b1,<1.0.0)
|
|
69
|
+
Requires-Dist: opentelemetry-instrumentation-urllib (>=0.55b1,<1.0.0)
|
|
70
|
+
Requires-Dist: opentelemetry-instrumentation-urllib3 (>=0.55b1,<1.0.0)
|
|
71
|
+
Requires-Dist: opentelemetry-sdk (>=1.34.0,<2.0.0)
|
|
72
|
+
Requires-Dist: presidio-analyzer (>=2.2.358,<3.0.0)
|
|
73
|
+
Requires-Dist: traceloop-sdk (>=0.40.7,<0.41.0)
|
|
74
|
+
Project-URL: Bug Tracker, https://github.com/KeyValueSoftwareSystems/netra-sdk-py/issues
|
|
75
|
+
Project-URL: Documentation, https://github.com/KeyValueSoftwareSystems/netra-sdk-py/blob/main/README.md
|
|
76
|
+
Project-URL: Homepage, https://github.com/KeyValueSoftwareSystems/netra-sdk-py
|
|
77
|
+
Project-URL: Repository, https://github.com/KeyValueSoftwareSystems/netra-sdk-py
|
|
78
|
+
Description-Content-Type: text/markdown
|
|
79
|
+
|
|
1
80
|
# Netra SDK
|
|
2
81
|
|
|
3
82
|
🚀 **Netra SDK** is a comprehensive Python library for AI application observability that provides OpenTelemetry-based monitoring, and tracing for LLM applications. It enables easy instrumentation, session tracking, and privacy-focused data analysis for AI systems.
|
|
@@ -146,16 +225,47 @@ class CustomerSupportAgent:
|
|
|
146
225
|
- **AIOHTTP** - Asynchronous HTTP client/server
|
|
147
226
|
- **FastAPI** - Modern web framework for APIs
|
|
148
227
|
- **Requests** - Popular HTTP library for Python
|
|
149
|
-
- **
|
|
228
|
+
- **Django** - High-level Python web framework
|
|
229
|
+
- **Flask** - Lightweight WSGI web application framework
|
|
230
|
+
- **Falcon** - High-performance Python web framework
|
|
231
|
+
- **Pyramid** - Small, fast, down-to-earth Python web framework
|
|
232
|
+
- **Starlette** - Lightweight ASGI framework/toolkit
|
|
233
|
+
- **Tornado** - Asynchronous networking library and web framework
|
|
234
|
+
- **gRPC** - High-performance, open-source universal RPC framework
|
|
235
|
+
- **Urllib** - Standard Python HTTP client library
|
|
236
|
+
- **Urllib3** - Powerful, user-friendly HTTP client for Python
|
|
150
237
|
|
|
151
238
|
### 🗄️ Database Clients
|
|
152
239
|
|
|
153
240
|
- **PyMySQL** - Pure Python MySQL client
|
|
154
241
|
- **Redis** - In-memory data structure store
|
|
242
|
+
- **SQLAlchemy** - SQL toolkit and Object-Relational Mapper
|
|
243
|
+
- **Psycopg** - Modern PostgreSQL database adapter for Python
|
|
244
|
+
- **Pymongo** - Python driver for MongoDB
|
|
245
|
+
- **Elasticsearch** - Distributed, RESTful search and analytics engine
|
|
246
|
+
- **Cassandra** - Distributed NoSQL database
|
|
247
|
+
- **PyMSSQL** - Simple Microsoft SQL Server client
|
|
248
|
+
- **MySQL Connector** - Official MySQL driver
|
|
249
|
+
- **Sqlite3** - Built-in SQL database engine
|
|
250
|
+
- **Aiopg** - Asynchronous PostgreSQL client
|
|
251
|
+
- **Asyncpg** - Fast asynchronous PostgreSQL client
|
|
252
|
+
- **Pymemcache** - Comprehensive Memcached client
|
|
253
|
+
- **Tortoise ORM** - Easy-to-use asyncio ORM
|
|
254
|
+
|
|
255
|
+
### 📨 Messaging & Task Queues
|
|
256
|
+
|
|
257
|
+
- **Celery** - Distributed task queue
|
|
258
|
+
- **Pika** - Pure-Python implementation of the AMQP 0-9-1 protocol
|
|
259
|
+
- **AIO Pika** - Asynchronous AMQP client
|
|
260
|
+
- **Kafka-Python** - Python client for Apache Kafka
|
|
261
|
+
- **AIOKafka** - Asynchronous Python client for Kafka
|
|
262
|
+
- **Confluent-Kafka** - Confluent's Python client for Apache Kafka
|
|
263
|
+
- **Boto3 SQS** - Amazon SQS client via Boto3
|
|
155
264
|
|
|
156
265
|
### 🔧 AI Frameworks & Orchestration
|
|
157
266
|
|
|
158
267
|
- **LangChain** - Framework for developing LLM applications
|
|
268
|
+
- **LangGraph** - Modern framework for LLM applications
|
|
159
269
|
- **LlamaIndex** - Data framework for LLM applications
|
|
160
270
|
- **Haystack** - End-to-end NLP framework
|
|
161
271
|
- **CrewAI** - Multi-agent AI systems
|
|
@@ -330,6 +440,72 @@ with Netra.start_session("video_generation_task") as session:
|
|
|
330
440
|
|
|
331
441
|
## 🔧 Advanced Configuration
|
|
332
442
|
|
|
443
|
+
### Environment Variables
|
|
444
|
+
|
|
445
|
+
Netra SDK can be configured using the following environment variables:
|
|
446
|
+
|
|
447
|
+
#### Netra-specific Variables
|
|
448
|
+
|
|
449
|
+
| Variable Name | Description | Default |
|
|
450
|
+
|---------------|-------------|---------|
|
|
451
|
+
| `NETRA_APP_NAME` | Logical name for your service | Falls back to `OTEL_SERVICE_NAME` or `llm_tracing_service` |
|
|
452
|
+
| `NETRA_OTLP_ENDPOINT` | URL for OTLP collector | Falls back to `OTEL_EXPORTER_OTLP_ENDPOINT` |
|
|
453
|
+
| `NETRA_API_KEY` | API key for authentication | `None` |
|
|
454
|
+
| `NETRA_HEADERS` | Additional headers in W3C Correlation-Context format | `None` |
|
|
455
|
+
| `NETRA_DISABLE_BATCH` | Disable batch span processor (`true`/`false`) | `false` |
|
|
456
|
+
| `NETRA_TRACE_CONTENT` | Whether to capture prompt/completion content (`true`/`false`) | `true` |
|
|
457
|
+
| `NETRA_ENV` | Deployment environment (e.g., `prod`, `staging`, `dev`) | `local` |
|
|
458
|
+
| `NETRA_RESOURCE_ATTRS` | JSON string of custom resource attributes | `{}` |
|
|
459
|
+
|
|
460
|
+
#### Standard OpenTelemetry Variables
|
|
461
|
+
|
|
462
|
+
| Variable Name | Description | Used When |
|
|
463
|
+
|---------------|-------------|-----------|
|
|
464
|
+
| `OTEL_SERVICE_NAME` | Logical name for your service | When `NETRA_APP_NAME` is not set |
|
|
465
|
+
| `OTEL_EXPORTER_OTLP_ENDPOINT` | URL for OTLP collector | When `NETRA_OTLP_ENDPOINT` is not set |
|
|
466
|
+
| `OTEL_EXPORTER_OTLP_HEADERS` | Additional headers for OTLP exporter | When `NETRA_HEADERS` is not set |
|
|
467
|
+
| `OTEL_RESOURCE_ATTRIBUTES` | Additional resource attributes | When `NETRA_RESOURCE_ATTRS` is not set |
|
|
468
|
+
|
|
469
|
+
### Configuration Precedence
|
|
470
|
+
|
|
471
|
+
Configuration values are resolved in the following order (highest to lowest precedence):
|
|
472
|
+
|
|
473
|
+
1. **Code Parameters**: Values passed directly to `Netra.init()`
|
|
474
|
+
2. **Netra Environment Variables**: `NETRA_*` variables
|
|
475
|
+
3. **OpenTelemetry Environment Variables**: Standard `OTEL_*` variables
|
|
476
|
+
4. **Default Values**: Fallback values defined in the SDK
|
|
477
|
+
|
|
478
|
+
This allows you to:
|
|
479
|
+
- Override any setting directly in code for maximum control
|
|
480
|
+
- Use Netra-specific environment variables for Netra-specific settings
|
|
481
|
+
- Fall back to standard OpenTelemetry variables for compatibility
|
|
482
|
+
- Rely on sensible defaults when no other configuration is provided
|
|
483
|
+
|
|
484
|
+
**Example**:
|
|
485
|
+
```bash
|
|
486
|
+
export NETRA_APP_NAME="my-ai-service"
|
|
487
|
+
export NETRA_OTLP_ENDPOINT="https://collector.example.com:4318"
|
|
488
|
+
export NETRA_API_KEY="your-api-key-here"
|
|
489
|
+
export NETRA_ENV="production"
|
|
490
|
+
export NETRA_RESOURCE_ATTRS='{"team":"ai", "version":"1.0.0"}'
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
### Programmatic Configuration
|
|
494
|
+
|
|
495
|
+
You can also configure the SDK programmatically when initializing:
|
|
496
|
+
|
|
497
|
+
```python
|
|
498
|
+
from netra import Netra
|
|
499
|
+
|
|
500
|
+
Netra.init(
|
|
501
|
+
app_name="my-ai-service",
|
|
502
|
+
environment="production",
|
|
503
|
+
resource_attributes={"team": "ai", "version": "1.0.0"},
|
|
504
|
+
trace_content=True,
|
|
505
|
+
disable_batch=False
|
|
506
|
+
)
|
|
507
|
+
```
|
|
508
|
+
|
|
333
509
|
### Custom Instrumentation Selection
|
|
334
510
|
|
|
335
511
|
Control which instrumentations are enabled:
|
|
@@ -400,6 +576,7 @@ Netra.init(app_name="Your App")
|
|
|
400
576
|
- **📈 Rich Ecosystem**: Leverage the entire OpenTelemetry ecosystem
|
|
401
577
|
|
|
402
578
|
|
|
579
|
+
|
|
403
580
|
## 📚 Examples
|
|
404
581
|
|
|
405
582
|
The SDK includes comprehensive examples in the `examples/` directory:
|
|
@@ -412,61 +589,52 @@ The SDK includes comprehensive examples in the `examples/` directory:
|
|
|
412
589
|
|
|
413
590
|
## 🧪 Tests
|
|
414
591
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
### Test Structure
|
|
418
|
-
|
|
419
|
-
- **conftest.py**: Contains shared fixtures, test utilities, and configuration for all tests
|
|
420
|
-
- **test_netra_init.py**: Tests for the main Netra SDK initialization and configuration
|
|
421
|
-
- **test_decorators.py**: Tests for workflow, agent, and task decorators
|
|
422
|
-
- **test_input_scanner.py**: Tests for prompt injection scanning and security features
|
|
592
|
+
Our test suite is built on `pytest` and is designed to ensure the reliability and stability of the Netra SDK. We follow comprehensive testing standards, including unit, integration, and thread-safety tests.
|
|
423
593
|
|
|
424
594
|
### Running Tests
|
|
425
595
|
|
|
426
|
-
To run the
|
|
596
|
+
To run the complete test suite, use the following command from the root of the project:
|
|
427
597
|
|
|
428
598
|
```bash
|
|
429
599
|
poetry run pytest
|
|
430
600
|
```
|
|
431
601
|
|
|
432
|
-
To run specific test modules:
|
|
433
602
|
|
|
603
|
+
### Run Specific Test File
|
|
604
|
+
To run a specific test file, use the following command from the root of the project:
|
|
434
605
|
```bash
|
|
435
606
|
poetry run pytest tests/test_netra_init.py
|
|
436
|
-
poetry run pytest tests/test_decorators.py
|
|
437
607
|
```
|
|
438
608
|
|
|
439
|
-
|
|
609
|
+
### Test Coverage
|
|
610
|
+
|
|
611
|
+
To generate a test coverage report, you can run:
|
|
440
612
|
|
|
441
613
|
```bash
|
|
442
614
|
poetry run pytest --cov=netra --cov-report=html
|
|
443
615
|
```
|
|
444
616
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
The testing framework provides several useful fixtures:
|
|
617
|
+
This will create an `htmlcov` directory with a detailed report.
|
|
448
618
|
|
|
449
|
-
|
|
450
|
-
- **clean_environment**: Provides a clean environment by temporarily clearing relevant environment variables
|
|
451
|
-
- **mock_config**, **mock_tracer**, **mock_init_instrumentations**: Mock objects for testing components in isolation
|
|
452
|
-
- **sample_config_params**, **sample_session_data**: Sample data for testing configuration and sessions
|
|
619
|
+
### Running Specific Test Categories
|
|
453
620
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
Tests are organized using pytest markers:
|
|
457
|
-
|
|
458
|
-
- **unit**: Unit tests for individual components
|
|
459
|
-
- **integration**: Integration tests for component interactions
|
|
460
|
-
- **thread_safety**: Tests for thread safety and concurrency
|
|
461
|
-
|
|
462
|
-
To run tests by category:
|
|
621
|
+
Tests are organized using `pytest` markers. You can run specific categories of tests as follows:
|
|
463
622
|
|
|
464
623
|
```bash
|
|
624
|
+
# Run only unit tests (default)
|
|
465
625
|
poetry run pytest -m unit
|
|
626
|
+
|
|
627
|
+
# Run only integration tests
|
|
466
628
|
poetry run pytest -m integration
|
|
629
|
+
|
|
630
|
+
# Run only thread-safety tests
|
|
467
631
|
poetry run pytest -m thread_safety
|
|
468
632
|
```
|
|
469
633
|
|
|
634
|
+
For more detailed information on our testing strategy, fixtures, and best practices, please refer to the `README.md` file in the `tests` directory.
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
|
|
470
638
|
## 🛠️ Development Setup
|
|
471
639
|
|
|
472
640
|
To set up your development environment for the Netra SDK, run the provided setup script:
|
|
@@ -536,3 +704,4 @@ docs: update installation instructions
|
|
|
536
704
|
**Footer** can be used for "BREAKING CHANGE:" or issue references.
|
|
537
705
|
|
|
538
706
|
---
|
|
707
|
+
|
|
@@ -1,37 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.3
|
|
2
|
-
Name: netra-sdk
|
|
3
|
-
Version: 0.1.0
|
|
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
|
-
License: Apache-2.0
|
|
6
|
-
Keywords: netra,tracing,observability,sdk,ai,llm,vector,database
|
|
7
|
-
Author: Sooraj Thomas
|
|
8
|
-
Author-email: sooraj@keyvalue.systems
|
|
9
|
-
Requires-Python: >=3.10,<3.13
|
|
10
|
-
Classifier: Development Status :: 4 - Beta
|
|
11
|
-
Classifier: Framework :: OpenTelemetry
|
|
12
|
-
Classifier: Intended Audience :: Developers
|
|
13
|
-
Classifier: Programming Language :: Python
|
|
14
|
-
Classifier: Programming Language :: Python :: 3
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
-
Classifier: Typing :: Typed
|
|
20
|
-
Provides-Extra: llm-guard
|
|
21
|
-
Requires-Dist: llm-guard (>=0.3.16,<0.4.0) ; extra == "llm-guard"
|
|
22
|
-
Requires-Dist: opentelemetry-api (>=1.34.0,<2.0.0)
|
|
23
|
-
Requires-Dist: opentelemetry-instrumentation-aiohttp-client (>=0.55b1,<1.0.0)
|
|
24
|
-
Requires-Dist: opentelemetry-instrumentation-fastapi (>=0.55b1,<1.0.0)
|
|
25
|
-
Requires-Dist: opentelemetry-instrumentation-httpx (>=0.55b1,<1.0.0)
|
|
26
|
-
Requires-Dist: opentelemetry-sdk (>=1.34.0,<2.0.0)
|
|
27
|
-
Requires-Dist: presidio-analyzer (>=2.2.358,<3.0.0)
|
|
28
|
-
Requires-Dist: traceloop-sdk (>=0.40.7,<0.41.0)
|
|
29
|
-
Project-URL: Bug Tracker, https://github.com/KeyValueSoftwareSystems/netra-sdk-py/issues
|
|
30
|
-
Project-URL: Documentation, https://github.com/KeyValueSoftwareSystems/netra-sdk-py/blob/main/README.md
|
|
31
|
-
Project-URL: Homepage, https://github.com/KeyValueSoftwareSystems/netra-sdk-py
|
|
32
|
-
Project-URL: Repository, https://github.com/KeyValueSoftwareSystems/netra-sdk-py
|
|
33
|
-
Description-Content-Type: text/markdown
|
|
34
|
-
|
|
35
1
|
# Netra SDK
|
|
36
2
|
|
|
37
3
|
🚀 **Netra SDK** is a comprehensive Python library for AI application observability that provides OpenTelemetry-based monitoring, and tracing for LLM applications. It enables easy instrumentation, session tracking, and privacy-focused data analysis for AI systems.
|
|
@@ -180,16 +146,47 @@ class CustomerSupportAgent:
|
|
|
180
146
|
- **AIOHTTP** - Asynchronous HTTP client/server
|
|
181
147
|
- **FastAPI** - Modern web framework for APIs
|
|
182
148
|
- **Requests** - Popular HTTP library for Python
|
|
183
|
-
- **
|
|
149
|
+
- **Django** - High-level Python web framework
|
|
150
|
+
- **Flask** - Lightweight WSGI web application framework
|
|
151
|
+
- **Falcon** - High-performance Python web framework
|
|
152
|
+
- **Pyramid** - Small, fast, down-to-earth Python web framework
|
|
153
|
+
- **Starlette** - Lightweight ASGI framework/toolkit
|
|
154
|
+
- **Tornado** - Asynchronous networking library and web framework
|
|
155
|
+
- **gRPC** - High-performance, open-source universal RPC framework
|
|
156
|
+
- **Urllib** - Standard Python HTTP client library
|
|
157
|
+
- **Urllib3** - Powerful, user-friendly HTTP client for Python
|
|
184
158
|
|
|
185
159
|
### 🗄️ Database Clients
|
|
186
160
|
|
|
187
161
|
- **PyMySQL** - Pure Python MySQL client
|
|
188
162
|
- **Redis** - In-memory data structure store
|
|
163
|
+
- **SQLAlchemy** - SQL toolkit and Object-Relational Mapper
|
|
164
|
+
- **Psycopg** - Modern PostgreSQL database adapter for Python
|
|
165
|
+
- **Pymongo** - Python driver for MongoDB
|
|
166
|
+
- **Elasticsearch** - Distributed, RESTful search and analytics engine
|
|
167
|
+
- **Cassandra** - Distributed NoSQL database
|
|
168
|
+
- **PyMSSQL** - Simple Microsoft SQL Server client
|
|
169
|
+
- **MySQL Connector** - Official MySQL driver
|
|
170
|
+
- **Sqlite3** - Built-in SQL database engine
|
|
171
|
+
- **Aiopg** - Asynchronous PostgreSQL client
|
|
172
|
+
- **Asyncpg** - Fast asynchronous PostgreSQL client
|
|
173
|
+
- **Pymemcache** - Comprehensive Memcached client
|
|
174
|
+
- **Tortoise ORM** - Easy-to-use asyncio ORM
|
|
175
|
+
|
|
176
|
+
### 📨 Messaging & Task Queues
|
|
177
|
+
|
|
178
|
+
- **Celery** - Distributed task queue
|
|
179
|
+
- **Pika** - Pure-Python implementation of the AMQP 0-9-1 protocol
|
|
180
|
+
- **AIO Pika** - Asynchronous AMQP client
|
|
181
|
+
- **Kafka-Python** - Python client for Apache Kafka
|
|
182
|
+
- **AIOKafka** - Asynchronous Python client for Kafka
|
|
183
|
+
- **Confluent-Kafka** - Confluent's Python client for Apache Kafka
|
|
184
|
+
- **Boto3 SQS** - Amazon SQS client via Boto3
|
|
189
185
|
|
|
190
186
|
### 🔧 AI Frameworks & Orchestration
|
|
191
187
|
|
|
192
188
|
- **LangChain** - Framework for developing LLM applications
|
|
189
|
+
- **LangGraph** - Modern framework for LLM applications
|
|
193
190
|
- **LlamaIndex** - Data framework for LLM applications
|
|
194
191
|
- **Haystack** - End-to-end NLP framework
|
|
195
192
|
- **CrewAI** - Multi-agent AI systems
|
|
@@ -364,6 +361,72 @@ with Netra.start_session("video_generation_task") as session:
|
|
|
364
361
|
|
|
365
362
|
## 🔧 Advanced Configuration
|
|
366
363
|
|
|
364
|
+
### Environment Variables
|
|
365
|
+
|
|
366
|
+
Netra SDK can be configured using the following environment variables:
|
|
367
|
+
|
|
368
|
+
#### Netra-specific Variables
|
|
369
|
+
|
|
370
|
+
| Variable Name | Description | Default |
|
|
371
|
+
|---------------|-------------|---------|
|
|
372
|
+
| `NETRA_APP_NAME` | Logical name for your service | Falls back to `OTEL_SERVICE_NAME` or `llm_tracing_service` |
|
|
373
|
+
| `NETRA_OTLP_ENDPOINT` | URL for OTLP collector | Falls back to `OTEL_EXPORTER_OTLP_ENDPOINT` |
|
|
374
|
+
| `NETRA_API_KEY` | API key for authentication | `None` |
|
|
375
|
+
| `NETRA_HEADERS` | Additional headers in W3C Correlation-Context format | `None` |
|
|
376
|
+
| `NETRA_DISABLE_BATCH` | Disable batch span processor (`true`/`false`) | `false` |
|
|
377
|
+
| `NETRA_TRACE_CONTENT` | Whether to capture prompt/completion content (`true`/`false`) | `true` |
|
|
378
|
+
| `NETRA_ENV` | Deployment environment (e.g., `prod`, `staging`, `dev`) | `local` |
|
|
379
|
+
| `NETRA_RESOURCE_ATTRS` | JSON string of custom resource attributes | `{}` |
|
|
380
|
+
|
|
381
|
+
#### Standard OpenTelemetry Variables
|
|
382
|
+
|
|
383
|
+
| Variable Name | Description | Used When |
|
|
384
|
+
|---------------|-------------|-----------|
|
|
385
|
+
| `OTEL_SERVICE_NAME` | Logical name for your service | When `NETRA_APP_NAME` is not set |
|
|
386
|
+
| `OTEL_EXPORTER_OTLP_ENDPOINT` | URL for OTLP collector | When `NETRA_OTLP_ENDPOINT` is not set |
|
|
387
|
+
| `OTEL_EXPORTER_OTLP_HEADERS` | Additional headers for OTLP exporter | When `NETRA_HEADERS` is not set |
|
|
388
|
+
| `OTEL_RESOURCE_ATTRIBUTES` | Additional resource attributes | When `NETRA_RESOURCE_ATTRS` is not set |
|
|
389
|
+
|
|
390
|
+
### Configuration Precedence
|
|
391
|
+
|
|
392
|
+
Configuration values are resolved in the following order (highest to lowest precedence):
|
|
393
|
+
|
|
394
|
+
1. **Code Parameters**: Values passed directly to `Netra.init()`
|
|
395
|
+
2. **Netra Environment Variables**: `NETRA_*` variables
|
|
396
|
+
3. **OpenTelemetry Environment Variables**: Standard `OTEL_*` variables
|
|
397
|
+
4. **Default Values**: Fallback values defined in the SDK
|
|
398
|
+
|
|
399
|
+
This allows you to:
|
|
400
|
+
- Override any setting directly in code for maximum control
|
|
401
|
+
- Use Netra-specific environment variables for Netra-specific settings
|
|
402
|
+
- Fall back to standard OpenTelemetry variables for compatibility
|
|
403
|
+
- Rely on sensible defaults when no other configuration is provided
|
|
404
|
+
|
|
405
|
+
**Example**:
|
|
406
|
+
```bash
|
|
407
|
+
export NETRA_APP_NAME="my-ai-service"
|
|
408
|
+
export NETRA_OTLP_ENDPOINT="https://collector.example.com:4318"
|
|
409
|
+
export NETRA_API_KEY="your-api-key-here"
|
|
410
|
+
export NETRA_ENV="production"
|
|
411
|
+
export NETRA_RESOURCE_ATTRS='{"team":"ai", "version":"1.0.0"}'
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
### Programmatic Configuration
|
|
415
|
+
|
|
416
|
+
You can also configure the SDK programmatically when initializing:
|
|
417
|
+
|
|
418
|
+
```python
|
|
419
|
+
from netra import Netra
|
|
420
|
+
|
|
421
|
+
Netra.init(
|
|
422
|
+
app_name="my-ai-service",
|
|
423
|
+
environment="production",
|
|
424
|
+
resource_attributes={"team": "ai", "version": "1.0.0"},
|
|
425
|
+
trace_content=True,
|
|
426
|
+
disable_batch=False
|
|
427
|
+
)
|
|
428
|
+
```
|
|
429
|
+
|
|
367
430
|
### Custom Instrumentation Selection
|
|
368
431
|
|
|
369
432
|
Control which instrumentations are enabled:
|
|
@@ -434,6 +497,7 @@ Netra.init(app_name="Your App")
|
|
|
434
497
|
- **📈 Rich Ecosystem**: Leverage the entire OpenTelemetry ecosystem
|
|
435
498
|
|
|
436
499
|
|
|
500
|
+
|
|
437
501
|
## 📚 Examples
|
|
438
502
|
|
|
439
503
|
The SDK includes comprehensive examples in the `examples/` directory:
|
|
@@ -446,61 +510,52 @@ The SDK includes comprehensive examples in the `examples/` directory:
|
|
|
446
510
|
|
|
447
511
|
## 🧪 Tests
|
|
448
512
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
### Test Structure
|
|
452
|
-
|
|
453
|
-
- **conftest.py**: Contains shared fixtures, test utilities, and configuration for all tests
|
|
454
|
-
- **test_netra_init.py**: Tests for the main Netra SDK initialization and configuration
|
|
455
|
-
- **test_decorators.py**: Tests for workflow, agent, and task decorators
|
|
456
|
-
- **test_input_scanner.py**: Tests for prompt injection scanning and security features
|
|
513
|
+
Our test suite is built on `pytest` and is designed to ensure the reliability and stability of the Netra SDK. We follow comprehensive testing standards, including unit, integration, and thread-safety tests.
|
|
457
514
|
|
|
458
515
|
### Running Tests
|
|
459
516
|
|
|
460
|
-
To run the
|
|
517
|
+
To run the complete test suite, use the following command from the root of the project:
|
|
461
518
|
|
|
462
519
|
```bash
|
|
463
520
|
poetry run pytest
|
|
464
521
|
```
|
|
465
522
|
|
|
466
|
-
To run specific test modules:
|
|
467
523
|
|
|
524
|
+
### Run Specific Test File
|
|
525
|
+
To run a specific test file, use the following command from the root of the project:
|
|
468
526
|
```bash
|
|
469
527
|
poetry run pytest tests/test_netra_init.py
|
|
470
|
-
poetry run pytest tests/test_decorators.py
|
|
471
528
|
```
|
|
472
529
|
|
|
473
|
-
|
|
530
|
+
### Test Coverage
|
|
531
|
+
|
|
532
|
+
To generate a test coverage report, you can run:
|
|
474
533
|
|
|
475
534
|
```bash
|
|
476
535
|
poetry run pytest --cov=netra --cov-report=html
|
|
477
536
|
```
|
|
478
537
|
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
The testing framework provides several useful fixtures:
|
|
538
|
+
This will create an `htmlcov` directory with a detailed report.
|
|
482
539
|
|
|
483
|
-
|
|
484
|
-
- **clean_environment**: Provides a clean environment by temporarily clearing relevant environment variables
|
|
485
|
-
- **mock_config**, **mock_tracer**, **mock_init_instrumentations**: Mock objects for testing components in isolation
|
|
486
|
-
- **sample_config_params**, **sample_session_data**: Sample data for testing configuration and sessions
|
|
540
|
+
### Running Specific Test Categories
|
|
487
541
|
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
Tests are organized using pytest markers:
|
|
491
|
-
|
|
492
|
-
- **unit**: Unit tests for individual components
|
|
493
|
-
- **integration**: Integration tests for component interactions
|
|
494
|
-
- **thread_safety**: Tests for thread safety and concurrency
|
|
495
|
-
|
|
496
|
-
To run tests by category:
|
|
542
|
+
Tests are organized using `pytest` markers. You can run specific categories of tests as follows:
|
|
497
543
|
|
|
498
544
|
```bash
|
|
545
|
+
# Run only unit tests (default)
|
|
499
546
|
poetry run pytest -m unit
|
|
547
|
+
|
|
548
|
+
# Run only integration tests
|
|
500
549
|
poetry run pytest -m integration
|
|
550
|
+
|
|
551
|
+
# Run only thread-safety tests
|
|
501
552
|
poetry run pytest -m thread_safety
|
|
502
553
|
```
|
|
503
554
|
|
|
555
|
+
For more detailed information on our testing strategy, fixtures, and best practices, please refer to the `README.md` file in the `tests` directory.
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
|
|
504
559
|
## 🛠️ Development Setup
|
|
505
560
|
|
|
506
561
|
To set up your development environment for the Netra SDK, run the provided setup script:
|
|
@@ -570,4 +625,3 @@ docs: update installation instructions
|
|
|
570
625
|
**Footer** can be used for "BREAKING CHANGE:" or issue references.
|
|
571
626
|
|
|
572
627
|
---
|
|
573
|
-
|
|
@@ -35,7 +35,7 @@ class Config:
|
|
|
35
35
|
):
|
|
36
36
|
# Application name: from param, else env
|
|
37
37
|
self.app_name = (
|
|
38
|
-
app_name or os.getenv("
|
|
38
|
+
app_name or os.getenv("NETRA_APP_NAME") or os.getenv("OTEL_SERVICE_NAME") or "llm_tracing_service"
|
|
39
39
|
)
|
|
40
40
|
|
|
41
41
|
# OTLP endpoint: if explicit param, else OTEL_EXPORTER_OTLP_ENDPOINT
|