7. 2nd Bug - hunt via traces
Open the Distributed Tracing App#
Protip: Open the Tracing App anywhere in Dynatrace
Type CTRL + K, then search for 'Tracing'. The Tracing App should appear in the Super Search.
Want to learn more about the Tracing App?
If you want to learn more about the new Distributed Tracing App, watch this amazing 12 min recording of Dynatrace App Spotlights
In the filter add:
"Kubernetes namespace" = todoapp AND "Kubernetes workload" = todoapp
You can also let the autocomplete help you or use the facets on the left-hand side to filter for all requests of the Pod todoapp
that is deployed in the namespace todoapp
.
If we take a look at the traces, we can see there is a trace named addTodo
. By opening this trace, in the details pane on the right-hand side, we can see in the Code Attributes
that the Code function = addTodo
and the Code Namespace = com.dynatrace.todoapp.TodoController
Now we know where in the application code we should be looking for the bug!
Open the Live Debugger#
- Let's search for the
Code function = addTodo
under theCode Namespace = com.dynatrace.todoapp.TodoController
. In the search, typeTodoController
the class file appears, open it. - Now let's search for the
AddTodo
function, the declaration is in line 24.
Notice anything unusual? The developer left a String function on line 28:
28
String todoTitle = newTodoRecord.getTitle().replaceAll("[^a-zA-Z0-9\s]+", "");
- Let's add two breakpoints around that line, one before, let's say on line 25 and another on line 32.
- Go to the TodoApp in your browser and add a Task with a special character.
Task:
This is exciting!!!
- Go back to the Live Debugger and watch the two snapshots, snapshots get gathered in real time.
- If you open the first snapshot, the one on line 25, you'll notice the Object
newTodoRecord.title = This is exciting!!!
that contains the exclamation mark. Meaning the data is being correctly passed on to the functionaddTodo
, but then something happens and the!!!
are removed. - If you then look for the same attribute in the same method on the second snapshot you'll see that the
!!!
are gone.
Watching variables#
- We want to make your life as a developer easier. With the Live Debugger you can watch variables, right click on the
newTodoRecord.title
and selectWatch
- You'll see that in the snapshots, the title variable captured in both snapshots are added for ease of debugging complex applications. This is a very simple app, but imagine you have hundreds or thousands of lines of code, not all of them written by you, using this strategy you can understand how specific variables change through the code.