Skip to content
Merged
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
20 changes: 16 additions & 4 deletions weave/guides/tracking/tracing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,8 @@ For more information, see [Trace data is truncated](/weave/guides/troubleshootin

In situations where you want to unconditionally disable tracing for the entire program, you can set the environment variable `WEAVE_DISABLED=true`.

`WEAVE_DISABLED` is read only once, at function-defintion time. This variable cannot be used to toggle tracing at runtime.
Comment thread
anastasiaguspan marked this conversation as resolved.

#### Client initialization

Sometimes, you may want to conditionally enable tracing for a specific initialization based on some condition. In this case, you can initialize the client with the `disabled` flag in init settings.
Expand All @@ -1141,20 +1143,30 @@ This feature is not available for the TypeScript SDK yet.

#### Context manager

Finally, you may want to conditionally disable tracing for a single function based on some application logic. In this case, you can use the context manager `with set_tracing_enabled(False)` which can be imported from `weave.trace.context.call_context`.
To conditionally disable tracing for a specific block of code, you can use a tracing context manager. Use `with tracing_disabled()` to suppress tracing **only for the function calls executed inside the `with` block**. It is intended to be used in application code to scope which calls should not be logged.

```python lines
import weave
from weave.trace.context.call_context import set_tracing_enabled
from weave.trace.context.call_context import tracing_disabled

client = weave.init(...)
client = weave.init('your-team/your-project-name')

@weave.op
def my_op():
...

with set_tracing_enabled(False):
with tracing_disabled():
my_op()
```

Although tracing behavior is fixed when functions are defined, this can be used for runtime control when combined with application logic. For example, you can wrap the context manager in a conditional to dynamically enable or disable tracing based on a runtime value:

```python lines
if should_trace:
my_op()
else:
with tracing_disabled():
my_op()
```

### How do I capture information about a Call?
Expand Down