langtrace-python-sdk 2.1.10__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.
- langtrace_python_sdk/extensions/langtrace_exporter.py +8 -3
- langtrace_python_sdk/langtrace.py +32 -25
- langtrace_python_sdk/utils/prompt_registry.py +1 -4
- langtrace_python_sdk/utils/with_root_span.py +3 -3
- langtrace_python_sdk/version.py +1 -1
- {langtrace_python_sdk-2.1.10.dist-info → langtrace_python_sdk-2.1.12.dist-info}/METADATA +1 -1
- {langtrace_python_sdk-2.1.10.dist-info → langtrace_python_sdk-2.1.12.dist-info}/RECORD +9 -9
- {langtrace_python_sdk-2.1.10.dist-info → langtrace_python_sdk-2.1.12.dist-info}/WHEEL +0 -0
- {langtrace_python_sdk-2.1.10.dist-info → langtrace_python_sdk-2.1.12.dist-info}/licenses/LICENSE +0 -0
|
@@ -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
|
|
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}
|
|
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] =
|
|
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=
|
|
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,30 +78,9 @@ def init(
|
|
|
70
78
|
simple_processor_remote = SimpleSpanProcessor(remote_write_exporter)
|
|
71
79
|
simple_processor_console = SimpleSpanProcessor(console_exporter)
|
|
72
80
|
|
|
73
|
-
|
|
74
|
-
print(Fore.BLUE + "Writing spans to console" + Fore.RESET)
|
|
75
|
-
provider.add_span_processor(simple_processor_console)
|
|
76
|
-
|
|
77
|
-
elif custom_remote_exporter is not None:
|
|
78
|
-
print(Fore.BLUE + "Exporting spans to custom remote exporter.." + Fore.RESET)
|
|
79
|
-
if batch:
|
|
80
|
-
provider.add_span_processor(batch_processor_remote)
|
|
81
|
-
else:
|
|
82
|
-
provider.add_span_processor(simple_processor_remote)
|
|
83
|
-
|
|
84
|
-
elif api_host is not None:
|
|
85
|
-
print(Fore.BLUE + f"Exporting spans to custom host: {api_host}.." + Fore.RESET)
|
|
86
|
-
if batch:
|
|
87
|
-
provider.add_span_processor(batch_processor_remote)
|
|
88
|
-
else:
|
|
89
|
-
provider.add_span_processor(simple_processor_remote)
|
|
90
|
-
else:
|
|
91
|
-
print(Fore.BLUE + "Exporting spans to Langtrace cloud.." + Fore.RESET)
|
|
92
|
-
provider.add_span_processor(batch_processor_remote)
|
|
93
|
-
|
|
81
|
+
os.environ["LANGTRACE_API_HOST"] = host.replace("/api/trace", "")
|
|
94
82
|
# Initialize tracer
|
|
95
83
|
trace.set_tracer_provider(provider)
|
|
96
|
-
|
|
97
84
|
all_instrumentations = {
|
|
98
85
|
"openai": OpenAIInstrumentation(),
|
|
99
86
|
"groq": GroqInstrumentation(),
|
|
@@ -112,13 +99,33 @@ def init(
|
|
|
112
99
|
}
|
|
113
100
|
|
|
114
101
|
init_instrumentations(disable_instrumentations, all_instrumentations)
|
|
102
|
+
if write_spans_to_console:
|
|
103
|
+
print(Fore.BLUE + "Writing spans to console" + Fore.RESET)
|
|
104
|
+
provider.add_span_processor(simple_processor_console)
|
|
105
|
+
|
|
106
|
+
elif custom_remote_exporter is not None:
|
|
107
|
+
print(Fore.BLUE + "Exporting spans to custom remote exporter.." + Fore.RESET)
|
|
108
|
+
if batch:
|
|
109
|
+
provider.add_span_processor(batch_processor_remote)
|
|
110
|
+
else:
|
|
111
|
+
provider.add_span_processor(simple_processor_remote)
|
|
112
|
+
|
|
113
|
+
elif host != LANGTRACE_REMOTE_URL:
|
|
114
|
+
print(Fore.BLUE + f"Exporting spans to custom host: {host}.." + Fore.RESET)
|
|
115
|
+
if batch:
|
|
116
|
+
provider.add_span_processor(batch_processor_remote)
|
|
117
|
+
else:
|
|
118
|
+
provider.add_span_processor(simple_processor_remote)
|
|
119
|
+
else:
|
|
120
|
+
print(Fore.BLUE + "Exporting spans to Langtrace cloud.." + Fore.RESET)
|
|
121
|
+
provider.add_span_processor(batch_processor_remote)
|
|
115
122
|
|
|
116
123
|
|
|
117
124
|
def init_instrumentations(
|
|
118
125
|
disable_instrumentations: DisableInstrumentations, all_instrumentations: dict
|
|
119
126
|
):
|
|
120
127
|
if disable_instrumentations is None:
|
|
121
|
-
for
|
|
128
|
+
for idx, (name, v) in enumerate(all_instrumentations.items()):
|
|
122
129
|
v.instrument()
|
|
123
130
|
else:
|
|
124
131
|
|
|
@@ -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"{
|
|
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
|
|
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",
|
langtrace_python_sdk/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "2.1.
|
|
1
|
+
__version__ = "2.1.12"
|
|
@@ -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=
|
|
41
|
-
langtrace_python_sdk/version.py,sha256=
|
|
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=
|
|
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
|
|
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=
|
|
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.
|
|
142
|
-
langtrace_python_sdk-2.1.
|
|
143
|
-
langtrace_python_sdk-2.1.
|
|
144
|
-
langtrace_python_sdk-2.1.
|
|
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,,
|
|
File without changes
|
{langtrace_python_sdk-2.1.10.dist-info → langtrace_python_sdk-2.1.12.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|