openlit 0.0.1__tar.gz → 0.0.2__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.
Files changed (30) hide show
  1. {openlit-0.0.1 → openlit-0.0.2}/PKG-INFO +1 -1
  2. {openlit-0.0.1 → openlit-0.0.2}/pyproject.toml +1 -1
  3. {openlit-0.0.1 → openlit-0.0.2}/src/openlit/__init__.py +40 -16
  4. {openlit-0.0.1 → openlit-0.0.2}/src/openlit/instrumentation/cohere/__init__.py +1 -1
  5. {openlit-0.0.1 → openlit-0.0.2}/src/openlit/instrumentation/cohere/cohere.py +12 -12
  6. {openlit-0.0.1 → openlit-0.0.2}/src/openlit/instrumentation/langchain/__init__.py +1 -2
  7. {openlit-0.0.1 → openlit-0.0.2}/LICENSE +0 -0
  8. {openlit-0.0.1 → openlit-0.0.2}/README.md +0 -0
  9. {openlit-0.0.1 → openlit-0.0.2}/src/openlit/__helpers.py +0 -0
  10. {openlit-0.0.1 → openlit-0.0.2}/src/openlit/instrumentation/anthropic/__init__.py +0 -0
  11. {openlit-0.0.1 → openlit-0.0.2}/src/openlit/instrumentation/anthropic/anthropic.py +0 -0
  12. {openlit-0.0.1 → openlit-0.0.2}/src/openlit/instrumentation/anthropic/async_anthropic.py +0 -0
  13. {openlit-0.0.1 → openlit-0.0.2}/src/openlit/instrumentation/chroma/__init__.py +0 -0
  14. {openlit-0.0.1 → openlit-0.0.2}/src/openlit/instrumentation/chroma/chroma.py +0 -0
  15. {openlit-0.0.1 → openlit-0.0.2}/src/openlit/instrumentation/langchain/langchain.py +0 -0
  16. {openlit-0.0.1 → openlit-0.0.2}/src/openlit/instrumentation/mistral/__init__.py +0 -0
  17. {openlit-0.0.1 → openlit-0.0.2}/src/openlit/instrumentation/mistral/async_mistral.py +0 -0
  18. {openlit-0.0.1 → openlit-0.0.2}/src/openlit/instrumentation/mistral/mistral.py +0 -0
  19. {openlit-0.0.1 → openlit-0.0.2}/src/openlit/instrumentation/openai/__init__.py +0 -0
  20. {openlit-0.0.1 → openlit-0.0.2}/src/openlit/instrumentation/openai/async_azure_openai.py +0 -0
  21. {openlit-0.0.1 → openlit-0.0.2}/src/openlit/instrumentation/openai/async_openai.py +0 -0
  22. {openlit-0.0.1 → openlit-0.0.2}/src/openlit/instrumentation/openai/azure_openai.py +0 -0
  23. {openlit-0.0.1 → openlit-0.0.2}/src/openlit/instrumentation/openai/openai.py +0 -0
  24. {openlit-0.0.1 → openlit-0.0.2}/src/openlit/instrumentation/pinecone/__init__.py +0 -0
  25. {openlit-0.0.1 → openlit-0.0.2}/src/openlit/instrumentation/pinecone/pinecone.py +0 -0
  26. {openlit-0.0.1 → openlit-0.0.2}/src/openlit/instrumentation/transformers/__init__.py +0 -0
  27. {openlit-0.0.1 → openlit-0.0.2}/src/openlit/instrumentation/transformers/transformers.py +0 -0
  28. {openlit-0.0.1 → openlit-0.0.2}/src/openlit/otel/metrics.py +0 -0
  29. {openlit-0.0.1 → openlit-0.0.2}/src/openlit/otel/tracing.py +0 -0
  30. {openlit-0.0.1 → openlit-0.0.2}/src/openlit/semcov/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: openlit
3
- Version: 0.0.1
3
+ Version: 0.0.2
4
4
  Summary: OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications, facilitating the integration of observability into your GenAI-driven projects
5
5
  Home-page: https://github.com/open-lit/openlit/tree/main/openlit/python
