openlit 1.34.29__py3-none-any.whl → 1.34.31__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 (168) hide show
  1. openlit/__helpers.py +235 -86
  2. openlit/__init__.py +16 -13
  3. openlit/_instrumentors.py +2 -1
  4. openlit/evals/all.py +50 -21
  5. openlit/evals/bias_detection.py +47 -20
  6. openlit/evals/hallucination.py +53 -22
  7. openlit/evals/toxicity.py +50 -21
  8. openlit/evals/utils.py +54 -30
  9. openlit/guard/all.py +61 -19
  10. openlit/guard/prompt_injection.py +34 -14
  11. openlit/guard/restrict_topic.py +46 -15
  12. openlit/guard/sensitive_topic.py +34 -14
  13. openlit/guard/utils.py +58 -22
  14. openlit/instrumentation/ag2/__init__.py +24 -8
  15. openlit/instrumentation/ag2/ag2.py +34 -13
  16. openlit/instrumentation/ag2/async_ag2.py +34 -13
  17. openlit/instrumentation/ag2/utils.py +133 -30
  18. openlit/instrumentation/ai21/__init__.py +43 -14
  19. openlit/instrumentation/ai21/ai21.py +47 -21
  20. openlit/instrumentation/ai21/async_ai21.py +47 -21
  21. openlit/instrumentation/ai21/utils.py +299 -78
  22. openlit/instrumentation/anthropic/__init__.py +21 -4
  23. openlit/instrumentation/anthropic/anthropic.py +28 -17
  24. openlit/instrumentation/anthropic/async_anthropic.py +28 -17
  25. openlit/instrumentation/anthropic/utils.py +145 -35
  26. openlit/instrumentation/assemblyai/__init__.py +11 -2
  27. openlit/instrumentation/assemblyai/assemblyai.py +15 -4
  28. openlit/instrumentation/assemblyai/utils.py +120 -25
  29. openlit/instrumentation/astra/__init__.py +43 -10
  30. openlit/instrumentation/astra/astra.py +28 -5
  31. openlit/instrumentation/astra/async_astra.py +28 -5
  32. openlit/instrumentation/astra/utils.py +151 -55
  33. openlit/instrumentation/azure_ai_inference/__init__.py +43 -10
  34. openlit/instrumentation/azure_ai_inference/async_azure_ai_inference.py +53 -21
  35. openlit/instrumentation/azure_ai_inference/azure_ai_inference.py +53 -21
  36. openlit/instrumentation/azure_ai_inference/utils.py +307 -83
  37. openlit/instrumentation/bedrock/__init__.py +21 -4
  38. openlit/instrumentation/bedrock/bedrock.py +63 -25
  39. openlit/instrumentation/bedrock/utils.py +139 -30
  40. openlit/instrumentation/chroma/__init__.py +89 -16
  41. openlit/instrumentation/chroma/chroma.py +28 -6
  42. openlit/instrumentation/chroma/utils.py +167 -51
  43. openlit/instrumentation/cohere/__init__.py +63 -18
  44. openlit/instrumentation/cohere/async_cohere.py +63 -24
  45. openlit/instrumentation/cohere/cohere.py +63 -24
  46. openlit/instrumentation/cohere/utils.py +286 -73
  47. openlit/instrumentation/controlflow/__init__.py +35 -9
  48. openlit/instrumentation/controlflow/controlflow.py +66 -33
  49. openlit/instrumentation/crawl4ai/__init__.py +25 -10
  50. openlit/instrumentation/crawl4ai/async_crawl4ai.py +78 -31
  51. openlit/instrumentation/crawl4ai/crawl4ai.py +78 -31
  52. openlit/instrumentation/crewai/__init__.py +111 -24
  53. openlit/instrumentation/crewai/async_crewai.py +114 -0
  54. openlit/instrumentation/crewai/crewai.py +104 -131
  55. openlit/instrumentation/crewai/utils.py +615 -0
  56. openlit/instrumentation/dynamiq/__init__.py +46 -12
  57. openlit/instrumentation/dynamiq/dynamiq.py +74 -33
  58. openlit/instrumentation/elevenlabs/__init__.py +23 -4
  59. openlit/instrumentation/elevenlabs/async_elevenlabs.py +16 -4
  60. openlit/instrumentation/elevenlabs/elevenlabs.py +16 -4
  61. openlit/instrumentation/elevenlabs/utils.py +128 -25
  62. openlit/instrumentation/embedchain/__init__.py +11 -2
  63. openlit/instrumentation/embedchain/embedchain.py +68 -35
  64. openlit/instrumentation/firecrawl/__init__.py +24 -7
  65. openlit/instrumentation/firecrawl/firecrawl.py +46 -20
  66. openlit/instrumentation/google_ai_studio/__init__.py +45 -10
  67. openlit/instrumentation/google_ai_studio/async_google_ai_studio.py +67 -44
  68. openlit/instrumentation/google_ai_studio/google_ai_studio.py +67 -44
  69. openlit/instrumentation/google_ai_studio/utils.py +180 -67
  70. openlit/instrumentation/gpt4all/__init__.py +22 -7
  71. openlit/instrumentation/gpt4all/gpt4all.py +67 -29
  72. openlit/instrumentation/gpt4all/utils.py +285 -61
  73. openlit/instrumentation/gpu/__init__.py +128 -47
  74. openlit/instrumentation/groq/__init__.py +21 -4
  75. openlit/instrumentation/groq/async_groq.py +33 -21
  76. openlit/instrumentation/groq/groq.py +33 -21
  77. openlit/instrumentation/groq/utils.py +192 -55
  78. openlit/instrumentation/haystack/__init__.py +70 -24
  79. openlit/instrumentation/haystack/async_haystack.py +28 -6
  80. openlit/instrumentation/haystack/haystack.py +28 -6
  81. openlit/instrumentation/haystack/utils.py +196 -74
  82. openlit/instrumentation/julep/__init__.py +69 -19
  83. openlit/instrumentation/julep/async_julep.py +53 -27
  84. openlit/instrumentation/julep/julep.py +53 -28
  85. openlit/instrumentation/langchain/__init__.py +74 -63
  86. openlit/instrumentation/langchain/callback_handler.py +1100 -0
  87. openlit/instrumentation/langchain_community/__init__.py +13 -2
  88. openlit/instrumentation/langchain_community/async_langchain_community.py +23 -5
  89. openlit/instrumentation/langchain_community/langchain_community.py +23 -5
  90. openlit/instrumentation/langchain_community/utils.py +35 -9
  91. openlit/instrumentation/letta/__init__.py +68 -15
  92. openlit/instrumentation/letta/letta.py +99 -54
  93. openlit/instrumentation/litellm/__init__.py +43 -14
  94. openlit/instrumentation/litellm/async_litellm.py +51 -26
  95. openlit/instrumentation/litellm/litellm.py +51 -26
  96. openlit/instrumentation/litellm/utils.py +312 -101
  97. openlit/instrumentation/llamaindex/__init__.py +267 -90
  98. openlit/instrumentation/llamaindex/async_llamaindex.py +28 -6
  99. openlit/instrumentation/llamaindex/llamaindex.py +28 -6
  100. openlit/instrumentation/llamaindex/utils.py +204 -91
  101. openlit/instrumentation/mem0/__init__.py +11 -2
  102. openlit/instrumentation/mem0/mem0.py +50 -29
  103. openlit/instrumentation/milvus/__init__.py +10 -2
  104. openlit/instrumentation/milvus/milvus.py +31 -6
  105. openlit/instrumentation/milvus/utils.py +166 -67
  106. openlit/instrumentation/mistral/__init__.py +63 -18
  107. openlit/instrumentation/mistral/async_mistral.py +63 -24
  108. openlit/instrumentation/mistral/mistral.py +63 -24
  109. openlit/instrumentation/mistral/utils.py +277 -69
  110. openlit/instrumentation/multion/__init__.py +69 -19
  111. openlit/instrumentation/multion/async_multion.py +57 -26
  112. openlit/instrumentation/multion/multion.py +57 -26
  113. openlit/instrumentation/ollama/__init__.py +39 -18
  114. openlit/instrumentation/ollama/async_ollama.py +57 -26
  115. openlit/instrumentation/ollama/ollama.py +57 -26
  116. openlit/instrumentation/ollama/utils.py +226 -50
  117. openlit/instrumentation/openai/__init__.py +156 -32
  118. openlit/instrumentation/openai/async_openai.py +147 -67
  119. openlit/instrumentation/openai/openai.py +150 -67
  120. openlit/instrumentation/openai/utils.py +660 -186
  121. openlit/instrumentation/openai_agents/__init__.py +6 -2
  122. openlit/instrumentation/openai_agents/processor.py +409 -537
  123. openlit/instrumentation/phidata/__init__.py +13 -5
  124. openlit/instrumentation/phidata/phidata.py +67 -32
  125. openlit/instrumentation/pinecone/__init__.py +48 -9
  126. openlit/instrumentation/pinecone/async_pinecone.py +27 -5
  127. openlit/instrumentation/pinecone/pinecone.py +27 -5
  128. openlit/instrumentation/pinecone/utils.py +153 -47
  129. openlit/instrumentation/premai/__init__.py +22 -7
  130. openlit/instrumentation/premai/premai.py +51 -26
  131. openlit/instrumentation/premai/utils.py +246 -59
  132. openlit/instrumentation/pydantic_ai/__init__.py +49 -22
  133. openlit/instrumentation/pydantic_ai/pydantic_ai.py +69 -16
  134. openlit/instrumentation/pydantic_ai/utils.py +89 -24
  135. openlit/instrumentation/qdrant/__init__.py +19 -4
  136. openlit/instrumentation/qdrant/async_qdrant.py +33 -7
  137. openlit/instrumentation/qdrant/qdrant.py +33 -7
  138. openlit/instrumentation/qdrant/utils.py +228 -93
  139. openlit/instrumentation/reka/__init__.py +23 -10
  140. openlit/instrumentation/reka/async_reka.py +17 -11
  141. openlit/instrumentation/reka/reka.py +17 -11
  142. openlit/instrumentation/reka/utils.py +138 -36
  143. openlit/instrumentation/together/__init__.py +44 -12
  144. openlit/instrumentation/together/async_together.py +50 -27
  145. openlit/instrumentation/together/together.py +50 -27
  146. openlit/instrumentation/together/utils.py +301 -71
  147. openlit/instrumentation/transformers/__init__.py +2 -1
  148. openlit/instrumentation/transformers/transformers.py +13 -3
  149. openlit/instrumentation/transformers/utils.py +139 -36
  150. openlit/instrumentation/vertexai/__init__.py +81 -16
  151. openlit/instrumentation/vertexai/async_vertexai.py +33 -15
  152. openlit/instrumentation/vertexai/utils.py +123 -27
  153. openlit/instrumentation/vertexai/vertexai.py +33 -15
  154. openlit/instrumentation/vllm/__init__.py +12 -5
  155. openlit/instrumentation/vllm/utils.py +121 -31
  156. openlit/instrumentation/vllm/vllm.py +16 -10
  157. openlit/otel/events.py +35 -10
  158. openlit/otel/metrics.py +32 -24
  159. openlit/otel/tracing.py +24 -9
  160. openlit/semcov/__init__.py +101 -7
  161. {openlit-1.34.29.dist-info → openlit-1.34.31.dist-info}/METADATA +2 -1
  162. openlit-1.34.31.dist-info/RECORD +166 -0
  163. openlit/instrumentation/langchain/async_langchain.py +0 -102
  164. openlit/instrumentation/langchain/langchain.py +0 -102
  165. openlit/instrumentation/langchain/utils.py +0 -252
  166. openlit-1.34.29.dist-info/RECORD +0 -166
  167. {openlit-1.34.29.dist-info → openlit-1.34.31.dist-info}/LICENSE +0 -0
  168. {openlit-1.34.29.dist-info → openlit-1.34.31.dist-info}/WHEEL +0 -0
