Docs
Tenantry CoreAPI reference

TenantTelemetry class

Namespace: Tenantry · Package: Tenantry.Core · API reference

The names Tenantry records a tenant under in traces and logs: Tenantry.AspNetCore's app.UseTenantry() for a request, and Tenantry.Pro for jobs, messages and background work. Use them to record the tenant the same way in your own code, or to query and alert on it.

public static class TenantTelemetry

Fields

LogScopeName

The property that carries the tenant's id in a log scope: TenantId, the id formatted by TenantIds.Format<TKey>.

public const string LogScopeName = "TenantId"

Returns: string

TenantIdTag

The tag that carries the tenant's id on a span (an Activity) or a metric: tenant.id, the id formatted by TenantIds.Format<TKey>.

public const string TenantIdTag = "tenant.id"

Returns: string

Methods

CreateLogScope(string)

The state of a log scope with one property, TenantTelemetry.LogScopeName, for ILogger.BeginScope. A logging provider that records scopes (Serilog's, or the console's and OpenTelemetry's with IncludeScopes) adds the property to every entry written while the scope is open; its text is TenantId:<id>.

public static IReadOnlyList<KeyValuePair<string, object?>> CreateLogScope(string tenantId)

Parameters:

Returns: IReadOnlyList<KeyValuePair<string, object>>: The scope's state.

Exceptions:

  • ArgumentNullException: tenantId is null.

CreateLogScope<TKey>(TKey)

The state of a log scope with one property, TenantTelemetry.LogScopeName, for ILogger.BeginScope, with the id formatted as Tenantry formats it everywhere (TenantIds.Format<TKey>), so log entries can be queried by it.

public static IReadOnlyList<KeyValuePair<string, object?>> CreateLogScope<TKey>(TKey tenantId) where TKey : IEquatable<TKey>, IParsable<TKey>

Type parameters:

  • TKey: The tenant identifier type.

Parameters:

  • tenantId TKey: The tenant's id.

Returns: IReadOnlyList<KeyValuePair<string, object>>: The scope's state.

Exceptions:

  • ArgumentNullException: tenantId is null.
using (logger.BeginScope(TenantTelemetry.CreateLogScope(tenantId)))
{
    logger.LogInformation("Invoicing");   // carries TenantId
}

On this page