5.1 Conditional Trace Example using cURL Only

Example - How to use conditional trace with cURL commands

Example workflows

  1. To create a trace template for the workflow shown above, you create a json file. This template is configured to set a trace template for hits on the r_1 route, and the Analysis_1 agent in the workflow named "conditionalDemo.fwd.wf", with the field name "Sequence". The lifetime determines the timeout of a trace to be 10000 milliseconds, the maximum number of hits in a trace is limited to 10. The unique name of the trace template is "pulse2". The following line is included in the APL code in Analysis_1:

    trace(input, "Message");
    {
     "name": "pulse2",
     "max_hits": 10,
     "lifetime": 10000,
     "workflow": [{
      "name": { "expr" : "conditionalDemo.fwd.wf" },
      "routes": [
          { "name" : { "expr": "r_1" },
            "fields" : [
                { "name": { "expr" : "Sequence" }, "description": " Sequence number to match" }
            ]
          }
      ],
      "agents": [
          { "name": {"expr": "Analysis_1"}, 
            "fields": [ { "name": { "expr": "Sequence" }, "description": " Sequence number to match" } ] } ]
     }]
    }
  2. You then use the following cURL command to add the trace template that you have created to your list of templates, providing the location of the trace template and the name of the JSON file:

    curl --request POST -u mzadmin:dr http://localhost:9000/conditionaltrace/template -d "$(</home/myfile/test/pulsetemplate2.json)"
  3. To set a filter for a specific trace, you modify the relevant template by specifying the value(s) to trace, and save the filter as a JSON file. In this example, the filter is named pulse2 and is set to output hits on the route r_1 with the field value of 5, and hits on the agent Analysis_1 for any field values. In addition, the maximum number of hits has been set to 15, and the lifetime has been increased to 100000 milliseconds.

    {
     "name": "pulse2",
     "max_hits": 15,
     "lifetime": 100000,
     "workflow": [{
      "name": { "expr" : "conditionalDemo.fwd.wf" },
      "routes": [
          { "name" : { "expr": "r_1" },
            "fields" : [
                { "name": {"expr": "Sequence"}, "value": {"expr": "5" }}
            ]
          }
      ],
      "agents": [
          { "name": {"expr": "Analysis_1"}, 
            "fields": [ 
                { "name": {"expr": "Sequence"}, "value": {"expr": ".*", "regex": true }} ] } ]
     }]
    }
  4. To start the trace filter, you run the following cURL command:

    curl --request POST -u mzadmin:dr http://localhost:9000/conditionaltrace/filter -d "$(</home/myfile/test/filter1.json)"

    This cURL command starts the trace and provides the trace filter id:

    {
      "filterId": "8b0d504b-e745-43e5-b849-83848a6a2189",
      "fullFilterName": "pulse2.8b0d504b-e745-43e5-b849-83848a6a2189",
      "workflows": []
    }

    The data output from the trace in place is not stored. It is sent to the relevant service context. If required, you can send the information generated to a file by adding a flag to the cURL command. For further information on cURL, see https://curl.haxx.se/.


  5. If you want to stop the trace before the timeout, you use the following cURL command, with the addition of the trace filter id:

    curl --request PUT -u mzadmin:dr http://localhost:9000/conditionaltrace/filter/8b0d504b-e745-43e5-b849-83848a6a2189/stop