Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Blazor Server #2329

Open
mattjohnsonpint opened this issue Apr 25, 2023 · 1 comment
Open

Support Blazor Server #2329

mattjohnsonpint opened this issue Apr 25, 2023 · 1 comment
Labels
Feature New feature or request Framework: Blazor

Comments

@mattjohnsonpint
Copy link
Contributor

Problem Statement

We should investigate better support for Blazor Server

Solution Brainstorm

Could include a new package, or might just need improved guidance docs.

Also related: #1685

@monderino
Copy link

Hi,

is there any progress on this topic?
Or maybe a best practice to implement a custom tracing?

I tried the following approach, but I'm not sure if this is correct.
Every Page I want to include inherits from this page.

public abstract partial class AbstractPage
{
    private ITransaction _transaction;
    private ISpan _span;
    private string _currentUri;

    public override Task SetParametersAsync(ParameterView parameters)
    {
        _currentUri = NavigationManager.Uri;
        Console.Write($@"SetParameters {_currentUri}");
        _transaction = SentrySdk.StartTransaction(
            NavigationManager.Uri, // name
            NavigationManager.Uri // operation
        );
        
        // Validate the cart
        _span = _transaction.StartChild(
            GetType().Name, // operation
            "init" // description
        );
        
        // Set transaction on scope to associate with errors and get included span instrumentation
        // If there's currently an unfinished transaction, it may be dropped
        SentrySdk.ConfigureScope(scope => scope.Transaction = _transaction);
        
        return base.SetParametersAsync(parameters);
    }

    protected override Task OnInitializedAsync()
    {
        Console.Write($@"OnInitialized {_currentUri}");
        return base.OnInitializedAsync();
    }
    
    protected override Task OnAfterRenderAsync(bool firstRender)
    {
        if(firstRender)
        {
            Console.Write($@"OnAfterRender first {_currentUri}");
            _span?.Finish();
            _transaction?.Finish();
        }
        else
        {
            Console.Write($@"OnAfterRender {_currentUri} ");
        }
        return base.OnAfterRenderAsync(firstRender);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature or request Framework: Blazor
Projects
Status: No status
Archived in project
Development

No branches or pull requests

3 participants