@@ -6,12 +6,11 @@ import importlib.metadata
6
6
  from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
7
7
  from wrapt import wrap_function_wrapper
8
8
 
9
- from openlit.instrumentation.firecrawl.firecrawl import (
10
- wrap_crawl
11
- )
9
+ from openlit.instrumentation.firecrawl.firecrawl import wrap_crawl
12
10
 
13
11
  _instruments = ("firecrawl-py >= 1.6.3",)
14
12
 
13
+
15
14
  class FireCrawlInstrumentor(BaseInstrumentor):
16
15
  """
17
16
  An instrumentor for firecrawl's client library.
@@ -33,15 +32,33 @@ class FireCrawlInstrumentor(BaseInstrumentor):
33
32
  wrap_function_wrapper(
34
33
  "firecrawl.firecrawl",
35
34
  "FirecrawlApp.scrape_url",
36
- wrap_crawl("firecrawl.scrape_url", version, environment, application_name,
37
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
35
+ wrap_crawl(
36
+ "firecrawl.scrape_url",
37
+ version,
38
+ environment,
39
+ application_name,
40
+ tracer,
41
+ pricing_info,
42
+ capture_message_content,
43
+ metrics,
44
+ disable_metrics,
45
+ ),
38
46
  )
39
47
 
40
48
  wrap_function_wrapper(
41
49
  "firecrawl.firecrawl",
42
50
  "FirecrawlApp.crawl_url",
43
- wrap_crawl("firecrawl.crawl_url", version, environment, application_name,
44
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
51
+ wrap_crawl(
52
+ "firecrawl.crawl_url",
53
+ version,
54
+ environment,
55
+ application_name,
56
+ tracer,
57
+ pricing_info,
58
+ capture_message_content,
59
+ metrics,
60
+ disable_metrics,
61
+ ),
45
62
  )
46
63
 
47
64
  def _uninstrument(self, **kwargs):
@@ -5,7 +5,11 @@ Module for monitoring FireCrawl calls.
5
5
 
6
6
  import logging
7
7
  from opentelemetry.trace import SpanKind, Status, StatusCode
8
- from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
8
+ from opentelemetry.sdk.resources import (
9
+ SERVICE_NAME,
10
+ TELEMETRY_SDK_NAME,
11
+ DEPLOYMENT_ENVIRONMENT,
12
+ )
9
13
  from openlit.__helpers import (
10
14
  handle_exception,
11
15
  )
@@ -14,8 +18,18 @@ from openlit.semcov import SemanticConvention
14
18
  # Initialize logger for logging potential issues and operations
15
19
  logger = logging.getLogger(__name__)
16
20
 
17
- def wrap_crawl(gen_ai_endpoint, version, environment, application_name,
18
- tracer, pricing_info, capture_message_content, metrics, disable_metrics):
21
+
22
+ def wrap_crawl(
23
+ gen_ai_endpoint,
24
+ version,
25
+ environment,
26
+ application_name,
27
+ tracer,
28
+ pricing_info,
29
+ capture_message_content,
30
+ metrics,
31
+ disable_metrics,
32
+ ):
19
33
  """
