Visionary.AspNetCore
0.5.2
See the version list below for details.
dotnet add package Visionary.AspNetCore --version 0.5.2
NuGet\Install-Package Visionary.AspNetCore -Version 0.5.2
<PackageReference Include="Visionary.AspNetCore" Version="0.5.2" />
<PackageVersion Include="Visionary.AspNetCore" Version="0.5.2" />
<PackageReference Include="Visionary.AspNetCore" />
paket add Visionary.AspNetCore --version 0.5.2
#r "nuget: Visionary.AspNetCore, 0.5.2"
#:package Visionary.AspNetCore@0.5.2
#addin nuget:?package=Visionary.AspNetCore&version=0.5.2
#tool nuget:?package=Visionary.AspNetCore&version=0.5.2
Visionary for ASP.NET Core
A NuGet package, Visionary.AspNetCore, that collects what Visionary analyses,
straight from an ASP.NET Core application (minimal APIs, controllers, Razor
Pages, anything on endpoint routing):
- one row per HTTP request in
api_logs, with the route pattern, user, redacted headers and bodies, error codes, and how many database and outbound HTTP calls the request made; - periodic host, process, GC and throughput samples in
system_metrics; - database and
HttpClientspans inspans, exceptions inerrors, and a deploy marker inreleases,
written in batches on background services to Cloudflare D1, PostgreSQL, MySQL/MariaDB or SQLite. The Visionary server reads those tables for its dashboards.
It follows the same contract as the other Visionary SDKs; see
sdks/SPEC.md. The Go SDK in sdks/go is the reference
implementation.
Requirements: .NET 8 or later. The package depends only on the ASP.NET Core shared framework; database drivers are the application's choice.
Install
From nuget.org, for .NET 8 or later:
dotnet add package Visionary.AspNetCore
To try an unreleased commit, pack it into a local feed instead:
cd sdks/dotnet/Visionary.AspNetCore
dotnet pack -c Release -o ../../../local-packages
dotnet nuget add source "$(pwd)/../../../local-packages" --name visionary-local
dotnet add package Visionary.AspNetCore --version 0.1.0 # in your application
Quickstart: minimal API
using Styropyr0.Visionary;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddVisionary();
var app = builder.Build();
app.UseVisionary(); // first, before exception handlers, auth and routing
app.MapGet("/users/{id}", (string id, HttpContext ctx) =>
{
Visionary.SetUser(ctx, id, handle: "ann", role: "admin");
return Results.Ok(new { id });
});
app.Run();
export VISIONARY_DATABASE_URL=postgres://user:pass@db.internal:5432/app
dotnet run
You will see one line like
visionary: writing to postgres://user@db.internal:5432/app (postgres); requests on ....
The tables are created on first start (and older tables gain new columns).
Quickstart: controllers
using Styropyr0.Visionary;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddVisionary(o => o.PathPrefix = "/api");
var app = builder.Build();
app.UseVisionary();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Run();
[ApiController]
[Route("api/[controller]")]
public class OrdersController : ControllerBase
{
[HttpGet("{id:int}")]
public IActionResult Get(int id)
{
try
{
return Ok(Load(id));
}
catch (TimeoutException e)
{
Visionary.CaptureException(e); // a handled error, linked to this request
return StatusCode(503);
}
}
private static object Load(int id) => new { id };
}
This request is logged with route = /api/Orders/{id}.
With no database configured, the package logs one warning and does nothing else; the application starts and serves exactly as before. A database that goes down later never affects requests: writes fail on the background services, are retried, and are logged.
Choosing the database
The first match wins:
| Setting | Backend |
|---|---|
VisionaryOptions.DataSource (a DbDataSource, e.g. NpgsqlDataSource) or ConnectionFactory |
the application's own driver and pool; the dialect is detected from the provider or set with Dialect |
VISIONARY_DATABASE_URL=postgres://user:pass@host:5432/db (or postgresql://) |
PostgreSQL, through Npgsql |
VISIONARY_DATABASE_URL=mysql://user:pass@host:3306/db (or mariadb://) |
MySQL 8+ / MariaDB, through MySqlConnector (or MySql.Data) |
VISIONARY_DATABASE_URL=sqlite:///absolute/path.db, sqlite://relative.db |
SQLite, through Microsoft.Data.Sqlite |
VISIONARY_DATABASE_URL=d1://, or unset with D1_ACCOUNT_ID, D1_DATABASE_ID, D1_API_TOKEN |
Cloudflare D1 over its REST API (HttpClient, no driver); D1_API_BASE overrides the API URL |
The driver must be referenced by the application; the package finds it at runtime
(DbProviderFactories registrations first, then the driver's factory type). Query
parameters on postgres:// and mysql:// URLs are passed to the driver (for
example ?sslmode=require); user and password may be percent-encoded. On Windows,
sqlite:///C:/data/visionary.db is an absolute path.
Sharing the application's pool:
var dataSource = NpgsqlDataSource.Create(builder.Configuration.GetConnectionString("Default")!);
builder.Services.AddSingleton(dataSource);
builder.Services.AddVisionary(o => o.DataSource = dataSource);
Attaching the user
Call Visionary.SetUser(httpContext, id, handle, role) once the user is known,
typically in auth middleware. Without it, an authenticated HttpContext.User is
used: the NameIdentifier (or sub) claim as user_id, the identity name as
user_handle, and the role claim as user_role.
To fill in handle and role from an id, set LookupUser. It runs on the background
writer, once per distinct user per batch, only for users missing a handle or role:
builder.Services.AddVisionary(o => o.LookupUser = async (id, ct) =>
cache.TryGetValue(id, out var u) ? new VisionaryUser(id, u.Name, u.Role) : null);
Spans
Without any code, the package records:
HttpClientcalls (any handler, includingIHttpClientFactoryclients), from the runtime'sHttpHandlerDiagnosticListener:GET api.stripe.com, with statuserroron transport failures and 5xx responses;- Npgsql and MySqlConnector commands, from their
ActivitySources (ADO.NET, Dapper and EF Core alike); - EF Core commands on any provider (SQLite, SQL Server, ...), from EF Core's
DiagnosticListener. Commands a driver already reports are not counted twice.
Statements are stored sanitized (literals become ?, IN (...) lists collapse),
never with parameter values. Every logged request gets db_count, db_ms,
http_count and http_ms; span rows are kept for requests slower than
VISIONARY_SPAN_THRESHOLD_MS or answering 5xx, at most VISIONARY_SPAN_MAX each.
Plain ADO.NET on a driver without diagnostics (for example Dapper on SQLite) is not visible; time such calls, or cache and queue calls, by hand:
using (var span = Visionary.StartSpan("cache", "GET session", "redis/sessions"))
{
value = await redis.StringGetAsync(key);
}
The package's own writes are never recorded as spans.
Errors
Exceptions that escape the pipeline are recorded (handled = 0) and rethrown, so
the framework answers exactly as before; exceptions an UseExceptionHandler
placed after UseVisionary handled are recorded too. Visionary.CaptureException(ex)
records a handled one (handled = 1). Each row has the type, message, stack
(Exception.ToString()), and a fingerprint over the top five frames of your own
code (namespaces other than System.*, Microsoft.* and the SDK's), so the same
bug groups together across releases and machines.
Configuration
Every setting is read from the environment variable, or the IConfiguration key of
the same name (so appsettings.json works too), and can then be overridden in
AddVisionary(o => ...).
| Variable | Default | VisionaryOptions |
|---|---|---|
VISIONARY_DATABASE_URL |
see above | DatabaseUrl |
D1_ACCOUNT_ID, D1_DATABASE_ID, D1_API_TOKEN, D1_API_BASE |
D1AccountId, ... |
|
VISIONARY_INSTANCE |
hostname | Instance |
VISIONARY_LOG_REQUESTS |
true |
LogRequests |
VISIONARY_LOG_PATH_PREFIX |
empty (everything) | PathPrefix |
VISIONARY_LOG_BODIES |
true |
LogBodies |
VISIONARY_LOG_MAX_BODY_BYTES |
8192 |
MaxBodyBytes |
VISIONARY_LOG_RETENTION_DAYS |
30 (0 keeps forever) |
LogRetentionDays |
VISIONARY_LOG_REDACT_HEADERS, _REDACT_FIELDS, _REDACT_REQUEST_FIELDS |
empty (comma lists, added to the defaults) | RedactHeaders, ... |
VISIONARY_LOG_ERROR_CODE_FIELD, _ERROR_KEY_FIELD |
error.code, error.key |
ErrorCodeField, ErrorKeyField |
VISIONARY_SYSTEM_METRICS |
true |
SystemMetrics |
VISIONARY_SYSTEM_INTERVAL |
15s |
SystemInterval |
VISIONARY_SYSTEM_RETENTION_DAYS |
30 |
SystemRetentionDays |
VISIONARY_SERVICE |
empty | Service |
VISIONARY_RELEASE |
the platform's commit variable (GITHUB_SHA, RAILWAY_GIT_COMMIT_SHA, ...) |
Release |
VISIONARY_SPANS |
true |
Spans |
VISIONARY_SPAN_THRESHOLD_MS |
100 |
SpanThresholdMs |
VISIONARY_SPAN_MAX |
100 |
SpanMax |
VISIONARY_ERRORS |
true |
Errors |
DbStats reports connection pool numbers for the db_* columns; Route names
requests endpoint routing doesn't see (or call Visionary.SetRoute).
What is captured
- Requests: request id (
X-Request-IDin, or a new one, echoed on the response), method, path, route pattern (/users/{id}; inline constraints dropped), query, status (500 when the pipeline threw), duration, client IP (firstX-Forwarded-Forhop), user agent, user, headers (withAuthorization,Cookie,Set-Cookie,X-Api-Key, ... redacted), and bodies up to the cap with passwords, tokens, keys and card numbers redacted (JSON and form encoded, even when cut off). Bodies are copied as they stream past, so streaming responses still stream andSendFileAsynckeeps its zero-copy path for binary content. - System metrics: CPU (host and process; user, system, iowait, steal), load,
memory, cache and swap, disk space and inodes, disk and network throughput,
IOPS, latency, errors, TCP connections and retransmits, processes, context
switches, process I/O, threads, open handles against the limit, GC heap,
collections and pause time, thread pool size, and HTTP throughput. Linux reads
/proc; Windows uses Win32 counters; whatever a platform lacks is NULL.
Everything is queued without blocking the request (5000 entries at most; beyond that entries are dropped and counted) and written by one background service every 50 entries or 3 seconds, with two retries. Shutdown drains the queue.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.4.0 | 82 | 11/18/2026 |
| 1.3.0 | 94 | 11/13/2026 |
| 1.2.3 | 113 | 10/31/2026 |
| 1.2.2 | 103 | 10/31/2026 |
| 1.2.1 | 99 | 10/31/2026 |
| 1.2.0 | 108 | 10/31/2026 |
| 1.1.1 | 100 | 10/30/2026 |
| 1.1.0 | 104 | 10/28/2026 |
| 1.0.1 | 102 | 10/27/2026 |
| 1.0.0 | 105 | 10/27/2026 |
| 0.10.0 | 100 | 10/26/2026 |
| 0.9.0 | 109 | 10/25/2026 |
| 0.8.0 | 106 | 10/23/2026 |
| 0.7.1 | 102 | 10/23/2026 |
| 0.7.0 | 106 | 10/23/2026 |
| 0.6.1 | 99 | 10/22/2026 |
| 0.5.2 | 99 | 10/19/2026 |
| 0.5.1 | 90 | 10/19/2026 |
| 0.5.0 | 101 | 10/19/2026 |
| 0.4.0 | 103 | 10/18/2026 |