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

Results not getting stored in PostgreSQL #620

Open
ayushagarwal181 opened this issue Aug 24, 2022 · 1 comment
Open

Results not getting stored in PostgreSQL #620

ayushagarwal181 opened this issue Aug 24, 2022 · 1 comment

Comments

@ayushagarwal181
Copy link

I have integrated MiniProfiler v4.2.22 in my Asp.Net Core application.

Its is working as expected when using In-Memory database, but when i change the storage option to PostgreSQL no data is coming in the results.

Code Used -

services.AddMiniProfiler(options =>
{
    options.UserIdProvider = (request) =>
    {
        var id = request.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? request.HttpContext.User.FindFirst("sub")?.Value;
        return id;
    };

    options.RouteBasePath = "/profiler"; 
    options.PopupRenderPosition = StackExchange.Profiling.RenderPosition.BottomLeft;
    options.PopupShowTimeWithChildren = true;

    if (!string.IsNullOrEmpty(miniProfilerOptions?.PostgreSqlStorage?.ConectionString))
    {
        var storageOpt = miniProfilerOptions.PostgreSqlStorage;
        var storage = new PostgreSqlStorage(storageOpt.ConectionString, storageOpt.ProfilersTable, storageOpt.TimingsTable, storageOpt.ClientTimingsTable);
        _ = storage.TableCreationScripts;

        options.Storage = storage;
    }                   

    options.ShouldProfile = (request) =>
    {
        if (request.Path.StartsWithSegments("/healthcheck"))
        {
            return false;
        }

        return true;
    };
})
.AddEntityFramework();

appsettings.json -

"Monitoring": {
    "MiniProfiler": {
        "IsEnabled": true,
        "PostgreSqlStorage": {
             "ConectionString": "Server=localhost;Port=5432;Database=MiniProfilerTestDB;User ID=myLogin;Password=Password@1234567890;",
            "ProfilersTable": "MiniProfilersTable",
            "TimingsTable": "MiniProfilerTimingsTable",
            "ClientTimingsTable": "MiniProfilerClientTimingsTable"
        },
    },
}

Model -

public class MiniProfilerOptions
{
    public bool IsEnabled { get; set; }
    public PostgreSqlStorageOptions PostgreSqlStorage { get; set; }
}

public class PostgreSqlStorageOptions
{
    public string ConectionString { get; set; }
    public string ProfilersTable { get; set; }
    public string TimingsTable { get; set; }
    public string ClientTimingsTable { get; set; }
}

SQL query used to create table -

CREATE TABLE "MiniProfilersTable"
(
    RowId                                serial primary key,
    Id                                   uuid not null, -- don't cluster on a guid
    RootTimingId                         uuid null,
    Name                                 varchar(200) null,
    Started                              timestamp(3) not null,
    DurationMilliseconds                 decimal(15,1) not null,
    "User"                               varchar(100) null,
    HasUserViewed                        boolean not null,
    MachineName                          varchar(100) null,
    CustomLinksJson                      varchar,
    ClientTimingsRedirectCount           integer null
);

CREATE UNIQUE INDEX IX_MiniProfilersTable_Id ON "MiniProfilersTable" (Id);
        
CREATE INDEX IX_MiniProfilersTable_User_HasUserViewed_Includes ON "MiniProfilersTable" ("User", HasUserViewed);

CREATE TABLE "MiniProfilerTimingsTable"
(
    RowId                               serial primary key,
    Id                                  uuid not null,
    MiniProfilerId                      uuid not null,
    ParentTimingId                      uuid null,
    Name                                varchar(200) not null,
    DurationMilliseconds                decimal(15,3) not null,
    StartMilliseconds                   decimal(15,3) not null,
    IsRoot                              boolean not null,
    Depth                               smallint not null,
    CustomTimingsJson                   varchar null
);

CREATE UNIQUE INDEX IX_MiniProfilerTimingsTable_Id ON "MiniProfilerTimingsTable" (Id);

CREATE INDEX IX_MiniProfilerTimingsTable_MiniProfilerId ON "MiniProfilerTimingsTable" (MiniProfilerId);

CREATE TABLE "MiniProfilerClientTimingsTable"
(
    RowId                               serial primary key,
    Id                                  uuid not null,
    MiniProfilerId                      uuid not null,
    Name                                varchar(200) not null,
    Start                               decimal(9, 3) not null,
    Duration                            decimal(9, 3) not null
);

CREATE UNIQUE INDEX IX_MiniProfilerClientTimingsTable_Id on "MiniProfilerClientTimingsTable" (Id);

CREATE INDEX IX_MiniProfilerClientTimingsTable_MiniProfilerId on "MiniProfilerClientTimingsTable" (MiniProfilerId);

Am i doing something wrong ? or am i missing anything ?

StackOverflow Link - https://stackoverflow.com/questions/73440691/store-miniprofiler-results-in-postgresql

@NickCraver
Copy link
Member

What error are you getting? We don't guard here, so any error should surface. If that's not happening, my best guess is your options aren't actually wiring it up to save (e.g. something is null for a subtle reason).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants