def add_or_update_given_trace_context(
    trace_context, action_executions=None, rules=None, trigger_instances=None
):
    """
    Will update an existing Trace or add a new Trace. This method will only look for exact
    Trace as identified by the trace_context. Even if the trace_context contain a trace_tag
    it shall not be used to lookup a Trace.

    * If an exact matching Trace is not found a new Trace is created
    * Whenever only a trace_tag is supplied a new Trace is created.

    :param trace_context: context object using which a trace can be found. If not found
                          trace_context.trace_tag is used to start new trace.
    :type trace_context: ``dict`` or ``TraceContext``

    :param action_executions: The action_execution to be added to the Trace. Should a list
                              of object_ids or a dict containing object_ids and caused_by.
    :type action_executions: ``list``

    :param rules: The rules to be added to the Trace.  Should a list of object_ids or a dict
                  containing object_ids and caused_by.
    :type rules: ``list``

    :param trigger_instances: The trigger_instances to be added to the Trace. Should a list
                              of object_ids or a dict containing object_ids and caused_by.
    :type trigger_instances: ``list``

    :rtype: ``TraceDB``
    """
    trace_db = get_trace(trace_context=trace_context, ignore_trace_tag=True)
    if not trace_db:
        # since trace_db is None need to end up with a valid trace_context
        trace_context = _get_valid_trace_context(trace_context)
        trace_db = TraceDB(trace_tag=trace_context.trace_tag)
    return add_or_update_given_trace_db(
        trace_db=trace_db,
        action_executions=action_executions,
        rules=rules,
        trigger_instances=trigger_instances,
    )

    Will update an existing Trace or add a new Trace. This method will only look for exact
    Trace as identified by the trace_context. Even if the trace_context contain a trace_tag
    it shall not be used to lookup a Trace.

    * If an exact matching Trace is not found a new Trace is created
    * Whenever only a trace_tag is supplied a new Trace is created.

    :param trace_context: context object using which a trace can be found. If not found
                          trace_context.trace_tag is used to start new trace.
    :type trace_context: ``dict`` or ``TraceContext``

    :param action_executions: The action_execution to be added to the Trace. Should a list
                              of object_ids or a dict containing object_ids and caused_by.
    :type action_executions: ``list``

    :param rules: The rules to be added to the Trace.  Should a list of object_ids or a dict
                  containing object_ids and caused_by.
    :type rules: ``list``

    :param trigger_instances: The trigger_instances to be added to the Trace. Should a list
                              of object_ids or a dict containing object_ids and caused_by.
    :type trigger_instances: ``list``

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