6
6
  Keywords: OpenTelemetry,otel,otlp,llm,tracing,openai,anthropic,claude,cohere,llm monitoring,observability,monitoring,gpt,Generative AI,chatGPT
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "openlit"
3
- version = "0.0.1"
3
+ version = "0.0.2"
4
4
  description = "OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications, facilitating the integration of observability into your GenAI-driven projects"
5
5
  authors = ["OpenLIT"]
6
6
  repository = "https://github.com/open-lit/openlit/tree/main/openlit/python"
@@ -3,8 +3,9 @@ The __init__.py module for the openLIT package.
3
3
  This module sets up the openLIT configuration and instrumentation for various
4
4
  large language models (LLMs).
5
5
  """
6
- from typing import Optional, Dict, Any
6
+ from typing import Dict
7
7
  import logging
8
+ from importlib.util import find_spec
8
9
 
9
10
  # Import internal modules for setting up tracing and fetching pricing info.
10
11
  from openlit.otel.tracing import setup_tracing
@@ -91,6 +92,30 @@ class OpenlitConfig:
91
92
  cls.trace_content = trace_content
92
93
  cls.disable_metrics = disable_metrics
93
94
 
95
+ def instrument_if_available(instrumentor_name, instrumentor_instance, config,
96
+ disabled_instrumentors, module_name_map):
97
+ """Instruments the specified instrumentor if its library is available."""
98
+ if instrumentor_name in disabled_instrumentors:
99
+ return
100
+
101
+ module_name = module_name_map.get(instrumentor_name)
102
+
103
+ if not module_name or find_spec(module_name) is not None:
104
+ try:
105
+ instrumentor_instance.instrument(
106
+ environment=config.environment,
107
+ application_name=config.application_name,
108
+ tracer=config.tracer,
109
+ pricing_info=config.pricing_info,
110
+ trace_content=config.trace_content,
111
+ metrics_dict=config.metrics_dict,
112
+ disable_metrics=config.disable_metrics
113
+ )
114
+
115
+ # pylint: disable=broad-exception-caught
116
+ except Exception as e:
117
+ logger.error("Failed to instrument %s: %s", instrumentor_name, e)
118
+
94
119
  def init(environment="default", application_name="default", tracer=None, otlp_endpoint=None,
95
120
  otlp_headers=None, disable_batch=False, trace_content=True, disabled_instrumentors=None,
96
121
  meter=None, disable_metrics=False):
@@ -115,12 +140,19 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
115
140
  disabled_instrumentors = disabled_instrumentors if disabled_instrumentors else []
116
141
 
117
142
  # Check for invalid instrumentor names
118
- valid_instruments = {
119
- "openai", "anthropic", "langchain",
120
- "cohere", "mistral", "chroma",
121
- "pinecone", "transformers"
143
+
144
+ module_name_map = {
145
+ "openai": "openai",
146
+ "anthropic": "anthropic",
147
+ "cohere": "cohere",
148
+ "mistral": "mistralai",
149
+ "langchain": "langchain",
150
+ "chroma": "chromadb",
151
+ "pinecone": "pincone",
152
+ "transformers": "transformers"
122
153
  }
123
- invalid_instrumentors = set(disabled_instrumentors) - valid_instruments
154
+
155
+ invalid_instrumentors = [name for name in disabled_instrumentors if name not in module_name_map]
124
156
  for invalid_name in invalid_instrumentors:
125
157
  logger.warning("Invalid instrumentor name detected and ignored: '%s'", invalid_name)
126
158
 
@@ -168,16 +200,8 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
168
200
 
169
201
  # Initialize and instrument only the enabled instrumentors
170
202
  for name, instrumentor in instrumentor_instances.items():
171
- if name not in disabled_instrumentors:
172
- instrumentor.instrument(
173
- environment=config.environment,
174
- application_name=config.application_name,
175
- tracer=config.tracer,
176
- pricing_info=config.pricing_info,
177
- trace_content=config.trace_content,
178
- metrics_dict=config.metrics_dict,
179
- disable_metrics=config.disable_metrics
180
- )
203
+ instrument_if_available(name, instrumentor, config,
204
+ disabled_instrumentors, module_name_map)
181
205
 
182
206
  # pylint: disable=broad-exception-caught
183
207
  except Exception as e:
@@ -7,7 +7,7 @@ from wrapt import wrap_function_wrapper
7
7
 
8
8
  from openlit.instrumentation.cohere.cohere import chat, chat_stream, embed
9
9
 
10
- _instruments = ("cohere >= 5.0.0",)
10
+ _instruments = ("cohere >= 5.3.2",)
11
11
 
12
12
  class CohereInstrumentor(BaseInstrumentor):
13
13
  """An instrumentor for Cohere's client library."""
