-
Notifications
You must be signed in to change notification settings - Fork 201
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
Enable exporting spans to snowflake stage if a TruLensSnowflakeSpanExporter
is provided
#1708
Changes from all commits
929187f
b4d2c84
f112f38
197cd0a
062d197
1cc2a95
dfc3fa5
95f250c
788f945
ef17076
2c9d9bb
85cbdc6
65544c9
9b9644b
02855f9
d9a4694
5c939ac
d025a07
bcd677f
8456019
d2d2361
b3ff929
d4603b1
cbeb5a4
1846dba
eab220e
093f8ad
0236798
7d0e800
a8e9084
5d35d11
af18dde
f3c9e22
e94147f
2a74796
fd645d1
258abd2
28cee08
7dc4a1c
d8422ad
09f69ca
ab0bb6a
9e50f2c
21f9b72
37b6dcc
e23b2fc
af90428
0fce605
0422373
3083dd1
18d1094
910265b
9280281
6ca1f3c
a91b0eb
b3c5eca
bd3fb50
881c68d
5fff6fc
2d7b6a0
8bae5fb
c11b1c9
5a55584
61d87a8
8824794
a9f0537
9f4c8a3
f46af3c
2903b52
1a5d455
0353258
c28e10d
1c1d718
4e27038
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
from abc import ABC | ||
from abc import ABCMeta | ||
from abc import abstractmethod | ||
import contextlib | ||
import contextvars | ||
import datetime | ||
import inspect | ||
|
@@ -423,18 +422,6 @@ def tru(self) -> core_connector.DBConnector: | |
pydantic.PrivateAttr(default_factory=dict) | ||
) | ||
|
||
tokens: List[object] = [] | ||
""" | ||
OTEL context tokens for the current context manager. These tokens are how the OTEL | ||
context api keeps track of what is changed in the context, and used to undo the changes. | ||
""" | ||
|
||
span_context: Optional[contextlib.AbstractContextManager] = None | ||
""" | ||
Span context manager. Required to help keep track of the appropriate span context | ||
to enter/exit. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
connector: Optional[core_connector.DBConnector] = None, | ||
|
@@ -889,20 +876,18 @@ def model_dump(self, *args, redact_keys: bool = False, **kwargs): | |
**kwargs, | ||
) | ||
|
||
# For use as a context manager. | ||
def __enter__(self): | ||
if not core_instruments.Instrument._have_context(): | ||
raise RuntimeError(core_endpoint._NO_CONTEXT_WARNING) | ||
|
||
def _prevent_invalid_otel_syntax(self): | ||
if self.session.experimental_feature( | ||
core_experimental.Feature.OTEL_TRACING | ||
): | ||
from trulens.experimental.otel_tracing.core.instrument import ( | ||
App as OTELApp, | ||
) | ||
raise RuntimeError("Invalid TruLens OTEL Tracing syntax.") | ||
|
||
return OTELApp.__enter__(self) | ||
# For use as a context manager. | ||
def __enter__(self): | ||
if not core_instruments.Instrument._have_context(): | ||
raise RuntimeError(core_endpoint._NO_CONTEXT_WARNING) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we want to force the user to use syntax that looks like: with app():
... which will allow us to return a wrapping class around app to hold the OTEL properties, to avoid the risk of OTEL properties being mixed between invocations |
||
|
||
self._prevent_invalid_otel_syntax() | ||
ctx = core_instruments._RecordingContext(app=self) | ||
|
||
token = self.recording_contexts.set(ctx) | ||
|
@@ -912,35 +897,19 @@ def __enter__(self): | |
|
||
# For use as a context manager. | ||
def __exit__(self, exc_type, exc_value, exc_tb): | ||
if self.session.experimental_feature( | ||
core_experimental.Feature.OTEL_TRACING | ||
): | ||
from trulens.experimental.otel_tracing.core.instrument import ( | ||
App as OTELApp, | ||
) | ||
|
||
return OTELApp.__exit__(self, exc_type, exc_value, exc_tb) | ||
self._prevent_invalid_otel_syntax() | ||
|
||
ctx = self.recording_contexts.get() | ||
self.recording_contexts.reset(ctx.token) | ||
|
||
# self._reset_context_vars() | ||
|
||
if exc_type is not None: | ||
raise exc_value | ||
|
||
return | ||
|
||
# For use as a context manager. | ||
async def __aenter__(self): | ||
if self.session.experimental_feature( | ||
core_experimental.Feature.OTEL_TRACING | ||
): | ||
from trulens.experimental.otel_tracing.core.instrument import ( | ||
App as OTELApp, | ||
) | ||
|
||
return OTELApp.__enter__(self) | ||
self._prevent_invalid_otel_syntax() | ||
|
||
ctx = core_instruments._RecordingContext(app=self) | ||
|
||
|
@@ -953,14 +922,7 @@ async def __aenter__(self): | |
|
||
# For use as a context manager. | ||
async def __aexit__(self, exc_type, exc_value, exc_tb): | ||
if self.session.experimental_feature( | ||
core_experimental.Feature.OTEL_TRACING | ||
): | ||
from trulens.experimental.otel_tracing.core.instrument import ( | ||
App as OTELApp, | ||
) | ||
|
||
return OTELApp.__exit__(self, exc_type, exc_value, exc_tb) | ||
self._prevent_invalid_otel_syntax() | ||
|
||
ctx = self.recording_contexts.get() | ||
self.recording_contexts.reset(ctx.token) | ||
|
@@ -972,6 +934,20 @@ async def __aexit__(self, exc_type, exc_value, exc_tb): | |
|
||
return | ||
|
||
def __call__(self, *, run_name: str = "", input_id: str = ""): | ||
if not self.session.experimental_feature( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry can you explain to me what's going on in this function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. haha - this might not have been the best way to achieve this. The goal is to enable syntax that looks like: with custom_app(run_name='run_name', input_id='input_id') as recording:
test_app.respond_to_query(input) to achieve this - hence - the approach here is, when
|
||
core_experimental.Feature.OTEL_TRACING | ||
): | ||
raise RuntimeError("OTEL Tracing is not enabled for this session.") | ||
|
||
from trulens.experimental.otel_tracing.core.instrument import ( | ||
OTELRecordingContext as OTELApp, | ||
) | ||
|
||
# Pylance shows an error here, but it is likely a false positive. due to the overriden | ||
# model dump returning json instead of a dict. | ||
return OTELApp(app=self, run_name=run_name, input_id=input_id) | ||
|
||
def _set_context_vars(self): | ||
# HACK: For debugging purposes, try setting/resetting all context vars | ||
# used in trulens around the app context managers due to bugs in trying | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did you name this function this? Like what do you mean by otel tracing syntax?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
basically trying to force the user to use syntax that looks like:
or
as opposed to the conventional
this is because we need to be able to return a different object in order to avoid the possibility of polluting the
App