def _to_trace_component_db(component):
    """
    Take the component as string or a dict and will construct a TraceComponentDB.

    :param component: Should identify the component. If a string should be id of the
                      component. If a dict should contain id and the caused_by.
    :type component: ``bson.ObjectId`` or ``dict``

    :rtype: ``TraceComponentDB``
    """
    if not isinstance(component, (six.string_types, dict)):
        print(type(component))
        raise ValueError("Expected component to be str or dict")

    object_id = (
        component if isinstance(component, six.string_types) else component["id"]
    )
    ref = component.get("ref", "") if isinstance(component, dict) else ""
    caused_by = component.get("caused_by", {}) if isinstance(component, dict) else {}

    return TraceComponentDB(object_id=object_id, ref=ref, caused_by=caused_by)

    Take the component as string or a dict and will construct a TraceComponentDB.

    :param component: Should identify the component. If a string should be id of the
                      component. If a dict should contain id and the caused_by.
    :type component: ``bson.ObjectId`` or ``dict``

    :rtype: ``TraceComponentDB``
    
st2common/st2common/services/trace.py