-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OPIK-673] implement OPIK_TRACK_DISABLE configuration (#962)
* Implement OPIK_TRACK_DISABLE configuration, add unit tests * Add disabled mode for track * Fix lint errors * Update test names
- Loading branch information
1 parent
b4c108b
commit a338601
Showing
3 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
sdks/python/tests/unit/decorator/test_track_disabled_mode.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from opik import opik_context | ||
from opik.decorator import tracker | ||
|
||
from ...testlib import patch_environ | ||
|
||
|
||
def test_track_disabled_mode__nothing_logged__happyflow(fake_backend): | ||
tracker_instance = tracker.OpikTrackDecorator() | ||
|
||
with patch_environ({"OPIK_TRACK_DISABLE": "true"}): | ||
|
||
@tracker_instance.track | ||
def f_inner(): | ||
return 42 | ||
|
||
@tracker_instance.track | ||
def f_outer(): | ||
f_inner() | ||
|
||
f_outer() | ||
tracker.flush_tracker() | ||
|
||
assert len(fake_backend.trace_trees) == 0 | ||
assert len(fake_backend.span_trees) == 0 | ||
|
||
|
||
def test_track_disabled_mode__get_current_span_and_trace_called__spans_and_trace_exist__but_nothing_logged( | ||
fake_backend, | ||
): | ||
""" | ||
SpanData and TraceData are still returned intentionally to make sure that scripts | ||
which called them continue working and don't fail because they started return `None` | ||
in disabled mode. | ||
""" | ||
tracker_instance = tracker.OpikTrackDecorator() | ||
|
||
with patch_environ({"OPIK_TRACK_DISABLE": "true"}): | ||
|
||
@tracker_instance.track | ||
def f(): | ||
assert opik_context.get_current_span_data() is not None | ||
assert opik_context.get_current_trace_data() is not None | ||
|
||
f() | ||
tracker.flush_tracker() | ||
|
||
assert len(fake_backend.trace_trees) == 0 | ||
assert len(fake_backend.span_trees) == 0 | ||
|
||
|
||
def test_track_disabled_mode__update_current_span_and_trace_called__no_errors_raised__nothing_logged( | ||
fake_backend, | ||
): | ||
tracker_instance = tracker.OpikTrackDecorator() | ||
|
||
with patch_environ({"OPIK_TRACK_DISABLE": "true"}): | ||
|
||
@tracker_instance.track | ||
def f(): | ||
opik_context.update_current_span(name="some-name") | ||
opik_context.update_current_trace(name="some-name") | ||
|
||
f() | ||
tracker.flush_tracker() | ||
|
||
assert len(fake_backend.trace_trees) == 0 | ||
assert len(fake_backend.span_trees) == 0 |