-
-
Notifications
You must be signed in to change notification settings - Fork 7
Method Tracer
Bozhidar Zashev edited this page Jun 12, 2025
·
6 revisions
The method tracers are feeding runtime information to the library. All calls are processed in a different thread and are not influencing your method execution time. They reveal the broader picture or where to look into details for issues.
The method tracers are dependent on two method calls:
- at the start of the traced method: WvBlazorTraceService.OnEnter
- at the end of the traced method: WvBlazorTraceService.OnExit
This ensures that we get a complete picture of the method execution at runtime. The best way is to first start with all your LifeCycle methods:
- OnInitialized,OnInitializedAsync
- OnAfterRender, OnAfterRenderAsync
- OnParametersSet, OnParametersSetAsync
- ShouldRender
- Dispose, DisposeAsync (if you have it)
// if razor component without code behind
@attribute [WvBlazorTrace]// if razor.cs code behind you can decorate the entire class
[WvBlazorTrace]
public partial class Test1 : ComponentBase
{
//code...
}// if razor.cs code behind you can decorate only several methods you need traced
public partial class Test1 : ComponentBase
{
[WvBlazorTrace]
private void _countTest1(){}
}Here is an example:
protected override void OnInitialized()
{
WvBlazorTraceService.OnEnter(component: this);
base.OnInitialized();
//Do something
WvBlazorTraceService.OnExit(component: this);
}if there are many returns in the method you can also do it with try/finally block
protected override void OnInitialized()
{
try
{
WvBlazorTraceService.OnEnter(component: this);
base.OnInitialized();
//Do something
}
finally
{
WvBlazorTraceService.OnExit(component: this);
}
}IMPORTANT: method duration and memory delta are evaluated only OnExit.
Both methods have the following arguments for fine tuning the trace:
| argument | type | default | description |
|---|---|---|---|
| component | ComponentBase (required) | none | the component instance that calls the method. Usually provided with 'this' |
| traceId | Guid? (recommended) | null | unique identifier for pairing OnEnter and OnExit calls. If not provided will pair with the first non exited trace |
| instanceTag | string? | null | NULL by default, will group all instances of the component in the trace. To tag each separate instance of the component you need to provide unique tag for it. |
| customData | string? | null | custom string or JSON that you need stored with each call for more advanced tracing |
| firstRender | bool? | null | when available, usually if the tracer is called by OnAfterRender methods |
| options | WvTraceMethodOptions | new() | setting up the limits, exceeding which will be presented by the service as a limit exceeded |
| methodName | string | automatic | Automatically initialized by [CallerMemberName] atttribute. Override only if you need to. |
The options WvTraceMethodOptions model has the following properties:
| argument | type | default | description |
|---|---|---|---|
| DurationLimitMS | long | 1000 | How many milliseconds is an OK for executing this method. |
| CallLimit | long | 10 | How many calls is OK for this method. |
| MemoryLimitTotalBytes | long | 2048 | What is the total maximum memory limit. |
| MemoryLimitDeltaBytes | long | 2048 | What is the maximum memory delta limit between enter and exit. |