20
34
  Generates a telemetry wrapper for chat completions to collect metrics.
21
35
 
@@ -50,28 +64,40 @@ def wrap_crawl(gen_ai_endpoint, version, environment, application_name,
50
64
  """
51
65
 
52
66
  # pylint: disable=line-too-long
53
- with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
67
+ with tracer.start_as_current_span(
68
+ gen_ai_endpoint, kind=SpanKind.CLIENT
69
+ ) as span:
54
70
  response = wrapped(*args, **kwargs)
55
71
 
56
72
  try:
57
73
  # Set base span attribues
58
74
  span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
59
- span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
60
- SemanticConvention.GEN_AI_SYSTEM_FIRECRAWL)
61
- span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
62
- SemanticConvention.GEN_AI_OPERATION_TYPE_AGENT)
63
- span.set_attribute(SemanticConvention.GEN_AI_ENDPOINT,
64
- gen_ai_endpoint)
65
- span.set_attribute(SERVICE_NAME,
66
- application_name)
67
- span.set_attribute(DEPLOYMENT_ENVIRONMENT,
68
- environment)
69
- span.set_attribute(SemanticConvention.GEN_AI_AGENT_TYPE,
70
- SemanticConvention.GEN_AI_AGENT_TYPE_BROWSER)
71
- span.set_attribute(SemanticConvention.GEN_AI_AGENT_PARAMS,
72
- str(kwargs.get("params")))
73
-
74
- url = kwargs.get("url") if "url" in kwargs else str(args[0]) if args else None
75
+ span.set_attribute(
76
+ SemanticConvention.GEN_AI_SYSTEM,
77
+ SemanticConvention.GEN_AI_SYSTEM_FIRECRAWL,
78
+ )
79
+ span.set_attribute(
80
+ SemanticConvention.GEN_AI_OPERATION,
81
+ SemanticConvention.GEN_AI_OPERATION_TYPE_AGENT,
82
+ )
83
+ span.set_attribute(SemanticConvention.GEN_AI_ENDPOINT, gen_ai_endpoint)
84
+ span.set_attribute(SERVICE_NAME, application_name)
85
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT, environment)
86
+ span.set_attribute(
87
+ SemanticConvention.GEN_AI_AGENT_TYPE,
88
+ SemanticConvention.GEN_AI_AGENT_TYPE_BROWSER,
89
+ )
90
+ span.set_attribute(
91
+ SemanticConvention.GEN_AI_AGENT_PARAMS, str(kwargs.get("params"))
92
+ )
93
+
94
+ url = (
95
+ kwargs.get("url")
96
+ if "url" in kwargs
97
+ else str(args[0])
98
+ if args
99
+ else None
100
+ )
75
101
  if url is not None:
76
102
  span.set_attribute(SemanticConvention.GEN_AI_AGENT_BROWSE_URL, url)
77
103
 
@@ -6,15 +6,18 @@ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
6
6
  from wrapt import wrap_function_wrapper
7
7
 
8
8
  from openlit.instrumentation.google_ai_studio.google_ai_studio import (
9
- generate, generate_stream
9
+ generate,
10
+ generate_stream,
10
11
  )
11
12
 
12
13
  from openlit.instrumentation.google_ai_studio.async_google_ai_studio import (
13
- async_generate, async_generate_stream
14
+ async_generate,
15
+ async_generate_stream,
14
16
  )
15
17
 
16
18
  _instruments = ("google-genai >= 1.3.0",)
17
19
 
20
+
18
21
  class GoogleAIStudioInstrumentor(BaseInstrumentor):
19
22
  """
20
23
  An instrumentor for google-genai's client library.
@@ -37,32 +40,64 @@ class GoogleAIStudioInstrumentor(BaseInstrumentor):
37
40
  wrap_function_wrapper(
38
41
  "google.genai.models",
39
42
  "Models.generate_content",
40
- generate(version, environment, application_name,
41
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
43
+ generate(
44
+ version,
45
+ environment,
46
+ application_name,
47
+ tracer,
48
+ pricing_info,
49
+ capture_message_content,
50
+ metrics,
51
+ disable_metrics,
52
+ ),
42
53
  )
43
54
 
44
55
  # sync stream generate
45
56
  wrap_function_wrapper(
46
57
  "google.genai.models",
47
58
  "Models.generate_content_stream",
48
- generate_stream(version, environment, application_name,
49
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
59
+ generate_stream(
60
+ version,
61
+ environment,
62
+ application_name,
63
+ tracer,
64
+ pricing_info,
65
+ capture_message_content,
66
+ metrics,
67
+ disable_metrics,
68
+ ),
50
69
  )
51
70
 
52
71
  # async generate
53
72
  wrap_function_wrapper(
54
73
  "google.genai.models",
55
74
  "AsyncModels.generate_content",
56
- async_generate(version, environment, application_name,
57
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
75
+ async_generate(
76
+ version,
77
+ environment,
78
+ application_name,
79
+ tracer,
80
+ pricing_info,
81
+ capture_message_content,
82
+ metrics,
83
+ disable_metrics,
84
+ ),
58
85
  )
59
86
 
60
87
  # async stream generate
61
88
  wrap_function_wrapper(
62
89
  "google.genai.models",
63
90
  "AsyncModels.generate_content_stream",
64
- async_generate_stream(version, environment, application_name,
65
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
91
+ async_generate_stream(
92
+ version,
93
+ environment,
94
+ application_name,
95
+ tracer,
96
+ pricing_info,
97
+ capture_message_content,
98
+ metrics,
99
+ disable_metrics,
100
+ ),
66
101
  )
67
102
 
68
103
  def _uninstrument(self, **kwargs):
@@ -4,19 +4,25 @@ Module for monitoring Google AI Studio API calls.
4
4
 
5
5
  import time
6
6
  from opentelemetry.trace import SpanKind
7
- from openlit.__helpers import (
8
- handle_exception,
9
- set_server_address_and_port
10
- )
7
+ from openlit.__helpers import handle_exception, set_server_address_and_port
11
8
  from openlit.instrumentation.google_ai_studio.utils import (
12
9
  process_chat_response,
13
10
  process_chunk,
14
- process_streaming_chat_response
11
+ process_streaming_chat_response,
15
12
  )
16
13
  from openlit.semcov import SemanticConvention
17
14
 
18
- def async_generate(version, environment, application_name,
19
- tracer, pricing_info, capture_message_content, metrics, disable_metrics):
15
+
16
+ def async_generate(
17
+ version,
18
+ environment,
19
+ application_name,
20
+ tracer,
21
+ pricing_info,
22
+ capture_message_content,
23
+ metrics,
24
+ disable_metrics,
25
+ ):
20
26
  """
21
27
  Generates a telemetry wrapper for GenAI function call
22
28
  """
@@ -26,7 +32,9 @@ def async_generate(version, environment, application_name,
26
32
  Wraps the GenAI function call.
27
33
  """
28
34
 
29
- server_address, server_port = set_server_address_and_port(instance, "generativelanguage.googleapis.com", 443)
35
+ server_address, server_port = set_server_address_and_port(
36
+ instance, "generativelanguage.googleapis.com", 443
37
+ )
30
38
  request_model = kwargs.get("model", "gemini-2.0-flash")
31
39
 
32
40
  span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
@@ -37,22 +45,22 @@ def async_generate(version, environment, application_name,
37
45
 
38
46
  try:
39
47
  response = process_chat_response(
40
- instance = instance,
41
- response=response,
42
- request_model=request_model,
43
- pricing_info=pricing_info,
44
- server_port=server_port,
45
- server_address=server_address,
46
- environment=environment,
47
- application_name=application_name,
48
- metrics=metrics,
49
- start_time=start_time,
50
- span=span,
51
- args=args,
52
- kwargs=kwargs,
53
- capture_message_content=capture_message_content,
54
- disable_metrics=disable_metrics,
55
- version=version,
48
+ instance=instance,
49
+ response=response,
50
+ request_model=request_model,
51
+ pricing_info=pricing_info,
52
+ server_port=server_port,
53
+ server_address=server_address,
54
+ environment=environment,
55
+ application_name=application_name,
56
+ metrics=metrics,
57
+ start_time=start_time,
58
+ span=span,
59
+ args=args,
60
+ kwargs=kwargs,
61
+ capture_message_content=capture_message_content,
62
+ disable_metrics=disable_metrics,
63
+ version=version,
56
64
  )
57
65
 
58
66
  except Exception as e:
@@ -63,8 +71,17 @@ def async_generate(version, environment, application_name,
63
71
 
64
72
  return wrapper
65
73
 
66
- def async_generate_stream(version, environment, application_name,
67
- tracer, pricing_info, capture_message_content, metrics, disable_metrics):
74
+
75
+ def async_generate_stream(
76
+ version,
77
+ environment,
78
+ application_name,
79
+ tracer,
80
+ pricing_info,
81
+ capture_message_content,
82
+ metrics,
83
+ disable_metrics,
84
+ ):
68
85
  """
69
86
  Generates a telemetry wrapper for GenAI function call
70
87
  """
@@ -75,23 +92,23 @@ def async_generate_stream(version, environment, application_name,
75
92
  """
76
93
 
77
94
  def __init__(
78
- self,
79
- wrapped,
80
- span,
81
- span_name,
82
- kwargs,
83
- server_address,
84
- server_port,
85
- **args,
86
- ):
95
+ self,
96
+ wrapped,
97
+ span,
98
+ span_name,
99
+ kwargs,
100
+ server_address,
101
+ server_port,
102
+ **args,
103
+ ):
87
104
  self.__wrapped__ = wrapped
88
105
  self._span = span
89
106
  self._span_name = span_name
90
- self._llmresponse = ''
91
- self._finish_reason = ''
92
- self._output_tokens = ''
93
- self._input_tokens = ''
94
- self._response_model = ''
107
+ self._llmresponse = ""
108
+ self._finish_reason = ""
109
+ self._output_tokens = ""
110
+ self._input_tokens = ""
111
+ self._response_model = ""
95
112
  self._tools = None
96
113
 
97
114
  self._args = args
@@ -125,7 +142,9 @@ def async_generate_stream(version, environment, application_name,
125
142
  return chunk
126
143
  except StopAsyncIteration:
127
144
  try:
128
- with tracer.start_as_current_span(self._span_name, kind= SpanKind.CLIENT) as self._span:
145
+ with tracer.start_as_current_span(
146
+ self._span_name, kind=SpanKind.CLIENT
147
+ ) as self._span:
129
148
  process_streaming_chat_response(
130
149
  self,
131
150
  pricing_info=pricing_info,
@@ -134,7 +153,7 @@ def async_generate_stream(version, environment, application_name,
134
153
  metrics=metrics,
135
154
  capture_message_content=capture_message_content,
136
155
  disable_metrics=disable_metrics,
137
- version=version
156
+ version=version,
138
157
  )
139
158
 
140
159
  except Exception as e:
@@ -146,7 +165,9 @@ def async_generate_stream(version, environment, application_name,
146
165
  Wraps the GenAI function call.
147
166
  """
148
167
 
149
- server_address, server_port = set_server_address_and_port(instance, "generativelanguage.googleapis.com", 443)
168
+ server_address, server_port = set_server_address_and_port(
169
+ instance, "generativelanguage.googleapis.com", 443
170
+ )
150
171
  request_model = kwargs.get("model", "gemini-2.0-flash")
151
172
 
152
173
  span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
@@ -154,6 +175,8 @@ def async_generate_stream(version, environment, application_name,
154
175
  awaited_wrapped = await wrapped(*args, **kwargs)
155
176
  span = tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT)
156
177
 
157
- return TracedAsyncStream(awaited_wrapped, span, span_name, kwargs, server_address, server_port)
178
+ return TracedAsyncStream(
179
+ awaited_wrapped, span, span_name, kwargs, server_address, server_port
180
+ )
158
181
 
159
182
  return wrapper
@@ -4,19 +4,25 @@ Module for monitoring Google AI Studio API calls.
4
4
 
5
5
  import time
6
6
  from opentelemetry.trace import SpanKind
7
- from openlit.__helpers import (
8
- handle_exception,
9
- set_server_address_and_port
10
- )
7
+ from openlit.__helpers import handle_exception, set_server_address_and_port
11
8
  from openlit.instrumentation.google_ai_studio.utils import (
12
9
  process_chat_response,
13
10
  process_chunk,
14
- process_streaming_chat_response
11
+ process_streaming_chat_response,
15
12
  )
16
13
  from openlit.semcov import SemanticConvention
17
14
 
18
- def generate(version, environment, application_name,
19
- tracer, pricing_info, capture_message_content, metrics, disable_metrics):
15
+
16
+ def generate(
17
+ version,
18
+ environment,
19
+ application_name,
20
+ tracer,
21
+ pricing_info,
22
+ capture_message_content,
23
+ metrics,
24
+ disable_metrics,
25
+ ):
20
26
  """
21
27
  Generates a telemetry wrapper for GenAI function call
22
28
  """
@@ -26,7 +32,9 @@ def generate(version, environment, application_name,
26
32
  Wraps the GenAI function call.
27
33
  """
28
34
 
29
- server_address, server_port = set_server_address_and_port(instance, "generativelanguage.googleapis.com", 443)
35
+ server_address, server_port = set_server_address_and_port(
36
+ instance, "generativelanguage.googleapis.com", 443
37
+ )
30
38
  request_model = kwargs.get("model", "gemini-2.0-flash")
31
39
 
32
40
  span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
@@ -37,22 +45,22 @@ def generate(version, environment, application_name,
37
45
 
38
46
  try:
39
47
  response = process_chat_response(
40
- instance = instance,
41
- response=response,
42
- request_model=request_model,
43
- pricing_info=pricing_info,
44
- server_port=server_port,
45
- server_address=server_address,
46
- environment=environment,
47
- application_name=application_name,
48
- metrics=metrics,
49
- start_time=start_time,
50
- span=span,
51
- args=args,
52
- kwargs=kwargs,
53
- capture_message_content=capture_message_content,
54
- disable_metrics=disable_metrics,
55
- version=version,
48
+ instance=instance,
49
+ response=response,
50
+ request_model=request_model,
51
+ pricing_info=pricing_info,
52
+ server_port=server_port,
53
+ server_address=server_address,
54
+ environment=environment,
55
+ application_name=application_name,
56
+ metrics=metrics,
57
+ start_time=start_time,
58
+ span=span,
59
+ args=args,
60
+ kwargs=kwargs,
61
+ capture_message_content=capture_message_content,
62
+ disable_metrics=disable_metrics,
63
+ version=version,
56
64
  )
57
65
 
58
66
  except Exception as e:
@@ -63,8 +71,17 @@ def generate(version, environment, application_name,
63
71
 
64
72
  return wrapper
65
73
 
66
- def generate_stream(version, environment, application_name,
67
- tracer, pricing_info, capture_message_content, metrics, disable_metrics):
74
+
75
+ def generate_stream(
76
+ version,
77
+ environment,
78
+ application_name,
79
+ tracer,
80
+ pricing_info,
81
+ capture_message_content,
82
+ metrics,
83
+ disable_metrics,
84
+ ):
68
85
  """
69
86
  Generates a telemetry wrapper for GenAI function call
70
87
  """
@@ -75,23 +92,23 @@ def generate_stream(version, environment, application_name,
75
92
  """
76
93
 
77
94
  def __init__(
78
- self,
79
- wrapped,
80
- span,
81
- span_name,
82
- kwargs,
83
- server_address,
84
- server_port,
85
- **args,
86
- ):
95
+ self,
96
+ wrapped,
97
+ span,
98
+ span_name,
99
+ kwargs,
100
+ server_address,
101
+ server_port,
102
+ **args,
103
+ ):
87
104
  self.__wrapped__ = wrapped
88
105
  self._span = span
89
106
  self._span_name = span_name
90
- self._llmresponse = ''
91
- self._finish_reason = ''
92
- self._output_tokens = ''
93
- self._input_tokens = ''
94
- self._response_model = ''
107
+ self._llmresponse = ""
108
+ self._finish_reason = ""
109
+ self._output_tokens = ""
110
+ self._input_tokens = ""
111
+ self._response_model = ""
95
112
  self._tools = None
96
113
 
97
114
  self._args = args
@@ -125,7 +142,9 @@ def generate_stream(version, environment, application_name,
125
142
  return chunk
126
143
  except StopIteration:
127
144
  try:
128
- with tracer.start_as_current_span(self._span_name, kind= SpanKind.CLIENT) as self._span:
145
+ with tracer.start_as_current_span(
146
+ self._span_name, kind=SpanKind.CLIENT
147
+ ) as self._span:
129
148
  process_streaming_chat_response(
130
149
  self,
131
150
  pricing_info=pricing_info,
@@ -134,7 +153,7 @@ def generate_stream(version, environment, application_name,
134
153
  metrics=metrics,
135
154
  capture_message_content=capture_message_content,
136
155
  disable_metrics=disable_metrics,
137
- version=version
156
+ version=version,
138
157
  )
139
158
 
140
159
  except Exception as e:
@@ -146,7 +165,9 @@ def generate_stream(version, environment, application_name,
146
165
  Wraps the GenAI function call.
147
166
  """
148
167
 
149
- server_address, server_port = set_server_address_and_port(instance, "generativelanguage.googleapis.com", 443)
168
+ server_address, server_port = set_server_address_and_port(
169
+ instance, "generativelanguage.googleapis.com", 443
170
+ )
150
171
  request_model = kwargs.get("model", "gemini-2.0-flash")
151
172
 
152
173
  span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
@@ -154,6 +175,8 @@ def generate_stream(version, environment, application_name,
154
175
  awaited_wrapped = wrapped(*args, **kwargs)
155
176
  span = tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT)
156
177
 
157
- return TracedSyncStream(awaited_wrapped, span, span_name, kwargs, server_address, server_port)
178
+ return TracedSyncStream(
179
+ awaited_wrapped, span, span_name, kwargs, server_address, server_port
180
+ )
158
181
 
159
182
  return wrapper