def get_log_attrs():
    """Get logging attributes from the opencensus context.

    :rtype: :class:`LogAttrs`
    :return: The current span's trace ID, span ID, and sampling decision.
    """
    try:
        tracer = execution_context.get_opencensus_tracer()
        if tracer is None:
            raise RuntimeError
    except Exception:  # noqa
        _meta_logger.error("Failed to get opencensus tracer")
        return ATTR_DEFAULTS

    try:
        trace_id = tracer.span_context.trace_id
        if trace_id is None:
            trace_id = ATTR_DEFAULTS.trace_id
    except Exception:  # noqa
        _meta_logger.error("Failed to get opencensus trace ID")
        trace_id = ATTR_DEFAULTS.trace_id

    try:
        span_id = tracer.span_context.span_id
        if span_id is None:
            span_id = ATTR_DEFAULTS.span_id
    except Exception:  # noqa
        _meta_logger.error("Failed to get opencensus span ID")
        span_id = ATTR_DEFAULTS.span_id

    try:
        sampling_decision = tracer.span_context.trace_options.get_enabled
        if sampling_decision is None:
            sampling_decision = ATTR_DEFAULTS.sampling_decision
    except AttributeError:
        sampling_decision = ATTR_DEFAULTS.sampling_decision
    except Exception:  # noqa
        _meta_logger.error("Failed to get opencensus sampling decision")
        sampling_decision = ATTR_DEFAULTS.sampling_decision

    return LogAttrs(trace_id, span_id, sampling_decision)
def get_log_attrs ( ) : try : tracer = execution_context . get_opencensus_tracer ( ) if tracer is None : raise RuntimeError except Exception : _meta_logger . error ( "Failed to get opencensus tracer" ) return ATTR_DEFAULTS try : trace_id = tracer . span_context . trace_id if trace_id is None : trace_id = ATTR_DEFAULTS . trace_id except Exception : _meta_logger . error ( "Failed to get opencensus trace ID" ) trace_id = ATTR_DEFAULTS . trace_id try : span_id = tracer . span_context . span_id if span_id is None : span_id = ATTR_DEFAULTS . span_id except Exception : _meta_logger . error ( "Failed to get opencensus span ID" ) span_id = ATTR_DEFAULTS . span_id try : sampling_decision = tracer . span_context . trace_options . get_enabled if sampling_decision is None : sampling_decision = ATTR_DEFAULTS . sampling_decision except AttributeError : sampling_decision = ATTR_DEFAULTS . sampling_decision except Exception : _meta_logger . error ( "Failed to get opencensus sampling decision" ) sampling_decision = ATTR_DEFAULTS . sampling_decision return LogAttrs ( trace_id , span_id , sampling_decision )
Get logging attributes from the opencensus context.

    :rtype: :class:`LogAttrs`
    :return: The current span's trace ID, span ID, and sampling decision.