Skip to content

Commit 01dc2af

Browse files
committed
add sentry integration
1 parent c2c7f5e commit 01dc2af

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
LANGTRACE_SDK_NAME = "langtrace-python-sdk"
2+
SENTRY_DSN = "https://[email protected]/4507929133056000"

src/langtrace_python_sdk/langtrace.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from typing import Optional
2020
import importlib.util
2121
from colorama import Fore
22+
from langtrace_python_sdk.constants import LANGTRACE_SDK_NAME, SENTRY_DSN
2223
from opentelemetry import trace
2324
from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
2425
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
@@ -60,8 +61,9 @@
6061
InstrumentationMethods,
6162
InstrumentationType,
6263
)
63-
from langtrace_python_sdk.utils import check_if_sdk_is_outdated
64+
from langtrace_python_sdk.utils import check_if_sdk_is_outdated, get_sdk_version
6465
from langtrace_python_sdk.utils.langtrace_sampler import LangtraceSampler
66+
import sentry_sdk
6567

6668

6769
def init(
@@ -164,6 +166,30 @@ def init(
164166
provider.add_span_processor(batch_processor_remote)
165167

166168
sys.stdout = sys.__stdout__
169+
if (
170+
os.environ.get("LANGTRACE_ERROR_REPORTING", "True") == "True"
171+
or os.environ.get("LANGTRACE_ERROR_REPORTING", "True") == "true"
172+
):
173+
sentry_sdk.init(
174+
dsn=SENTRY_DSN,
175+
traces_sample_rate=1.0,
176+
profiles_sample_rate=1.0,
177+
)
178+
sdk_options = {
179+
"service_name": os.environ.get("OTEL_SERVICE_NAME")
180+
or service_name
181+
or sys.argv[0],
182+
"disable_logging": disable_logging,
183+
"disable_instrumentations": disable_instrumentations,
184+
"disable_tracing_for_functions": disable_tracing_for_functions,
185+
"batch": batch,
186+
"write_spans_to_console": write_spans_to_console,
187+
"custom_remote_exporter": custom_remote_exporter,
188+
"sdk_name": LANGTRACE_SDK_NAME,
189+
"sdk_version": get_sdk_version(),
190+
"api_host": host,
191+
}
192+
sentry_sdk.set_context("sdk_init_options", sdk_options)
167193

168194

169195
def init_instrumentations(

src/langtrace_python_sdk/utils/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ def set_event_prompt(span: Span, prompt):
3131
def check_if_sdk_is_outdated():
3232
SDKVersionChecker().check()
3333
return
34+
35+
36+
def get_sdk_version():
37+
return SDKVersionChecker().get_sdk_version()

src/langtrace_python_sdk/utils/sdk_version_checker.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ def is_outdated(self):
4444
return self._current_version < latest_version
4545
return False
4646

47+
def get_sdk_version(self):
48+
return self._current_version
49+
4750
def check(self):
4851
if self.is_outdated():
4952
print(

0 commit comments

Comments
 (0)