Lab: Diagnostic Trace
This lab covers how to enable and review diagnostic trace for a sample Liberty application in OpenShift.
Theory
There are multiple ways to enable diagnostic trace in Liberty in an OpenShift environment:
- Add a
<logging traceSpecification=... />section toserver.xmlor add a configuration drop-in. This only works if runtime configuration updates are enabled, as they are by default. - If the application is installed using the WebSphere Liberty Operator, the WebSphereLibertyTrace custom resource may be used to enable and disable trace. This only works if runtime configuration updates are enabled, as they are by default, if the
WebSphereLibertyApplicationcustom resource has the properopenliberty.io/day2operationsannotation, and if the container has a/serviceabilitydirectory. - An application image may be re-built and re-deployed with an additional
<logging traceSpecification=... />section inserver.xmlor using a configuration drop-in.
There are various well-known diagnostic trace specifications for WebSphere Liberty.
Labs
Choose one or more labs:
- Lab: HTTP Diagnostic Trace by adding a configuration dropin
- Lab: HTTP Diagnostic Trace through the WebSphere Liberty Operator
Lab: HTTP Diagnostic Trace by adding a configuration dropin
This lab will enable HTTP diagnostic trace by adding a configuration dropin with a trace specification.
This lab will take approximately 10 minutes.
Step 1: Install example application
If you haven't already, install the sample application. If you installed it in a previous lab, you may continue using the previous installation.
Step 2: Configure diagnostic trace
Now that the application is installed and running, you will configure diagnostic trace. You will be modifying a running pod. In some real-world cases, this may be infeasible and the image will need to be re-built and re-deployed with the updated configuration.
Using the command line
-
List the pods for the example application deployment; for example:
oc get podsExample output:
NAME READY STATUS RESTARTS AGE libertydiag-b98748954-mgj64 1/1 Running 0 97s -
Open a shell into the pod by replacing
$PODwith a pod name from the previous command:oc rsh -t $PODFor example:
oc rsh -t libertydiag-b98748954-mgj64 -
Copy and paste the following command and press
Enter. Liberty will dynamically update the diagnostic trace configuration in the server.
echo '<?xml version="1.0" encoding="UTF-8"?><server><logging traceSpecification="*=info:com.ibm.ws.webcontainer*=all:com.ibm.wsspi.webcontainer*=all:HTTPChannel=all:GenericBNF=all:HTTPDispatcher=all" maxFileSize="100" maxFiles="10" /></server>' > /config/configDropins/overrides/trace.xml
Using the browser
- In the
Topologyview of theDeveloperperspective, click on thelibertydiagcircle, then click theResourcestab in the drawer on the right, and then click on the one pod that's running:

- Click on the
Terminaltab to open a remote shell into the running container in the pod:

- Copy and paste the following command and press
Enter. Liberty will dynamically update the diagnostic trace configuration in the server.
echo '<?xml version="1.0" encoding="UTF-8"?><server><logging traceSpecification="*=info:com.ibm.ws.webcontainer*=all:com.ibm.wsspi.webcontainer*=all:HTTPChannel=all:GenericBNF=all:HTTPDispatcher=all" maxFileSize="100" maxFiles="10" /></server>' > /config/configDropins/overrides/trace.xml
Step 3: Exercise an HTTP request
Now that HTTP diagnostic trace is configured, you will simulate an HTTP request to Liberty.
Using the command line
-
Request the following web page from your terminal to simulate an HTTP request:
-
macOS, Linux, or Windows with Cygwin:
curl -k -s "https://$(oc get route libertydiag "--output=jsonpath={.spec.host}")/servlet/Sleep" -
Windows with Command Prompt:
- Ensure you have
curlfor Windows installed -
List the application's URL:
oc get route libertydiag "--output=jsonpath={.spec.host}{'\n'}" -
Execute the following command, replacing
$HOSTwith the output of the previous command:curl -k -s "https://$HOST/servlet/Sleep"
- Ensure you have
-
Using the browser
- Click on the
/servlet/Sleeplink from the libertydiag application homepage:

Step 4: Disable diagnostic trace
Now that the diagnostic trace has been captured, you will learn how to disable the diagnostic trace.
Using the command line
-
List the pods for the example application deployment; for example:
oc get podsExample output:
NAME READY STATUS RESTARTS AGE libertydiag-b98748954-mgj64 1/1 Running 0 97s -
Open a shell into the pod by replacing
$PODwith a pod name from the previous command:oc rsh -t $PODFor example:
oc rsh -t libertydiag-b98748954-mgj64 -
Copy and paste the following command and press
Enter. Liberty will dynamically update the diagnostic trace configuration in the server back to its original value.rm /config/configDropins/overrides/trace.xml
Using the browser
- In the
Topologyview of theDeveloperperspective, click on thelibertydiagcircle, then click theResourcestab in the drawer on the right, and then click on the one pod that's running:

