genai-otel-instrument 0.1.24__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.
Files changed (69) hide show
  1. genai_otel/__init__.py +132 -0
  2. genai_otel/__version__.py +34 -0
  3. genai_otel/auto_instrument.py +602 -0
  4. genai_otel/cli.py +92 -0
  5. genai_otel/config.py +333 -0
  6. genai_otel/cost_calculator.py +467 -0
  7. genai_otel/cost_enriching_exporter.py +207 -0
  8. genai_otel/cost_enrichment_processor.py +174 -0
  9. genai_otel/evaluation/__init__.py +76 -0
  10. genai_otel/evaluation/bias_detector.py +364 -0
  11. genai_otel/evaluation/config.py +261 -0
  12. genai_otel/evaluation/hallucination_detector.py +525 -0
  13. genai_otel/evaluation/pii_detector.py +356 -0
  14. genai_otel/evaluation/prompt_injection_detector.py +262 -0
  15. genai_otel/evaluation/restricted_topics_detector.py +316 -0
  16. genai_otel/evaluation/span_processor.py +962 -0
  17. genai_otel/evaluation/toxicity_detector.py +406 -0
  18. genai_otel/exceptions.py +17 -0
  19. genai_otel/gpu_metrics.py +516 -0
  20. genai_otel/instrumentors/__init__.py +71 -0
  21. genai_otel/instrumentors/anthropic_instrumentor.py +134 -0
  22. genai_otel/instrumentors/anyscale_instrumentor.py +27 -0
  23. genai_otel/instrumentors/autogen_instrumentor.py +394 -0
  24. genai_otel/instrumentors/aws_bedrock_instrumentor.py +94 -0
  25. genai_otel/instrumentors/azure_openai_instrumentor.py +69 -0
  26. genai_otel/instrumentors/base.py +919 -0
  27. genai_otel/instrumentors/bedrock_agents_instrumentor.py +398 -0
  28. genai_otel/instrumentors/cohere_instrumentor.py +140 -0
  29. genai_otel/instrumentors/crewai_instrumentor.py +311 -0
  30. genai_otel/instrumentors/dspy_instrumentor.py +661 -0
  31. genai_otel/instrumentors/google_ai_instrumentor.py +310 -0
  32. genai_otel/instrumentors/groq_instrumentor.py +106 -0
  33. genai_otel/instrumentors/guardrails_ai_instrumentor.py +510 -0
  34. genai_otel/instrumentors/haystack_instrumentor.py +503 -0
  35. genai_otel/instrumentors/huggingface_instrumentor.py +399 -0
  36. genai_otel/instrumentors/hyperbolic_instrumentor.py +236 -0
  37. genai_otel/instrumentors/instructor_instrumentor.py +425 -0
  38. genai_otel/instrumentors/langchain_instrumentor.py +340 -0
  39. genai_otel/instrumentors/langgraph_instrumentor.py +328 -0
  40. genai_otel/instrumentors/llamaindex_instrumentor.py +36 -0
  41. genai_otel/instrumentors/mistralai_instrumentor.py +315 -0
  42. genai_otel/instrumentors/ollama_instrumentor.py +197 -0
  43. genai_otel/instrumentors/ollama_server_metrics_poller.py +336 -0
  44. genai_otel/instrumentors/openai_agents_instrumentor.py +291 -0
  45. genai_otel/instrumentors/openai_instrumentor.py +260 -0
  46. genai_otel/instrumentors/pydantic_ai_instrumentor.py +362 -0
  47. genai_otel/instrumentors/replicate_instrumentor.py +87 -0
  48. genai_otel/instrumentors/sambanova_instrumentor.py +196 -0
  49. genai_otel/instrumentors/togetherai_instrumentor.py +146 -0
  50. genai_otel/instrumentors/vertexai_instrumentor.py +106 -0
  51. genai_otel/llm_pricing.json +1676 -0
  52. genai_otel/logging_config.py +45 -0
  53. genai_otel/mcp_instrumentors/__init__.py +14 -0
  54. genai_otel/mcp_instrumentors/api_instrumentor.py +144 -0
  55. genai_otel/mcp_instrumentors/base.py +105 -0
  56. genai_otel/mcp_instrumentors/database_instrumentor.py +336 -0
  57. genai_otel/mcp_instrumentors/kafka_instrumentor.py +31 -0
  58. genai_otel/mcp_instrumentors/manager.py +139 -0
  59. genai_otel/mcp_instrumentors/redis_instrumentor.py +31 -0
  60. genai_otel/mcp_instrumentors/vector_db_instrumentor.py +265 -0
  61. genai_otel/metrics.py +148 -0
  62. genai_otel/py.typed +2 -0
  63. genai_otel/server_metrics.py +197 -0
  64. genai_otel_instrument-0.1.24.dist-info/METADATA +1404 -0
  65. genai_otel_instrument-0.1.24.dist-info/RECORD +69 -0
  66. genai_otel_instrument-0.1.24.dist-info/WHEEL +5 -0
  67. genai_otel_instrument-0.1.24.dist-info/entry_points.txt +2 -0
  68. genai_otel_instrument-0.1.24.dist-info/licenses/LICENSE +680 -0
  69. genai_otel_instrument-0.1.24.dist-info/top_level.txt +1 -0
