Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ langtrace.init(custom_remote_exporter=<your_exporter>, batch=<True or False>)
| `api_host` | `Optional[str]` | `https://langtrace.ai/` | The API host for the remote exporter. |
| `disable_instrumentations` | `Optional[DisableInstrumentations]` | `None` | You can pass an object to disable instrumentation for specific vendors ex: `{'only': ['openai']}` or `{'all_except': ['openai']}` |

### Error Reporting to Langtrace

By default all sdk errors are reported to langtrace via Sentry. This can be disabled by setting the following enviroment variable to `False` like so `LANGTRACE_ERROR_REPORTING=False`

### Additional Customization

- `@with_langtrace_root_span` - this decorator is designed to organize and relate different spans, in a hierarchical manner. When you're performing multiple operations that you want to monitor together as a unit, this function helps by establishing a "parent" (`LangtraceRootSpan` or whatever is passed to `name`) span. Then, any calls to the LLM APIs made within the given function (fn) will be considered "children" of this parent span. This setup is especially useful for tracking the performance or behavior of a group of operations collectively, rather than individually.
Expand Down Expand Up @@ -229,6 +233,7 @@ prompt = get_prompt_from_registry(<Registry ID>, options={"prompt_version": 1, "
```

### Opt out of tracing prompt and completion data

By default, prompt and completion data are captured. If you would like to opt out of it, set the following env var,

`TRACE_PROMPT_COMPLETION_DATA=false`
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies = [
'sqlalchemy',
'fsspec>=2024.6.0',
"transformers>=4.11.3",
"sentry-sdk>=2.14.0",
]

requires-python = ">=3.9"
Expand Down
1 change: 1 addition & 0 deletions src/langtrace_python_sdk/constants/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
LANGTRACE_SDK_NAME = "langtrace-python-sdk"
SENTRY_DSN = "https://7f8eed3a1237fb2efef0f5e96ab407af@o1419498.ingest.us.sentry.io/4507929133056000"
25 changes: 24 additions & 1 deletion src/langtrace_python_sdk/langtrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from typing import Optional
import importlib.util
from colorama import Fore
from langtrace_python_sdk.constants import LANGTRACE_SDK_NAME, SENTRY_DSN
from opentelemetry import trace
from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
Expand Down Expand Up @@ -60,8 +61,9 @@
InstrumentationMethods,
InstrumentationType,
)
from langtrace_python_sdk.utils import check_if_sdk_is_outdated
from langtrace_python_sdk.utils import check_if_sdk_is_outdated, get_sdk_version
from langtrace_python_sdk.utils.langtrace_sampler import LangtraceSampler
import sentry_sdk


def init(
Expand Down Expand Up @@ -164,6 +166,27 @@ def init(
provider.add_span_processor(batch_processor_remote)

sys.stdout = sys.__stdout__
if os.environ.get("LANGTRACE_ERROR_REPORTING", "True") == "True":
sentry_sdk.init(
dsn=SENTRY_DSN,
traces_sample_rate=1.0,
profiles_sample_rate=1.0,
)
sdk_options = {
"service_name": os.environ.get("OTEL_SERVICE_NAME")
or service_name
or sys.argv[0],
"disable_logging": disable_logging,
"disable_instrumentations": disable_instrumentations,
"disable_tracing_for_functions": disable_tracing_for_functions,
"batch": batch,
"write_spans_to_console": write_spans_to_console,
"custom_remote_exporter": custom_remote_exporter,
"sdk_name": LANGTRACE_SDK_NAME,
"sdk_version": get_sdk_version(),
"api_host": host,
}
sentry_sdk.set_context("sdk_init_options", sdk_options)


def init_instrumentations(
Expand Down
4 changes: 4 additions & 0 deletions src/langtrace_python_sdk/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ def set_event_prompt(span: Span, prompt):
def check_if_sdk_is_outdated():
SDKVersionChecker().check()
return


def get_sdk_version():
return SDKVersionChecker().get_sdk_version()
3 changes: 3 additions & 0 deletions src/langtrace_python_sdk/utils/sdk_version_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def is_outdated(self):
return self._current_version < latest_version
return False

def get_sdk_version(self):
return self._current_version

def check(self):
if self.is_outdated():
print(
Expand Down