- Click on the
Terminaltab to open a remote shell into the running container in the pod:

- Copy and paste the following command and press
Enter. Liberty will dynamically update the diagnostic trace configuration in the server back to its original value.rm /config/configDropins/overrides/trace.xml
Step 5: Download trace logs
Download trace logs to your workstation.
Using the command line
-
List the pods for the example application deployment; for example:
oc get podsExample output:
NAME READY STATUS RESTARTS AGE libertydiag-ddf5f95b6-wj6dm 1/1 Running 0 97s -
Download the logs by replacing
$PODwith a pod name from above. Note thatoc cpdoes not support wildcards so the whole directory (or a single file) must be downloaded.oc cp $POD:/logs .For example:
oc cp libertydiag-ddf5f95b6-wj6dm:/logs . -
You should be able to find the
Sleeprequest executed above; for example:[1/3/23 16:48:19:462 UTC] 0000006d id=00000000 com.ibm.ws.webcontainer.servlet.ServletWrapper > handleRequest ServletWrapper[com.example.servlet.Sleep:[/servlet/Sleep]] ,request-> com.ibm.ws.webcontainer40.srt.SRTServletRequest40@20a8494e ,response-> com.ibm.ws.webcontainer40.srt.SRTServletResponse40@86c16c72 ENTRY [1/3/23 16:48:19:473 UTC] 0000006d id=00000000 com.example.util.BaseServlet I libertydiag: Invoking com.example.servlet.Sleep by anonymous (10.254.20.1)... [] [1/3/23 16:48:20:482 UTC] 0000006d id=00000000 com.example.util.BaseServlet I libertydiag: Done com.example.servlet.Sleep [1/3/23 16:48:20:495 UTC] 0000006d id=7d221183 com.ibm.ws.webcontainer.osgi.DynamicVirtualHost 3 Webcontainer handleRequest complete for--> [/servlet/Sleep], mapped webApp context [com.ibm.ws.webcontainer40.osgi.webapp.WebApp40@35a6e71f[libertydiag#libertydiag.war]], inboundConnection --> [com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink@22dbf0bd], this --> com.ibm.ws.webcontainer.osgi.DynamicVirtualHost$2@7d221183
Using the browser
Files other than native logs (equivalent to Liberty's console.log) cannot be downloaded through the browser. You must use the command line steps above. Alternatively, you may use the Terminal tab of the pod and cat the file in the browser.
Summary
In summary, this lab demonstrated how to configure HTTP diagnostic trace in Liberty, exercise a request, and download the trace logs.
Lab: HTTP Diagnostic Trace through the WebSphere Liberty Operator
This lab will enable HTTP diagnostic trace using the WebSphere Liberty Operator with an example application and review the output.
This lab will take approximately 10 minutes.
Step 1: Install example application
If you haven't already, install the sample application using the WebSphere Liberty operator. If you installed it in a previous lab, you may continue using the previous installation. If you previously installed the sample using a basic Kubernetes deployment, then uninstall it and re-install using the WebSphere Liberty operator.
Step 2: Configure diagnostic trace
Now that the application is installed and running, you will configure diagnostic trace using the WebSphere Liberty Operator trace custom resource.
Using the command line
-
List the pods for the example application deployment; for example:
oc get podsExample output:
NAME READY STATUS RESTARTS AGE libertydiag-b98748954-mgj64 1/1 Running 0 97s -
Create a
trace.yamlfile, replacing$PODwith the name of the pod from the previous command (e.g.libertydiag-b98748954-mgj64):apiVersion: liberty.websphere.ibm.com/v1 kind: WebSphereLibertyTrace metadata: name: libertytrace1 annotations: day2operation.openliberty.io/targetKinds: Pod spec: license: accept: true podName: $POD traceSpecification: "*=info:com.ibm.ws.webcontainer*=all:com.ibm.wsspi.webcontainer*=all:HTTPChannel=all:GenericBNF=all:HTTPDispatcher=all" maxFileSize: 100 maxFiles: 5 disable: false -
Apply the YAML:
oc apply -f trace.yaml
Using the browser
- Ensure the perspective is set to
Developerin the top left:

- Set your current namespace/project to what you were provided. For example:

- In the
Topologyview of theDeveloperperspective, click on thelibertydiagcircle, then click theResourcestab in the drawer on the right, and then copy the name of the pod that's running:

- Click
Operator Backedon the+Addpage:

- Click
WebSphereLibertyTraceand then clickCreate - Expand
Licenseand checkaccept - Paste the pod name from the step above into the
podNametext box. -
Set the
traceSpecificationto:*=info:com.ibm.ws.webcontainer*=all:com.ibm.wsspi.webcontainer*=all:HTTPChannel=all:GenericBNF=all:HTTPDispatcher=all -
Set
maxFileSizeto100 - Click
Create
Step 3: Exercise an HTTP request
Now that HTTP diagnostic trace is configured, you will simulate an HTTP request to Liberty.
Using the command line
-
Request the following web page from your terminal to simulate an HTTP request:
-
macOS, Linux, or Windows with Cygwin:
curl -k -s "https://$(oc get route libertydiag "--output=jsonpath={.spec.host}")/servlet/Sleep" -
Windows with Command Prompt:
- Ensure you have
curlfor Windows installed -
List the application's URL:
oc get route libertydiag "--output=jsonpath={.spec.host}{'\n'}" -
Execute the following command, replacing
$HOSTwith the output of the previous command:curl -k -s "https://$HOST/servlet/Sleep"
- Ensure you have
-
Using the browser
- Click on the
/servlet/Sleeplink from the libertydiag application homepage:

Step 4: Disable diagnostic trace
Now that the diagnostic trace has been captured, you will learn how to disable the diagnostic trace.
Using the command line
-
List
WebSphereLibertyTracecustom resources; for example:oc get wltraceExample output:
NAME PODNAME TRACING libertytrace1 libertydiag-5fdf699f-sfwqn True -
Delete the custom resource you created earlier; for example:
oc delete wltrace libertytrace1
Using the browser
- Click on
Search, click theResourcesdrop down, search fortrace, checkWebSphereLibertyTrace, click the vertical ellipses next to the custom resource created earlier, clickDelete WebSphereLibertyTrace, and clickDelete:

Step 5: Download trace logs
Download trace logs to your workstation.
Using the command line
-
List the pods for the example application deployment; for example:
oc get podsExample output:
NAME READY STATUS RESTARTS AGE libertydiag-ddf5f95b6-wj6dm 1/1 Running 0 97s -
Download the logs by replacing
$PODwith a pod name from above and$NAMESPACEwith your namespace. Note thatoc cpdoes not support wildcards so the whole directory (or a single file) must be downloaded.oc cp $POD:/serviceability/$NAMESPACE/$POD/ .For example:
oc cp libertydiag-ddf5f95b6-wj6dm:/serviceability/user15-namespace/libertydiag-ddf5f95b6-wj6dm/ . -
You should be able to find the
Sleeprequest executed above; for example:[1/3/23 16:48:19:462 UTC] 0000006d id=00000000 com.ibm.ws.webcontainer.servlet.ServletWrapper > handleRequest ServletWrapper[com.example.servlet.Sleep:[/servlet/Sleep]] ,request-> com.ibm.ws.webcontainer40.srt.SRTServletRequest40@20a8494e ,response-> com.ibm.ws.webcontainer40.srt.SRTServletResponse40@86c16c72 ENTRY [1/3/23 16:48:19:473 UTC] 0000006d id=00000000 com.example.util.BaseServlet I libertydiag: Invoking com.example.servlet.Sleep by anonymous (10.254.20.1)... [] [1/3/23 16:48:20:482 UTC] 0000006d id=00000000 com.example.util.BaseServlet I libertydiag: Done com.example.servlet.Sleep [1/3/23 16:48:20:495 UTC] 0000006d id=7d221183 com.ibm.ws.webcontainer.osgi.DynamicVirtualHost 3 Webcontainer handleRequest complete for--> [/servlet/Sleep], mapped webApp context [com.ibm.ws.webcontainer40.osgi.webapp.WebApp40@35a6e71f[libertydiag#libertydiag.war]], inboundConnection --> [com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink@22dbf0bd], this --> com.ibm.ws.webcontainer.osgi.DynamicVirtualHost$2@7d221183
Using the browser
Files other than native logs (equivalent to Liberty's console.log) cannot be downloaded through the browser. You must use the command line steps above. Alternatively, you may use the Terminal tab of the pod and cat the file in the browser.
Summary
In summary, this lab demonstrated how to configure HTTP diagnostic trace in Liberty using the WebSphere Liberty Operator, exercise a request, and download the trace logs.