zalando-zmon / opentracing-utils

Convenient utilities for adding OpenTracing support in your python projects
MIT License
20 stars 8 forks source link

Allow trace decorator to optionally skip tracing based on user defined logic #16

Closed mohabusama closed 6 years ago

mohabusama commented 6 years ago

In certain cases an opentracing-utils user might need to skip @trace spans based on custom logic.

Suggested usage example:

def skip_span_logic(*args, **kwargs):
    if  'something' in kwargs:
        # @trace should not add a new span
        return True

    # @trace should add a new span
    return False

@trace(skip_span=skip_span_logic)
def trace_me(*args, **kwargs):
    # do stuff

This could be helpful in the case of trace_requests(ignore_url_patterns=[...]), since the skip_span func could inform @trace whether to add a span or not.