@@ -173,8 +173,8 @@ def chat(gen_ai_endpoint, version, environment, application_name, tracer,
173
173
  # Calculate cost of the operation
174
174
  cost = get_chat_model_cost(kwargs.get("model", "command"),
175
175
  pricing_info,
176
- response.meta["billed_units"]["input_tokens"],
177
- response.meta["billed_units"]["output_tokens"])
176
+ response.meta.billed_units.input_tokens,
177
+ response.meta.billed_units.output_tokens)
178
178
 
179
179
  # Set Span attributes
180
180
  span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
@@ -207,12 +207,12 @@ def chat(gen_ai_endpoint, version, environment, application_name, tracer,
207
207
  span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
208
208
  response.response_id)
209
209
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
210
- response.meta["billed_units"]["input_tokens"])
210
+ response.meta.billed_units.input_tokens)
211
211
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
212
- response.meta["billed_units"]["output_tokens"])
212
+ response.meta.billed_units.output_tokens)
213
213
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
214
- response.meta["billed_units"]["input_tokens"] +
215
- response.meta["billed_units"]["output_tokens"])
214
+ response.meta.billed_units.input_tokens +
215
+ response.meta.billed_units.output_tokens)
216
216
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
217
217
  cost)
218
218
  if trace_content:
@@ -241,12 +241,12 @@ def chat(gen_ai_endpoint, version, environment, application_name, tracer,
241
241
 
242
242
  metrics["genai_requests"].add(1, attributes)
243
243
  metrics["genai_total_tokens"].add(
244
- response.meta["billed_units"]["input_tokens"] +
245
- response.meta["billed_units"]["output_tokens"], attributes)
244
+ response.meta.billed_units.input_tokens +
245
+ response.meta.billed_units.output_tokens, attributes)
246
246
  metrics["genai_completion_tokens"].add(
247
- response.meta["billed_units"]["output_tokens"], attributes)
247
+ response.meta.billed_units.output_tokens, attributes)
248
248
  metrics["genai_prompt_tokens"].add(
249
- response.meta["billed_units"]["input_tokens"], attributes)
249
+ response.meta.billed_units.input_tokens, attributes)
250
250
  metrics["genai_cost"].record(cost, attributes)
251
251
 
252
252
  # Return original response
@@ -307,8 +307,8 @@ def chat_stream(gen_ai_endpoint, version, environment, application_name,
307
307
  if event.event_type == "stream-end":
308
308
  llmresponse = event.response.text
309
309
  response_id = event.response.response_id
310
- prompt_tokens = event.response.meta["billed_units"]["input_tokens"]
311
- completion_tokens = event.response.meta["billed_units"]["output_tokens"]
310
+ prompt_tokens = event.response.meta.billed_units.input_tokens
311
+ completion_tokens = event.response.meta.billed_units.output_tokens
312
312
  finish_reason = event.finish_reason
313
313
  yield event
314
314
 
@@ -7,8 +7,7 @@ from wrapt import wrap_function_wrapper
7
7
 
8
8
  from openlit.instrumentation.langchain.langchain import general_wrap, hub
9
9
 
10
- _instruments = ("langchain >= 0.1.1", "langchain-openai >= 0.1.1",
11
- "langchain-core > 0.1.1", "langchain-community >= 0.0.31")
10
+ _instruments = ("langchain >= 0.1.1",)
12
11
 
13
12
  WRAPPED_METHODS = [
14
13
  {
File without changes
File without changes