<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to_headers(self, span_context):
 """Convert a SpanContext object to B3 propagation headers. :type span_context: :class:`~opencensus.trace.span_context.SpanContext` :param span_context: SpanContext object. :rtype: dict :returns: B3 propagation headers. """


        if not span_context.span_id:
            span_id = INVALID_SPAN_ID
        else:
            span_id = span_context.span_id

        sampled = span_context.trace_options.enabled

        return {
            _TRACE_ID_KEY: span_context.trace_id,
            _SPAN_ID_KEY: span_id,
            _SAMPLED_KEY: '1' if sampled else '0'
        }