langtrace-python-sdk 2.1.11__py3-none-any.whl → 2.1.12__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.
@@ -48,14 +48,19 @@ class LangTraceExporter(SpanExporter):
48
48
  """
49
49
 
50
50
  api_key: str
51
+ api_host: str
51
52
 
52
53
  def __init__(
53
54
  self,
55
+ api_host,
54
56
  api_key: str = None,
55
- api_host: typing.Optional[str] = None,
56
57
  ) -> None:
57
58
  self.api_key = api_key or os.environ.get("LANGTRACE_API_KEY")
58
- self.api_host: str = api_host or LANGTRACE_REMOTE_URL
59
+ self.api_host = (
60
+ f"{LANGTRACE_REMOTE_URL}/api/trace"
61
+ if api_host == LANGTRACE_REMOTE_URL
62
+ else api_host
63
+ )
59
64
 
60
65
  def export(self, spans: typing.Sequence[ReadableSpan]) -> SpanExportResult:
61
66
  """
@@ -90,7 +95,7 @@ class LangTraceExporter(SpanExporter):
90
95
  # Send data to remote URL
91
96
  try:
92
97
  response = requests.post(
93
- url=f"{self.api_host}/api/trace",
98
+ url=f"{self.api_host}",
94
99
  data=json.dumps(data),
95
100
  headers={"Content-Type": "application/json", "x-api-key": self.api_key},
96
101
  timeout=20,
@@ -16,6 +16,9 @@ limitations under the License.
16
16
 
17
17
  from typing import Optional
18
18
 
19
+ from langtrace_python_sdk.constants.exporter.langtrace_exporter import (
20
+ LANGTRACE_REMOTE_URL,
21
+ )
19
22
  from langtrace_python_sdk.types import DisableInstrumentations, InstrumentationType
20
23
  from opentelemetry import trace
21
24
  from opentelemetry.sdk.trace import TracerProvider
@@ -46,6 +49,7 @@ from langtrace_python_sdk.instrumentation import (
46
49
  from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
47
50
  from colorama import Fore
48
51
  from langtrace_python_sdk.utils import check_if_sdk_is_outdated
52
+ import os
49
53
 
50
54
 
51
55
  def init(
@@ -53,15 +57,19 @@ def init(
53
57
  batch: bool = True,
54
58
  write_spans_to_console: bool = False,
55
59
  custom_remote_exporter=None,
56
- api_host: Optional[str] = None,
60
+ api_host: Optional[str] = LANGTRACE_REMOTE_URL,
57
61
  disable_instrumentations: Optional[DisableInstrumentations] = None,
58
62
  ):
63
+
64
+ host = (
65
+ os.environ.get("LANGTRACE_API_HOST", None) or api_host or LANGTRACE_REMOTE_URL
66
+ )
59
67
  check_if_sdk_is_outdated()
60
68
  print(Fore.GREEN + "Initializing Langtrace SDK.." + Fore.RESET)
61
69
  provider = TracerProvider(resource=Resource.create({"service.name": sys.argv[0]}))
62
70
 
63
71
  remote_write_exporter = (
64
- LangTraceExporter(api_key=api_key, api_host=api_host)
72
+ LangTraceExporter(api_key=api_key, api_host=host)
65
73
  if custom_remote_exporter is None
66
74
  else custom_remote_exporter
67
75
  )
@@ -70,6 +78,7 @@ def init(
70
78
  simple_processor_remote = SimpleSpanProcessor(remote_write_exporter)
71
79
  simple_processor_console = SimpleSpanProcessor(console_exporter)
72
80
 
81
+ os.environ["LANGTRACE_API_HOST"] = host.replace("/api/trace", "")
73
82
  # Initialize tracer
74
83
  trace.set_tracer_provider(provider)
75
84
  all_instrumentations = {
@@ -101,8 +110,8 @@ def init(
101
110
  else:
102
111
  provider.add_span_processor(simple_processor_remote)
103
112
 
104
- elif api_host is not None:
105
- print(Fore.BLUE + f"Exporting spans to custom host: {api_host}.." + Fore.RESET)
113
+ elif host != LANGTRACE_REMOTE_URL:
114
+ print(Fore.BLUE + f"Exporting spans to custom host: {host}.." + Fore.RESET)
106
115
  if batch:
107
116
  provider.add_span_processor(batch_processor_remote)
108
117
  else:
@@ -1,7 +1,4 @@
1
1
  import os
2
- from langtrace_python_sdk.constants.exporter.langtrace_exporter import (
3
- LANGTRACE_REMOTE_URL,
4
- )
5
2
  import requests
6
3
  from urllib.parse import urlencode
7
4
  from typing import Optional, TypedDict, Dict, List
@@ -59,7 +56,7 @@ def get_prompt_from_registry(
59
56
  print(query_params)
60
57
  # Make the GET request to the API
61
58
  response = requests.get(
62
- f"{LANGTRACE_REMOTE_URL}/api/promptset?{query_string}",
59
+ f"{os.environ['LANGTRACE_API_HOST']}/api/promptset?{query_string}",
63
60
  headers=headers,
64
61
  timeout=None,
65
62
  )
@@ -118,9 +118,7 @@ class SendUserFeedback:
118
118
  _langtrace_api_key: str
119
119
 
120
120
  def __init__(self):
121
- self._langtrace_host = os.environ.get(
122
- "LANGTRACE_API_HOST", LANGTRACE_REMOTE_URL
123
- )
121
+ self._langtrace_host = os.environ["LANGTRACE_API_HOST"]
124
122
  self._langtrace_api_key = os.environ.get("LANGTRACE_API_KEY", None)
125
123
 
126
124
  def evaluate(self, data: EvaluationAPIData) -> None:
@@ -137,6 +135,7 @@ class SendUserFeedback:
137
135
  headers = {"x-api-key": self._langtrace_api_key}
138
136
  if evaluation is not None:
139
137
  # Make a PUT request to update the evaluation
138
+ print(Fore.BLUE + "Updating Feedback.." + Fore.RESET)
140
139
  response = requests.put(
141
140
  f"{self._langtrace_host}/api/evaluation",
142
141
  json=data,
@@ -147,6 +146,7 @@ class SendUserFeedback:
147
146
  response.raise_for_status()
148
147
 
149
148
  else:
149
+ print(Fore.BLUE + "Sending User Feedback.." + Fore.RESET)
150
150
  # Make a POST request to create a new evaluation
151
151
  response = requests.post(
152
152
  f"{self._langtrace_host}/api/evaluation",
@@ -1 +1 @@
1
- __version__ = "2.1.11"
1
+ __version__ = "2.1.12"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: langtrace-python-sdk
3
- Version: 2.1.11
3
+ Version: 2.1.12
4
4
  Summary: Python SDK for LangTrace
5
5
  Project-URL: Homepage, https://github.com/Scale3-Labs/langtrace-python-sdk
6
6
  Author-email: Scale3 Labs <engineering@scale3labs.com>
@@ -37,8 +37,8 @@ examples/qdrant_example/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG
37
37
  examples/qdrant_example/basic.py,sha256=DCMjHSuBZKkhEjCkwy5d5La9WMyW0lCWqtcZWiFCEm4,1425
38
38
  examples/weaviate_example/query_text.py,sha256=iE9OiHsibjsprbCGzabE03eZsGN06e6ym2iS1A9P3ig,64650
39
39
  langtrace_python_sdk/__init__.py,sha256=FuvyRuStRe_N2wo2SB2_ZQ0w7LGNIjV0lLi6S1IgGwY,958
40
- langtrace_python_sdk/langtrace.py,sha256=E2z-VCke4QnFiBm-Ivx7W571xN0vRH7r1raHl_sMz8w,6674
41
- langtrace_python_sdk/version.py,sha256=zcHMV6HbszEZFZ1gDEpbHxTYg8dJ5fCYdeDd-O6IPP4,23
40
+ langtrace_python_sdk/langtrace.py,sha256=pN-xJRXrtvJIenMOH0-xlNXcnqL9qMjg28SrW-PMRU0,6978
41
+ langtrace_python_sdk/version.py,sha256=2ZypnXz9pLMxwCwfHNJV9M24HPgZwt56lxlCb2BYeEA,23
42
42
  langtrace_python_sdk/constants/__init__.py,sha256=P8QvYwt5czUNDZsKS64vxm9Dc41ptGbuF1TFtAF6nv4,44
43
43
  langtrace_python_sdk/constants/exporter/langtrace_exporter.py,sha256=5MNjnAOg-4am78J3gVMH6FSwq5N8TOj72ugkhsw4vi0,46
44
44
  langtrace_python_sdk/constants/instrumentation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -52,7 +52,7 @@ langtrace_python_sdk/constants/instrumentation/pinecone.py,sha256=Xaqqw-xBO0JJLG
52
52
  langtrace_python_sdk/constants/instrumentation/qdrant.py,sha256=yL7BopNQTXW7L7Z-gVM2PdusKD7r9qqcATvczFd7NtQ,1999
53
53
  langtrace_python_sdk/constants/instrumentation/weaviate.py,sha256=Iytf2OpB_irZYEmvOQ7Pf483EdG5Bh59GxaBlXck0yY,1501
54
54
  langtrace_python_sdk/extensions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
55
- langtrace_python_sdk/extensions/langtrace_exporter.py,sha256=Fj--DzBr4AwTM_iS3lRz0NhqESEyTOZ3SBCA4OevFkE,4127
55
+ langtrace_python_sdk/extensions/langtrace_exporter.py,sha256=gWVRU2DlB4xjZ4ww7M63DaLiAN5zQ2k1HPrythmjEdo,4202
56
56
  langtrace_python_sdk/instrumentation/__init__.py,sha256=htP583cfv32IUvWeck6edRiPQxhk0uzUa1l1vgbtjtY,1042
57
57
  langtrace_python_sdk/instrumentation/anthropic/__init__.py,sha256=donrurJAGYlxrSRA3BIf76jGeUcAx9Tq8CVpah68S0Y,101
58
58
  langtrace_python_sdk/instrumentation/anthropic/instrumentation.py,sha256=-srgE8qumAn0ulQYZxMa8ch-9IBH0XgBW_rfEnGk6LI,1684
@@ -97,11 +97,11 @@ langtrace_python_sdk/types/__init__.py,sha256=-j8cuz3bhUdOqj7N2c0w5y-j3UmcxwEgNh
97
97
  langtrace_python_sdk/utils/__init__.py,sha256=E0nQyBE-4O_GR2PM9y_l7shx4hJLo5xRThR_LMx97M0,278
98
98
  langtrace_python_sdk/utils/llm.py,sha256=CiASOvObFvsN6T7ogWywNXfXGzI__u9misgolLxyeZk,2161
99
99
  langtrace_python_sdk/utils/misc.py,sha256=CD9NWRLxLpFd0YwlHJqzlpFNedXVWtAKGOjQWnDCo8k,838
100
- langtrace_python_sdk/utils/prompt_registry.py,sha256=7FFB4Pj0414qgf02h5zL5vXBZgNBf74g4Iq7GdFaIO0,2689
100
+ langtrace_python_sdk/utils/prompt_registry.py,sha256=-BNHX_UPAqBG1IdNUXZIA669M59wvFTyTvBifrFjy3k,2600
101
101
  langtrace_python_sdk/utils/sdk_version_checker.py,sha256=FzjIWZjn53cX0LEVPdipQd1fO9lG8iGVUEVUs9Hyk6M,1713
102
102
  langtrace_python_sdk/utils/silently_fail.py,sha256=F_9EteXCO9Cyq-8MA1OT2Zy_dx8n06nt31I7t7ui24E,478
103
103
  langtrace_python_sdk/utils/types.py,sha256=l-N6o7cnWUyrD6dBvW7W3Pf5CkPo5QaoT__k1XLbrQg,383
104
- langtrace_python_sdk/utils/with_root_span.py,sha256=wORIk9N4BOWEP9zoDMXpD3qX4r6P6sDMUn9bzl8BbvM,6754
104
+ langtrace_python_sdk/utils/with_root_span.py,sha256=ALe9AN7Ww8dSfJMqO_-XLpXcmw2FYr76vDNdadmldo8,6850
105
105
  tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
106
106
  tests/conftest.py,sha256=0Jo6iCZTXbdvyJVhG9UpYGkLabL75378oauCzmt-Sa8,603
107
107
  tests/utils.py,sha256=hP8sTH-M8WO6zlLkSFHPf6483ZcKEcnxul6JIIb1pLM,1396
@@ -138,7 +138,7 @@ tests/pinecone/cassettes/test_query.yaml,sha256=b5v9G3ssUy00oG63PlFUR3JErF2Js-5A
138
138
  tests/pinecone/cassettes/test_upsert.yaml,sha256=neWmQ1v3d03V8WoLl8FoFeeCYImb8pxlJBWnFd_lITU,38607
139
139
  tests/qdrant/conftest.py,sha256=9n0uHxxIjWk9fbYc4bx-uP8lSAgLBVx-cV9UjnsyCHM,381
140
140
  tests/qdrant/test_qdrant.py,sha256=pzjAjVY2kmsmGfrI2Gs2xrolfuaNHz7l1fqGQCjp5_o,3353
141
- langtrace_python_sdk-2.1.11.dist-info/METADATA,sha256=nEImkaBy426rcyy-Rn2YNFE3gYJgPF-EYYCrzmWvTTM,11860
142
- langtrace_python_sdk-2.1.11.dist-info/WHEEL,sha256=zEMcRr9Kr03x1ozGwg5v9NQBKn3kndp6LSoSlVg-jhU,87
143
- langtrace_python_sdk-2.1.11.dist-info/licenses/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
144
- langtrace_python_sdk-2.1.11.dist-info/RECORD,,
141
+ langtrace_python_sdk-2.1.12.dist-info/METADATA,sha256=Pg_yY_2SiEBShRlaXAHaTrLPcQtvPRkSmiu7EqIitKA,11860
142
+ langtrace_python_sdk-2.1.12.dist-info/WHEEL,sha256=zEMcRr9Kr03x1ozGwg5v9NQBKn3kndp6LSoSlVg-jhU,87
143
+ langtrace_python_sdk-2.1.12.dist-info/licenses/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
144
+ langtrace_python_sdk-2.1.12.dist-info/RECORD,,