<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def __add_stack(self, span, limit=None):
 """ Adds a backtrace to this span """

        span.stack = []
        frame_count = 0

        tb = traceback.extract_stack()
        tb.reverse()
        for frame in tb:
            if limit is not None and frame_count >= limit:
                break

            # Exclude Instana frames unless we're in dev mode
            if "INSTANA_DEV" not in os.environ:
                if re_tracer_frame.search(frame[0]) is not None:
                    continue

                if re_with_stan_frame.search(frame[2]) is not None:
                    continue

            span.stack.append({
                "c": frame[0],
                "n": frame[1],
                "m": frame[2]
            })

            if limit is not None:
                frame_count += 1