Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Davidkurokawa/downgrade alembic #1763

Closed
wants to merge 79 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
9675bc7
Fill in MAIN span for TruChain apps.
sfc-gh-dkurokawa Jan 17, 2025
9dab610
Get tests working.
sfc-gh-dkurokawa Jan 19, 2025
a103e7b
Get basics of TruLlama working.
sfc-gh-dkurokawa Jan 21, 2025
42464a3
Get main input/output working and also change test to be mostly mocke…
sfc-gh-dkurokawa Jan 21, 2025
b23260d
Have more descriptive names for the spans.
sfc-gh-dkurokawa Jan 21, 2025
5bbcc25
Refactor tests.
sfc-gh-dkurokawa Jan 21, 2025
94eba56
Write all kwargs for spans of type "UNKNOWN".
sfc-gh-dkurokawa Jan 21, 2025
0da6852
Have `@instrument` decorator handle async functions.
sfc-gh-dkurokawa Jan 22, 2025
e666e58
Remove TODOs.
sfc-gh-dkurokawa Jan 22, 2025
c5c2c56
Delete old code.
sfc-gh-dkurokawa Jan 22, 2025
3e56db4
Add multi-threaded test.
sfc-gh-dkurokawa Jan 22, 2025
4634886
Revert "Delete old code."
sfc-gh-dkurokawa Jan 22, 2025
5c883cb
Merge remote-tracking branch 'origin/main' into davidkurokawa/otel/ge…
sfc-gh-dkurokawa Jan 22, 2025
0ee6ce0
Refactor hack.
sfc-gh-dkurokawa Jan 22, 2025
187e40b
Hide llama-index imports.
sfc-gh-dkurokawa Jan 22, 2025
a9de876
Merge branch 'davidkurokawa/otel/get_tru_llama_working' into davidkur…
sfc-gh-dkurokawa Jan 22, 2025
b0d419d
Merge branch 'davidkurokawa/otel/write_all_kwargs_for_unknown_spans' …
sfc-gh-dkurokawa Jan 22, 2025
d2eed82
Merge branch 'davidkurokawa/otel/handle_async_functions' into davidku…
sfc-gh-dkurokawa Jan 22, 2025
9d21923
Merge branch 'davidkurokawa/otel/delete_old_code' into davidkurokawa/…
sfc-gh-dkurokawa Jan 22, 2025
be05443
Get commented out tests working.
sfc-gh-dkurokawa Jan 22, 2025
6f69902
Make sure types of span attributes are correct.
sfc-gh-dkurokawa Jan 23, 2025
56c15d5
Ignore memory locations in tests.
sfc-gh-dkurokawa Jan 23, 2025
93667c9
Merge branch 'davidkurokawa/otel/write_all_kwargs_for_unknown_spans' …
sfc-gh-dkurokawa Jan 23, 2025
41e10d3
Merge branch 'davidkurokawa/otel/handle_async_functions' into davidku…
sfc-gh-dkurokawa Jan 23, 2025
3d83e20
Merge branch 'davidkurokawa/otel/delete_old_code' into davidkurokawa/…
sfc-gh-dkurokawa Jan 23, 2025
8beb909
Merge branch 'davidkurokawa/otel/add_multithreaded_test' into davidku…
sfc-gh-dkurokawa Jan 23, 2025
2fa4690
Merge remote-tracking branch 'origin/main' into davidkurokawa/otel/wr…
sfc-gh-dkurokawa Jan 23, 2025
a231675
Run attribute type conversion on all attributes.
sfc-gh-dkurokawa Jan 23, 2025
7551158
Also allow for tuples with lists.
sfc-gh-dkurokawa Jan 23, 2025
3bb93bd
Merge branch 'davidkurokawa/otel/write_all_kwargs_for_unknown_spans' …
sfc-gh-dkurokawa Jan 23, 2025
d95c8bb
Merge branch 'davidkurokawa/otel/handle_async_functions' into davidku…
sfc-gh-dkurokawa Jan 23, 2025
17244c8
Merge branch 'davidkurokawa/otel/delete_old_code' into davidkurokawa/…
sfc-gh-dkurokawa Jan 23, 2025
7b7d677
Merge branch 'davidkurokawa/otel/add_multithreaded_test' into davidku…
sfc-gh-dkurokawa Jan 23, 2025
47632d5
Handle generators when they're garbage collected.
sfc-gh-dkurokawa Jan 23, 2025
909605c
Set as `trulens.unknown.return` the return value for any unknown spans.
sfc-gh-dkurokawa Jan 23, 2025
9cac107
Create E2E test to write to main snowflake event table.
sfc-gh-dkurokawa Jan 24, 2025
bdf5a0c
Change:
sfc-gh-dkurokawa Jan 24, 2025
06a914b
Handle weird "node" results.
sfc-gh-dkurokawa Jan 25, 2025
a16db3b
Merge branch 'davidkurokawa/otel/write_returns_for_unknown_spans' int…
sfc-gh-dkurokawa Jan 26, 2025
16cbfb2
Revert "remove sql instrumentation (#1715)"
sfc-gh-dkurokawa Jan 27, 2025
fd113a1
Revert "Revert "remove sql instrumentation (#1715)""
sfc-gh-dkurokawa Jan 27, 2025
aa3c28a
For sync functions, handle the case where the return value is a gener…
sfc-gh-dkurokawa Jan 28, 2025
c56b35a
Merge branch 'davidkurokawa/handle_generators_passed_through' into da…
sfc-gh-dkurokawa Jan 28, 2025
4f96593
Merge remote-tracking branch 'origin/main' into davidkurokawa/otel/wr…
sfc-gh-dkurokawa Jan 28, 2025
e4f2b63
Add in explanatory comment.
sfc-gh-dkurokawa Jan 28, 2025
71efc78
Update golden when using proper package versions.
sfc-gh-dkurokawa Jan 28, 2025
29fec9f
Get custom cortex kinda working.
sfc-gh-dkurokawa Jan 28, 2025
f5d7487
Get openai cost tracking working.
sfc-gh-dkurokawa Jan 28, 2025
f469f02
Merge branch 'davidkurokawa/otel/write_returns_for_unknown_spans' int…
sfc-gh-dkurokawa Jan 28, 2025
4505bb1
Merge remote-tracking branch 'origin/main' into davidkurokawa/otel/cr…
sfc-gh-dkurokawa Jan 28, 2025
2198e83
Fix up TODOs.
sfc-gh-dkurokawa Jan 28, 2025
7994a11
Clean up.
sfc-gh-dkurokawa Jan 29, 2025
b37ee9d
Merge branch 'davidkurokawa/otel/create_e2e_test_to_write_to_snowflak…
sfc-gh-dkurokawa Jan 29, 2025
8779092
Merge branch 'davidkurokawa/handle_generators_passed_through' into da…
sfc-gh-dkurokawa Jan 29, 2025
c13d17b
Use dictionary to mark if a function has been wrapped since pydantic …
sfc-gh-dkurokawa Jan 29, 2025
8714ef2
Fix tests.
sfc-gh-dkurokawa Jan 29, 2025
654c452
Stop using the event table flow in other unit tests.
sfc-gh-dkurokawa Jan 29, 2025
bf5e126
Clean up E2E test better as well.
sfc-gh-dkurokawa Jan 29, 2025
ba4704b
Merge branch 'davidkurokawa/otel/create_e2e_test_to_write_to_snowflak…
sfc-gh-dkurokawa Jan 29, 2025
f051ca7
Merge branch 'davidkurokawa/handle_generators_passed_through' into da…
sfc-gh-dkurokawa Jan 29, 2025
7973195
Clean up unnecessary instrumentations.
sfc-gh-dkurokawa Jan 29, 2025
33ca6fd
Update api tests.
sfc-gh-dkurokawa Jan 29, 2025
e8babd7
Merge branch 'davidkurokawa/otel/create_e2e_test_to_write_to_snowflak…
sfc-gh-dkurokawa Jan 29, 2025
04aaf7c
Merge branch 'davidkurokawa/otel/handle_generators_passed_through' in…
sfc-gh-dkurokawa Jan 29, 2025
68286ea
Merge branch 'davidkurokawa/otel/create_e2e_test_to_write_to_snowflak…
sfc-gh-dkurokawa Jan 29, 2025
1582b2f
Merge branch 'davidkurokawa/handle_generators_passed_through' into da…
sfc-gh-dkurokawa Jan 29, 2025
06f5214
Move test to e2e as it has openai/cortex calls.
sfc-gh-dkurokawa Jan 29, 2025
fabc9e9
Merge remote-tracking branch 'origin/davidkurokawa/otel/track_cortex_…
sfc-gh-dkurokawa Jan 29, 2025
d7003ca
Remove old OTEL logic.
sfc-gh-dkurokawa Jan 29, 2025
a5b850b
Fix api tests.
sfc-gh-dkurokawa Jan 29, 2025
7e0718d
Remove more logic.
sfc-gh-dkurokawa Jan 29, 2025
0742369
Update api test.
sfc-gh-dkurokawa Jan 29, 2025
1555527
Set up context retrieval spans for llama-index.
sfc-gh-dkurokawa Jan 29, 2025
f37f8ee
Merge remote-tracking branch 'origin/main' into davidkurokawa/otel/re…
sfc-gh-dkurokawa Jan 29, 2025
2c217b0
Merge branch 'davidkurokawa/otel/remove_old_otel_logic' into davidkur…
sfc-gh-dkurokawa Jan 29, 2025
21f40f5
Try downgrading alembic.
sfc-gh-dkurokawa Jan 29, 2025
13c75b9
Downgrade zipp to 3.20.1.
sfc-gh-dkurokawa Jan 29, 2025
093ec3a
Change makefile to install both alembic and zipp separately.
sfc-gh-dkurokawa Jan 30, 2025
f54ad74
Change version.
sfc-gh-dkurokawa Jan 30, 2025
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
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ env-tests:
ruff \

env-tests-required:
poetry install --only required \
pip install zipp==3.20.1 \
&& echo "INSTALLED zipp" \
&& pip install alembic==1.14.0 \
&& echo "INSTALLED alembic" \
&& poetry install --only required \
&& make env-tests

env-tests-optional: env env-tests
Expand Down
12 changes: 6 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

93 changes: 84 additions & 9 deletions src/apps/llamaindex/trulens/apps/llamaindex/tru_llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
AsyncGenerator,
Callable,
ClassVar,
Dict,
Generator,
List,
Optional,
Expand All @@ -32,6 +33,8 @@
from trulens.core.utils import pyschema as pyschema_utils
from trulens.core.utils import python as python_utils
from trulens.core.utils import serial as serial_utils
from trulens.experimental.otel_tracing.core.span import Attributes
from trulens.otel.semconv.trace import SpanAttributes

T = TypeVar("T")

Expand Down Expand Up @@ -72,6 +75,7 @@
from llama_index.core.response_synthesizers import Refine
from llama_index.core.retrievers import BaseRetriever
from llama_index.core.schema import BaseComponent
from llama_index.core.schema import NodeWithScore
from llama_index.core.schema import QueryBundle
from llama_index.core.service_context_elements.llm_predictor import (
BaseLLMPredictor,
Expand Down Expand Up @@ -133,6 +137,41 @@
pp = PrettyPrinter()


def _retrieval_span() -> Dict[str, Union[SpanAttributes.SpanType, Attributes]]:
def _full_scoped_span_attributes(
ret, exception, *args, **kwargs
) -> Attributes:
attributes = {}
# Guess query text.
possible_query_texts = []
for k, v in kwargs.items():
if isinstance(v, str):
possible_query_texts.append(v)
elif isinstance(v, QueryBundle):
possible_query_texts.append(v.query_str)
# Guess retrieved contexts.
retrieved_context = ret
if isinstance(ret, list):
if all(isinstance(curr, NodeWithScore) for curr in ret):
retrieved_context = [curr.get_content() for curr in ret]
elif all(hasattr(curr, "text") for curr in ret):
retrieved_context = [curr.text for curr in ret]
# Return.
attributes = {
SpanAttributes.RETRIEVAL.RETRIEVED_CONTEXTS: retrieved_context
}
if len(possible_query_texts) == 1:
attributes[SpanAttributes.RETRIEVAL.QUERY_TEXT] = (
possible_query_texts[0]
)
return attributes

return {
"span_type": SpanAttributes.SpanType.RETRIEVAL,
"full_scoped_span_attributes": _full_scoped_span_attributes,
}


class LlamaInstrument(core_instruments.Instrument):
"""Instrumentation for LlamaIndex apps."""

Expand Down Expand Up @@ -206,15 +245,51 @@ class Default:
InstrumentedMethod("acomplete", BaseChatEngine),
InstrumentedMethod("stream_complete", BaseChatEngine),
InstrumentedMethod("astream_complete", BaseChatEngine),
InstrumentedMethod("retrieve", BaseQueryEngine),
InstrumentedMethod("_retrieve", BaseQueryEngine),
InstrumentedMethod("_aretrieve", BaseQueryEngine),
InstrumentedMethod("retrieve", BaseRetriever),
InstrumentedMethod("_retrieve", BaseRetriever),
InstrumentedMethod("_aretrieve", BaseRetriever),
InstrumentedMethod("retrieve", WithFeedbackFilterNodes),
InstrumentedMethod("_retrieve", WithFeedbackFilterNodes),
InstrumentedMethod("_aretrieve", WithFeedbackFilterNodes),
InstrumentedMethod(
"retrieve",
BaseQueryEngine,
**_retrieval_span(),
),
InstrumentedMethod(
"_retrieve",
BaseQueryEngine,
**_retrieval_span(),
),
InstrumentedMethod(
"_aretrieve",
BaseQueryEngine,
**_retrieval_span(),
),
InstrumentedMethod(
"retrieve",
BaseRetriever,
**_retrieval_span(),
),
InstrumentedMethod(
"_retrieve",
BaseRetriever,
**_retrieval_span(),
),
InstrumentedMethod(
"_aretrieve",
BaseRetriever,
**_retrieval_span(),
),
InstrumentedMethod(
"retrieve",
WithFeedbackFilterNodes,
**_retrieval_span(),
),
InstrumentedMethod(
"_retrieve",
WithFeedbackFilterNodes,
**_retrieval_span(),
),
InstrumentedMethod(
"_aretrieve",
WithFeedbackFilterNodes,
**_retrieval_span(),
),
InstrumentedMethod("_postprocess_nodes", BaseNodePostprocessor),
InstrumentedMethod("_run_component", QueryEngineComponent),
InstrumentedMethod("_run_component", RetrieverComponent),
Expand Down
2 changes: 1 addition & 1 deletion src/core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ rich = "^13.6"
requests = "^2.31"
packaging = ">=23.0"
sqlalchemy = "^2.0"
alembic = "^1.8.1"
alembic = "^1.8.1,<1.14.1"
nest-asyncio = "^1.5"
python-dotenv = ">=0.21,<2.0"
importlib-resources = "^6.0"
Expand Down
2 changes: 0 additions & 2 deletions src/core/trulens/_mods.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@
from trulens.dashboard.utils import records_utils
from trulens.dashboard.ux import components as dashboard_components
from trulens.dashboard.ux import styles as dashboard_styles
from trulens.experimental.otel_tracing.core import otel as core_otel
from trulens.experimental.otel_tracing.core import trace as core_trace
from trulens.experimental.otel_tracing.core._utils import wrap as wrap_utils
from trulens.feedback import embeddings as feedback_embeddings
from trulens.feedback import feedback as mod_feedback
Expand Down
19 changes: 0 additions & 19 deletions src/core/trulens/core/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,25 +764,6 @@ def main_output(
) -> str:
return signature_utils.main_output(func, ret)

# Experimental OTEL WithInstrumentCallbacks requirement
def _on_new_recording_span(
self,
recording_span: Any, # Any = mod_trace.Span,
):
from trulens.experimental.otel_tracing.core.app import _App

return _App._on_new_recording_span(self, recording_span)

# Experimental OTEL WithInstrumentCallbacks requirement
def _on_new_root_span(
self,
recording: core_instruments._RecordingContext,
root_span: Any, # Any = mod_trace.Span,
) -> record_schema.Record:
from trulens.experimental.otel_tracing.core.app import _App

return _App._on_new_root_span(self, recording, root_span)

# WithInstrumentCallbacks requirement
def on_method_instrumented(
self, obj: object, func: Callable, path: serial_utils.Lens
Expand Down
30 changes: 0 additions & 30 deletions src/core/trulens/core/feedback/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@

import pydantic
from pydantic import Field
from pydantic import PrivateAttr
import requests
from trulens.core import experimental as core_experimental
from trulens.core import session as core_session
from trulens.core.schema import base as base_schema
from trulens.core.utils import asynchro as asynchro_utils
from trulens.core.utils import pace as pace_utils
Expand Down Expand Up @@ -223,11 +220,6 @@ class EndpointSetup:
callback_name: str = Field(exclude=True)
"""Name of variable that stores the callback noted above."""

_experimental_wrapper_callback_class: Optional[Type[Any]] = PrivateAttr(
None
) # Any actually WrapperEndpointCallback but cannot import it here
"""EXPERIMENTAL(otel_tracing): callback class to use for usage tracking."""

_context_endpoints: ClassVar[contextvars.ContextVar] = (
contextvars.ContextVar("endpoints", default={})
)
Expand Down Expand Up @@ -575,17 +567,6 @@ def track_all_costs_tally(
change after this method returns in case of Awaitable results.
"""

session = core_session.TruSession()

if session.experimental_feature(
core_experimental.Feature.OTEL_TRACING, freeze=True
):
from trulens.experimental.otel_tracing.core.feedback.endpoint import (
_Endpoint,
)

return _Endpoint.track_all_costs_tally(__func, *args, **kwargs)

result, cbs = Endpoint.track_all_costs(
__func,
*args,
Expand Down Expand Up @@ -746,17 +727,6 @@ def _have_context() -> bool:
def wrap_function(self, func):
"""Create a wrapper of the given function to perform cost tracking."""

session = core_session.TruSession()

if session.experimental_feature(
core_experimental.Feature.OTEL_TRACING, freeze=True
):
from trulens.experimental.otel_tracing.core.feedback.endpoint import (
_Endpoint,
)

return _Endpoint.wrap_function(self, func)

if python_utils.safe_hasattr(func, INSTRUMENT):
# Store the types of callback classes that will handle calls to the
# wrapped function in the INSTRUMENT attribute. This will be used to
Expand Down
5 changes: 0 additions & 5 deletions src/core/trulens/core/feedback/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,11 +733,6 @@ def check_selectors(
check_good: bool = True

for k, q in self.selectors.items():
if select_schema.Select.RecordSpans.is_prefix_of(q):
# Skip checking for RecordSpans as they are not known ahead of
# producing a record.
continue

if q.exists(source_data):
continue

Expand Down
31 changes: 0 additions & 31 deletions src/core/trulens/core/schema/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from typing import Optional

import pydantic
from trulens.core.utils import containers as container_utils
from trulens.core.utils import serial as serial_utils

MAX_DILL_SIZE: int = 1024 * 1024 # 1MB
Expand Down Expand Up @@ -162,36 +161,6 @@ def latency(self):
"""Latency in seconds."""
return self.end_time - self.start_time

@staticmethod
def of_ns_timestamps(
start_ns_timestamp: int, end_ns_timestamp: Optional[int] = None
) -> Perf:
"""EXPERIMENTAL(otel_tracing): Create a `Perf` instance from start and
end times in nanoseconds since the epoch."""

return Perf(
start_time=container_utils.datetime_of_ns_timestamp(
start_ns_timestamp
),
end_time=container_utils.datetime_of_ns_timestamp(end_ns_timestamp)
if end_ns_timestamp is not None
else datetime.datetime.max,
)

@property
def start_ns_timestamp(self) -> int:
"""EXPERIMENTAL(otel_tracing): Start time in number of nanoseconds since
the epoch."""

return container_utils.ns_timestamp_of_datetime(self.start_time)

@property
def end_ns_timestamp(self) -> int:
"""EXPERIMENTAL(otel_tracing): End time in number of nanoseconds since
the epoch."""

return container_utils.ns_timestamp_of_datetime(self.end_time)


# HACK013: Need these if using __future__.annotations .
Cost.model_rebuild()
Expand Down
Loading