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
genai_otel/__init__.py ADDED
@@ -0,0 +1,132 @@
1
+ """Top-level package for GenAI OpenTelemetry Auto-Instrumentation.
2
+
3
+ This package provides a comprehensive solution for automatically instrumenting
4
+ Generative AI (GenAI) and Large Language Model (LLM) applications with OpenTelemetry.
5
+ It supports various LLM providers, frameworks, and common data stores (MCP tools).
6
+ """
7
+
8
+ import logging
9
+ import os
10
+ import warnings
11
+
12
+ import httpx
13
+
14
+ # Suppress known third-party library warnings that we cannot control
15
+ warnings.filterwarnings("ignore", category=DeprecationWarning, module="pydantic")
16
+ warnings.filterwarnings("ignore", message=".*validate_default.*", module="pydantic")
17
+ warnings.filterwarnings("ignore", message=".*NumPy module was reloaded.*", module="replicate")
18
+
19
+ from .__version__ import __version__
20
+
21
+ # Package metadata (from pyproject.toml)
22
+ __author__ = "Kshitij Thakkar"
23
+ __email__ = "kshitijthakkar@rocketmail.com"
24
+ __license__ = "AGPL-3.0-or-later"
25
+
26
+ # Re-exporting key components for easier access
27
+ from .auto_instrument import setup_auto_instrumentation # Restoring direct import
28
+ from .config import OTelConfig
29
+ from .cost_calculator import CostCalculator
30
+ from .gpu_metrics import GPUMetricsCollector
31
+
32
+ # Import instrumentors conditionally to avoid errors if dependencies aren't installed
33
+ from .instrumentors import (
34
+ AnthropicInstrumentor,
35
+ AnyscaleInstrumentor,
36
+ AWSBedrockInstrumentor,
37
+ AzureOpenAIInstrumentor,
38
+ CohereInstrumentor,
39
+ GoogleAIInstrumentor,
40
+ GroqInstrumentor,
41
+ HuggingFaceInstrumentor,
42
+ LangChainInstrumentor,
43
+ LlamaIndexInstrumentor,
44
+ MistralAIInstrumentor,
45
+ OllamaInstrumentor,
46
+ OpenAIInstrumentor,
47
+ ReplicateInstrumentor,
48
+ TogetherAIInstrumentor,
49
+ VertexAIInstrumentor,
50
+ )
51
+ from .mcp_instrumentors.manager import MCPInstrumentorManager
52
+ from .server_metrics import ServerMetricsCollector, get_server_metrics
53
+
54
+ logger = logging.getLogger(__name__)
55
+
56
+
57
+ def instrument(**kwargs):
58
+ """Public function to initialize and start auto-instrumentation.
59
+
60
+ Loads configuration from environment variables or provided keyword arguments,
61
+ then sets up OpenTelemetry tracing and metrics.
62
+
63
+ Args:
64
+ **kwargs: Configuration parameters that can override environment variables.
65
+ See OTelConfig for available parameters (e.g., service_name, endpoint).
66
+
67
+ Example:
68
+ >>> from genai_otel import instrument
69
+ >>> instrument(service_name="my-app", endpoint="http://localhost:4318")
70
+
71
+ Environment Variables:
72
+ OTEL_SERVICE_NAME: Name of the service (default: "genai-app")
73
+ OTEL_EXPORTER_OTLP_ENDPOINT: OTLP endpoint (default: "http://localhost:4318")
74
+ GENAI_ENABLE_GPU_METRICS: Enable GPU metrics (default: "true")
75
+ GENAI_ENABLE_COST_TRACKING: Enable cost tracking (default: "true")
76
+ GENAI_ENABLE_MCP_INSTRUMENTATION: Enable MCP instrumentation (default: "true")
77
+ GENAI_FAIL_ON_ERROR: Fail if instrumentation errors occur (default: "false")
78
+ OTEL_EXPORTER_OTLP_HEADERS: OTLP headers in format "key1=val1,key2=val2"
79
+ GENAI_LOG_LEVEL: Logging level (default: "INFO")
80
+ GENAI_LOG_FILE: Log file path (optional)
81
+ """
82
+ try:
83
+ # Create config object, allowing kwargs to override env vars
84
+ config = OTelConfig(**kwargs)
85
+ setup_auto_instrumentation(config)
86
+ logger.info("GenAI OpenTelemetry instrumentation initialized successfully")
87
+ except Exception as e:
88
+ # Log the error and potentially re-raise based on fail_on_error
89
+ logger.error("Failed to initialize instrumentation: %s", e, exc_info=True)
90
+ fail_on_error = kwargs.get(
91
+ "fail_on_error", os.getenv("GENAI_FAIL_ON_ERROR", "false").lower() == "true"
92
+ )
93
+ if fail_on_error:
94
+ raise
95
+
96
+
97
+ __all__ = [
98
+ # Version info
99
+ "__version__",
100
+ "__author__",
101
+ "__email__",
102
+ "__license__",
103
+ # Core functions
104
+ "instrument",
105
+ "setup_auto_instrumentation", # Re-added to __all__
106
+ # Configuration
107
+ "OTelConfig",
108
+ # Utilities
109
+ "CostCalculator",
110
+ "GPUMetricsCollector",
111
+ "ServerMetricsCollector",
112
+ "get_server_metrics",
113
+ # Instrumentors
114
+ "OpenAIInstrumentor",
115
+ "AnthropicInstrumentor",
116
+ "GoogleAIInstrumentor",
117
+ "AWSBedrockInstrumentor",
118
+ "AzureOpenAIInstrumentor",
119
+ "CohereInstrumentor",
120
+ "MistralAIInstrumentor",
121
+ "TogetherAIInstrumentor",
122
+ "GroqInstrumentor",
123
+ "LangChainInstrumentor",
124
+ "LlamaIndexInstrumentor",
125
+ "HuggingFaceInstrumentor",
126
+ "OllamaInstrumentor",
127
+ "VertexAIInstrumentor",
128
+ "ReplicateInstrumentor",
129
+ "AnyscaleInstrumentor",
130
+ # MCP Manager
131
+ "MCPInstrumentorManager",
132
+ ]
@@ -0,0 +1,34 @@
1
+ # file generated by setuptools-scm
2
+ # don't change, don't track in version control
3
+
4
+ __all__ = [
5
+ "__version__",
6
+ "__version_tuple__",
7
+ "version",
8
+ "version_tuple",
9
+ "__commit_id__",
10
+ "commit_id",
11
+ ]
12
+
13
+ TYPE_CHECKING = False
14
+ if TYPE_CHECKING:
15
+ from typing import Tuple
16
+ from typing import Union
17
+
18
+ VERSION_TUPLE = Tuple[Union[int, str], ...]
19
+ COMMIT_ID = Union[str, None]
20
+ else:
21
+ VERSION_TUPLE = object
22
+ COMMIT_ID = object
23
+
24
+ version: str
25
+ __version__: str
26
+ __version_tuple__: VERSION_TUPLE
27
+ version_tuple: VERSION_TUPLE
28
+ commit_id: COMMIT_ID
29
+ __commit_id__: COMMIT_ID
30
+
31
+ __version__ = version = '0.1.24'
32
+ __version_tuple__ = version_tuple = (0, 1, 24)
33
+
34
+ __commit_id__ = commit_id = None