-
Notifications
You must be signed in to change notification settings - Fork 824
feat(traceloop-sdk): add 'trace_content' flag and relevant test cases. Fixes #137 #3433
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -223,6 +223,33 @@ def on_start(self, span, parent_context=None): | |
| TracerWrapper.instance = _trace_wrapper_instance | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def exporter_with_trace_content_override(): | ||
| # Clear singleton if existed | ||
| if hasattr(TracerWrapper, "instance"): | ||
| _trace_wrapper_instance = TracerWrapper.instance | ||
| del TracerWrapper.instance | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Set environment variable to false | ||
| os.environ["TRACELOOP_TRACE_CONTENT"] = "false" | ||
|
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. 🛠️ Refactor suggestion | 🟠 Major Preserve the original environment variable value. The fixture unconditionally deletes Apply this diff: + _original_trace_content = os.environ.get("TRACELOOP_TRACE_CONTENT")
# Set environment variable to false
os.environ["TRACELOOP_TRACE_CONTENT"] = "false"
...
# Clean up environment
- del os.environ["TRACELOOP_TRACE_CONTENT"]
+ if _original_trace_content is not None:
+ os.environ["TRACELOOP_TRACE_CONTENT"] = _original_trace_content
+ else:
+ os.environ.pop("TRACELOOP_TRACE_CONTENT", None)Also applies to: 250-250 🤖 Prompt for AI Agents |
||
|
|
||
| # Create exporter with trace_content=True to override env var | ||
| exporter = InMemorySpanExporter() | ||
| Traceloop.init( | ||
| exporter=exporter, | ||
| disable_batch=True, | ||
| trace_content=True # This should override the env var | ||
| ) | ||
|
|
||
| yield exporter | ||
|
|
||
| # Restore singleton if any | ||
| if _trace_wrapper_instance: | ||
| TracerWrapper.instance = _trace_wrapper_instance | ||
| # Clean up environment | ||
| del os.environ["TRACELOOP_TRACE_CONTENT"] | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def datasets(): | ||
| """Create a Datasets instance with HTTP client for VCR recording/playback""" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,7 @@ def init( | |
| sampler: Optional[Sampler] = None, | ||
| traceloop_sync_enabled: bool = False, | ||
| should_enrich_metrics: bool = True, | ||
| trace_content: bool = True, | ||
|
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. Breaking change: default The default value of Additionally, the OR semantics prevent true programmatic override: To maintain backward compatibility and enable true override, use - trace_content: bool = True,
+ trace_content: Optional[bool] = None,
resource_attributes: dict = {},And update the logic at line 98: - enable_content_tracing = trace_content or is_content_tracing_enabled()
+ enable_content_tracing = (
+ trace_content if trace_content is not None else is_content_tracing_enabled()
+ )This ensures:
Also applies to: 98-98 🤖 Prompt for AI Agents |
||
| resource_attributes: dict = {}, | ||
| instruments: Optional[Set[Instruments]] = None, | ||
| block_instruments: Optional[Set[Instruments]] = None, | ||
|
|
@@ -94,7 +95,7 @@ def init( | |
| print(Fore.YELLOW + "Tracing is disabled" + Fore.RESET) | ||
| return | ||
|
|
||
| enable_content_tracing = is_content_tracing_enabled() | ||
| enable_content_tracing = trace_content or is_content_tracing_enabled() | ||
|
|
||
| if exporter or processor: | ||
| print(Fore.GREEN + "Traceloop exporting traces to a custom exporter") | ||
|
|
||
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.
Initialize
_trace_wrapper_instancetoNone(e.g. before the if-check) so that the teardown code doesn’t raise aNameErrorif the attribute isn’t present.