- Python
- TypeScript
To create an op, decorate a python function with Calling an op creates a new op version if the code has changed from the last call, and log the inputs and outputs of the function.Functions decorated with
weave.op()
@weave.op()
will behave normally (without code versioning and tracking), if you don’t call weave.init('your-project-name')
before calling them.Ops can be served or deployed using the Weave toolbelt.Customize display names
- Python
- TypeScript
You can customize the op’s display name by setting the
name
parameter in the @weave.op
decorator:Customize logged inputs and outputs
- Python
- TypeScript
If you want to change the data that is logged to weave without modifying the original function (e.g. to hide sensitive data), you can pass
postprocess_inputs
and postprocess_output
to the op decorator.postprocess_inputs
takes in a dict where the keys are the argument names and the values are the argument values, and returns a dict with the transformed inputs.postprocess_output
takes in any value which would normally be returned by the function and returns the transformed output.Control sampling rate
- Python
- TypeScript
You can control how frequently an op’s calls are traced by setting the When an op’s call is not sampled:
tracing_sample_rate
parameter in the @weave.op
decorator. This is useful for high-frequency ops where you only need to trace a subset of calls.Note that sampling rates are only applied to root calls. If an op has a sample rate, but is called by another op first, then that sampling rate will be ignored.- The function executes normally
- No trace data is sent to Weave
- Child ops are also not traced for that call
Control call link output
If you want to suppress the printing of call links during logging, you can set theWEAVE_PRINT_CALL_LINK
environment variable to false
. This can be useful if you want to reduce output verbosity and reduce clutter in your logs.
Deleting an op
- Python
- TypeScript
To delete a version of an op, call Trying to access a deleted op will result in an error.
.delete()
on the op ref.