<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def wrap(function_to_trace=None, **trace_options):
 """ Functions decorated with this will be traced. Use ``local=True`` to only trace local code, eg:: @hunter.wrap(local=True) def my_function():
 Keyword arguments are allowed, eg:: @hunter.wrap(action=hunter.CallPrinter) def my_function():
 Or, filters:: @hunter.wrap(module='foobar') def my_function():
 """


    def tracing_decorator(func):
        @functools.wraps(func)
        def tracing_wrapper(*args, **kwargs):
            predicates = []
            local = trace_options.pop('local', False)
            if local:
                predicates.append(Q(depth_lt=2))
            predicates.append(~When(Q(calls_gt=0, depth=0) & ~Q(kind='return'), Stop))
            local_tracer = trace(*predicates, **trace_options)
            try:
                return func(*args, **kwargs)
            finally:
                local_tracer.stop()
        return tracing_wrapper
    if function_to_trace is None:
        return tracing_decorator
    else:
        return tracing_decorator(function_to_trace)