@@ -0,0 +1,261 @@
1
+ """Configuration classes for evaluation and safety features.
2
+
3
+ This module defines configuration dataclasses for all evaluation and safety features
4
+ including PII detection, toxicity detection, bias detection, prompt injection detection,
5
+ restricted topics, and hallucination detection.
6
+ """
7
+
8
+ from dataclasses import dataclass, field
9
+ from enum import Enum
10
+ from typing import List, Optional, Set
11
+
12
+
13
+ class PIIMode(str, Enum):
14
+ """PII detection mode."""
15
+
16
+ DETECT = "detect" # Only detect and report PII
17
+ REDACT = "redact" # Detect and redact PII entities
18
+ BLOCK = "block" # Block requests/responses containing PII
19
+
20
+
21
+ class PIIEntityType(str, Enum):
22
+ """PII entity types supported for detection."""
23
+
24
+ CREDIT_CARD = "CREDIT_CARD"
25
+ EMAIL_ADDRESS = "EMAIL_ADDRESS"
26
+ IBAN_CODE = "IBAN_CODE"
27
+ IP_ADDRESS = "IP_ADDRESS"
28
+ PERSON = "PERSON"
29
+ PHONE_NUMBER = "PHONE_NUMBER"
30
+ US_SSN = "US_SSN"
31
+ US_BANK_NUMBER = "US_BANK_NUMBER"
32
+ US_DRIVER_LICENSE = "US_DRIVER_LICENSE"
33
+ US_PASSPORT = "US_PASSPORT"
34
+ LOCATION = "LOCATION"
35
+ DATE_TIME = "DATE_TIME"
36
+ NRP = "NRP" # Named Recognized Person
37
+ MEDICAL_LICENSE = "MEDICAL_LICENSE"
38
+ URL = "URL"
39
+ CRYPTO = "CRYPTO" # Cryptocurrency wallet addresses
40
+ UK_NHS = "UK_NHS"
41
+
42
+
43
+ @dataclass
44
+ class PIIConfig:
45
+ """Configuration for PII detection and protection.
46
+
47
+ Attributes:
48
+ enabled: Whether PII detection is enabled
49
+ mode: Detection mode (detect, redact, or block)
50
+ entity_types: Set of PII entity types to detect
51
+ redaction_char: Character to use for redaction (default: "*")
52
+ threshold: Confidence threshold for detection (0.0-1.0)
53
+ gdpr_mode: Enable GDPR-specific entity types and rules
54
+ hipaa_mode: Enable HIPAA-specific entity types and rules
55
+ pci_dss_mode: Enable PCI-DSS-specific entity types and rules
56
+ custom_patterns: Custom regex patterns for additional PII detection
57
+ allow_list: Entities to exclude from detection
58
+ """
59
+
60
+ enabled: bool = False
61
+ mode: PIIMode = PIIMode.DETECT
62
+ entity_types: Set[PIIEntityType] = field(
63
+ default_factory=lambda: {
64
+ PIIEntityType.CREDIT_CARD,
65
+ PIIEntityType.EMAIL_ADDRESS,
66
+ PIIEntityType.IP_ADDRESS,
67
+ PIIEntityType.PERSON,
68
+ PIIEntityType.PHONE_NUMBER,
69
+ PIIEntityType.US_SSN,
70
+ }
71
+ )
72
+ redaction_char: str = "*"
73
+ threshold: float = 0.7
74
+ gdpr_mode: bool = False
75
+ hipaa_mode: bool = False
76
+ pci_dss_mode: bool = False
77
+ custom_patterns: Optional[dict] = None
78
+ allow_list: Optional[List[str]] = None
79
+
80
+ def __post_init__(self):
81
+ """Validate configuration and apply compliance modes."""
82
+ if not 0.0 <= self.threshold <= 1.0:
83
+ raise ValueError("threshold must be between 0.0 and 1.0")
84
+
85
+ # Apply GDPR mode - add EU-specific entities
86
+ if self.gdpr_mode:
87
+ self.entity_types.update(
88
+ {
89
+ PIIEntityType.IBAN_CODE,
90
+ PIIEntityType.UK_NHS,
91
+ PIIEntityType.NRP,
92
+ }
93
+ )
94
+
95
+ # Apply HIPAA mode - add healthcare entities
96
+ if self.hipaa_mode:
97
+ self.entity_types.update(
98
+ {
99
+ PIIEntityType.MEDICAL_LICENSE,
100
+ PIIEntityType.US_PASSPORT,
101
+ PIIEntityType.DATE_TIME,
102
+ }
103
+ )
104
+
105
+ # Apply PCI-DSS mode - ensure credit card detection
106
+ if self.pci_dss_mode:
107
+ self.entity_types.add(PIIEntityType.CREDIT_CARD)
108
+ self.entity_types.add(PIIEntityType.US_BANK_NUMBER)
109
+
110
+
111
+ @dataclass
112
+ class ToxicityConfig:
113
+ """Configuration for toxicity detection.
114
+
115
+ Attributes:
116
+ enabled: Whether toxicity detection is enabled
117
+ threshold: Toxicity score threshold (0.0-1.0)
118
+ use_perspective_api: Use Google Perspective API (requires API key)
119
+ perspective_api_key: API key for Perspective API
120
+ use_local_model: Use local Detoxify model as fallback
121
+ categories: Toxicity categories to check
122
+ block_on_detection: Block toxic content instead of just logging
123
+ """
124
+
125
+ enabled: bool = False
126
+ threshold: float = 0.7
127
+ use_perspective_api: bool = False
128
+ perspective_api_key: Optional[str] = None
129
+ use_local_model: bool = True
130
+ categories: Set[str] = field(
131
+ default_factory=lambda: {
132
+ "toxicity",
133
+ "severe_toxicity",
134
+ "identity_attack",
135
+ "insult",
136
+ "profanity",
137
+ "threat",
138
+ }
139
+ )
140
+ block_on_detection: bool = False
141
+
142
+ def __post_init__(self):
143
+ """Validate configuration."""
144
+ if not 0.0 <= self.threshold <= 1.0:
145
+ raise ValueError("threshold must be between 0.0 and 1.0")
146
+
147
+ if self.use_perspective_api and not self.perspective_api_key:
148
+ raise ValueError("perspective_api_key is required when use_perspective_api is True")
149
+
150
+
151
+ @dataclass
152
+ class BiasConfig:
153
+ """Configuration for bias detection.
154
+
155
+ Attributes:
156
+ enabled: Whether bias detection is enabled
157
+ threshold: Bias score threshold (0.0-1.0)
158
+ bias_types: Types of bias to detect
159
+ use_fairlearn: Use Fairlearn library for ML-based detection
160
+ sensitive_attributes: Attributes to check for bias
161
+ check_prompts: Check prompts for biased language
162
+ check_responses: Check responses for biased language
163
+ block_on_detection: Block content when bias is detected
164
+ """
165
+
166
+ enabled: bool = False
167
+ threshold: float = 0.5
168
+ bias_types: Set[str] = field(
169
+ default_factory=lambda: {
170
+ "gender",
171
+ "race",
172
+ "ethnicity",
173
+ "religion",
174
+ "age",
175
+ "disability",
176
+ "sexual_orientation",
177
+ "political",
178
+ }
179
+ )
180
+ use_fairlearn: bool = False
181
+ sensitive_attributes: Optional[List[str]] = None
182
+ check_prompts: bool = True
183
+ check_responses: bool = True
184
+ block_on_detection: bool = False
185
+
186
+ def __post_init__(self):
187
+ """Validate configuration."""
188
+ if not 0.0 <= self.threshold <= 1.0:
189
+ raise ValueError("threshold must be between 0.0 and 1.0")
190
+
191
+
192
+ @dataclass
193
+ class PromptInjectionConfig:
194
+ """Configuration for prompt injection detection.
195
+
196
+ Attributes:
197
+ enabled: Whether prompt injection detection is enabled
198
+ threshold: Detection confidence threshold (0.0-1.0)
199
+ use_ml_model: Use ML-based classifier for detection
200
+ check_patterns: Check for known injection patterns
201
+ patterns: Custom injection patterns to detect
202
+ block_on_detection: Block detected injection attempts
203
+ log_attempts: Log all injection attempts for analysis
204
+ """
205
+
206
+ enabled: bool = False
207
+ threshold: float = 0.7
208
+ use_ml_model: bool = True
209
+ check_patterns: bool = True
210
+ patterns: Optional[List[str]] = None
211
+ block_on_detection: bool = False
212
+ log_attempts: bool = True
213
+
214
+ def __post_init__(self):
215
+ """Validate configuration."""
216
+ if not 0.0 <= self.threshold <= 1.0:
217
+ raise ValueError("threshold must be between 0.0 and 1.0")
218
+
219
+
220
+ @dataclass
221
+ class RestrictedTopicsConfig:
222
+ """Configuration for restricted topics detection.
223
+
224
+ Attributes:
225
+ enabled: Whether restricted topics detection is enabled
226
+ restricted_topics: Optional list of specific topics to restrict
227
+ threshold: Classification confidence threshold (0.0-1.0)
228
+ block_on_detection: Block content matching restricted topics
229
+ """
230
+
231
+ enabled: bool = False
232
+ restricted_topics: Optional[List[str]] = None
233
+ threshold: float = 0.5
234
+ block_on_detection: bool = False
235
+
236
+ def __post_init__(self):
237
+ """Validate configuration."""
238
+ if not 0.0 <= self.threshold <= 1.0:
239
+ raise ValueError("threshold must be between 0.0 and 1.0")
240
+
241
+
242
+ @dataclass
243
+ class HallucinationConfig:
244
+ """Configuration for hallucination detection.
245
+
246
+ Attributes:
247
+ enabled: Whether hallucination detection is enabled
248
+ threshold: Hallucination score threshold (0.0-1.0)
249
+ check_citations: Check for citation validity
250
+ check_hedging: Check for hedge words
251
+ """
252
+
253
+ enabled: bool = False
254
+ threshold: float = 0.7
255
+ check_citations: bool = True
256
+ check_hedging: bool = True
257
+
258
+ def __post_init__(self):
259
+ """Validate configuration."""
260
+ if not 0.0 <= self.threshold <= 1.0:
261
+ raise ValueError("threshold must be between 0.0 and 1.0")