Debug Logging

When writing workflows, you may find it helpful to look at information in your workflow when it runs. The way to do that in Relay is by using the relay workflow logs command and adding in debugLog() function calls throughout your workflow. For example, you may modify the helloWorld sample to add a line such as this:

...
    await workflow.sayAndWait(source_uri, `hello world`)
    await workflow.debugLog("greeting complete")
    ...
...
    await workflow.say_and_wait(interaction_uri, 'hello world')
    await workflow.debug_log("greeting complete")
    ...
...
    await Relay.SayAndWait(this, sourceUri, $"{greeting} {listenResponse["text"]}! You are currently using {deviceName}");
    await Relay.DebugLog(this, "greeting complete");
    ...
...
    relay.say(interactionUri, "Hello world");
    relay.debugLog("greeting complete");
    ...
...
    api.Say(sourceUri, "Hello " + name + " you are currently using " + deviceName, sdk.ENGLISH)
    api.DebugLog("greeting complete")
    ...

Then you can use the CLI command relay workflow logs to look at a live stream of debug information from the workflow, where your invocation to debugLog() will be one of these entries (scroll to the right to see the interesting parts and see the "greeting complete" message):

{"context":{"subscriber_id":"ee4547e0-aaef-4956-b853-ade0ba436789","user_id":"990007560023456","workflow_id":"wf_hello_K3hqqZhF19BAFnodSTIx4XA"},"level":"info","message":"Handling request: {wf_api_listen_request,\"92d2572bcd0668d2d6c52f5054e2d083\",{wf_api_target,[\"urn:relay-resource:name:interaction:hello%20interaction?device=urn%3Arelay-resource%3Aname%3Adevice%3AWolf\"]},\"request1\",[],false,30,\"en-US\"}","timestamp":"2022-11-21T21:02:06.609419+00:00"}
{"context":{"subscriber_id":"ee4547e0-aaef-4956-b853-ade0ba436789","user_id":"990007560023456","workflow_id":"wf_hello_K3hqqZhF19BAFnodSTIx4XA"},"level":"info","message":"Handling request: {wf_api_say_request,\"6bf84c7174cb7476364cc3dbd968b0f7\",{wf_api_target,[\"urn:relay-resource:name:interaction:hello%20interaction?device=urn%3Arelay-resource%3Aname%3Adevice%3AWolf\"]},\"Hello Bob you are currently using wolf\",\"en-US\"}","timestamp":"2022-11-21T21:02:14.309243+00:00"}
{"context":{"subscriber_id":"ee4547e0-aaef-4956-b853-ade0ba436789","user_id":"990007560023456","workflow_id":"wf_hello_K3hqqZhF19BAFnodSTIx4XA"},"level":"info","message":"Handling request: {wf_api_debug_log_request,\"172ed85794bb358b0c3b525da1786f9f\",\"greeting complete\"}","timestamp":"2022-11-21T21:02:14.356347+00:00"}
{"context":{"subscriber_id":"ee4547e0-aaef-4956-b853-ade0ba436789","user_id":"990007560023456","workflow_id":"wf_hello_K3hqqZhF19BAFnodSTIx4XA"},"level":"info","message":"greeting complete","timestamp":"2022-11-21T21:02:14.356690+00:00"}
{"context":{"subscriber_id":"ee4547e0-aaef-4956-b853-ade0ba436789","user_id":"990007560023456","workflow_id":"wf_hello_K3hqqZhF19BAFnodSTIx4XA"},"level":"info","message":"Handling request: {wf_api_end_interaction_request,\"ff094279db1944ebd7a19d0f7bbacbe0\",{wf_api_target,[\"urn:relay-resource:name:interaction:hello%20interaction?device=urn%3Arelay-resource%3Aname%3Adevice%3AAlice\"]},undefined}","timestamp":"2022-11-21T21:02:14.450605+00:00"}
{"context":{"subscriber_id":"ee4547e0-aaef-4956-b853-ade0ba436789","user_id":"990007560023456","workflow_id":"wf_hello_K3hqqZhF19BAFnodSTIx4XA"},"level":"info","message":"Handling request: {wf_api_terminate_request,\"255aa5b7d44bec40f84c892b9bffd436\"}","timestamp":"2022-11-21T21:02:14.590837+00:00"}
{"context":{"subscriber_id":"ee4547e0-aaef-4956-b853-ade0ba436789","user_id":"990007560023456","workflow_id":"wf_hello_K3hqqZhF19BAFnodSTIx4XA"},"level":"info","message":"Terminating workflow","timestamp":"2022-11-21T21:02:14.591573+00:00"}
{"context":{"subscriber_id":"ee4547e0-aaef-4956-b853-ade0ba436789","user_id":"990007560023456","workflow_id":"wf_hello_K3hqqZhF19BAFnodSTIx4XA"},"level":"info","message":"Stopping workflow with reason: \"normal\"","timestamp":"2022-11-21T21:02:14.592613+00:00"}

So consider adding debugLog() commands in your workflow code, perhaps in multiple places, and perhaps including variables in its parameter, such as:

...
    await workflow.sayAndWait(source_uri, `hello world`)
    await workflow.debugLog("greeting complete, myVar=" + myVar)
    ...
...
    await workflow.say_and_wait(interaction_uri, 'hello world')
    await workflow.debug_log("greeting complete, myVar=" + myVar)
    ...
...
    await Relay.SayAndWait(this, sourceUri, $"{greeting} {listenResponse["text"]}! You are currently using {deviceName}");
    await Relay.DebugLog(this, "greeting complete, myVar=" + myVar);
    ...
...
    relay.say(interactionUri, "Hello world");
    relay.debugLog("greeting complete, myVar=" + myVar);
    ...
...
    api.Say(sourceUri, "Hello " + name + " you are currently using " + deviceName, sdk.ENGLISH)
    api.DebugLog("greeting complete for name=" + name)
    ...