InvergeDocs
.NETAPI reference

NexusClient & options

NexusClient & options in the .NET SDK.

SymbolKindSummary
INexusClientinterfaceA configured connection to one Nexus environment.
NexusClientclassOne object, every Nexus product.
NexusContextstatic classThe ambient telemetry context: bind identity once at the edge of a request, and everything captured underneath inherits it.
NexusOptionsclassEverything the client needs to talk to one Nexus environment.
NexusRequestclassOne call to the Nexus partner API.
NexusServicesstatic classThe Nexus products that can be switched off without removing the code that uses them.
NexusTelemetryContextclassWho and what a piece of telemetry belongs to.
NexusVersionstatic classThe SDK's own version, as reported to the API.
RoomMessageclassOne realtime message: the room, the event name or names, and the payload.

INexusClient

interface
interface Inverge.Nexus.INexusClient

A configured connection to one Nexus environment.

Register it as a singleton and share it. It is thread-safe, it owns the background buffers, and building one per request would both leak buffers and lose the batching that keeps telemetry cheap.

Dropped

property
long Dropped { get; }

How many buffered items have been dropped because a buffer was full.

Non-zero means telemetry is being lost — either the backend is unreachable or the process is producing more than MaxQueue can hold. Worth exposing as a metric.

Errors

property
ErrorsResource Errors { get; }

Error monitoring.

Events

property
EventsResource Events { get; }

Product analytics.

Flags

property
FlagsResource Flags { get; }

Feature flags.

InApp

property
InAppResource InApp { get; }

In-app messages.

property
LinksResource Links { get; }

Deep links and attribution.

LiveActivities

property
LiveActivitiesResource LiveActivities { get; }

Live Activities.

Logs

property
LogsResource Logs { get; }

Structured logging.

Options

property
NexusOptions Options { get; }

The options this client was built with.

Pending

property
int Pending { get; }

How many buffered telemetry items are waiting to be sent.

Push

property
PushResource Push { get; }

Push notifications.

Realtime

property
RealtimeResource Realtime { get; }

Realtime rooms.

RemoteConfig

property
RemoteConfigResource RemoteConfig { get; }

Remote Config.

Replay

property
ReplayResource Replay { get; }

Session replay ingestion.

Sessions

property
SessionsResource Sessions { get; }

People and journey sessions.

Surveys

property
SurveysResource Surveys { get; }

In-product surveys.

Voice

property
VoiceResource Voice { get; }

Voice (CPaaS) call control.

Background()

method
INexusClient Background(int workers = 1)

A sibling client on which every call is fire-and-forget.

Calls that need a response cannot work through it — there is nothing to return. Use the normal client for flags and Remote Config.

Parameters

Prop

Type

Returns INexusClient

CaptureExceptionAsync()

method
Task<ErrorCaptureResult> CaptureExceptionAsync(Exception exception, bool handled = true, object? errorContext = null, CancellationToken cancellationToken = default)

Reports a caught exception.

Parameters

Prop

Type

Returns Task<ErrorCaptureResult>

EmitAsync()

method
Task<EmitResult> EmitAsync(string room, string eventName, object? payload = null, CancellationToken cancellationToken = default)

Emits a named event to a realtime room.

Parameters

Prop

Type

Returns Task<EmitResult>

FlushAsync()

method
Task FlushAsync(TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Ships every buffered event and log line.

Call it before a short-lived process exits. A console app or a function that returns without flushing loses whatever is still buffered.

Parameters

Prop

Type

IdentifyAsync()

method
Task<IdentifyResult> IdentifyAsync(string distinctId, string? email = null, string? name = null, string? phone = null, object? traits = null, CancellationToken cancellationToken = default)

Sets the current person locally and creates or updates them server-side.

Parameters

Prop

Type

Returns Task<IdentifyResult>

IsEnabledAsync()

method
Task<bool> IsEnabledAsync(string key, string? distinctId = null, object? properties = null, bool fallback = false, CancellationToken cancellationToken = default)

Whether a feature flag is on for a person.

Parameters

Prop

Type

Returns Task<bool>

Reset()

method
void Reset()

Forgets the person and starts a new session — what you want on logout.

ResolveContext()

method
NexusTelemetryContext ResolveContext(NexusTelemetryContext? contextOverrides = null)

Client options, ambient context and per-call overrides, resolved in that order of increasing precedence.

Parameters

Prop

Type

Returns NexusTelemetryContext

SendAsync()

method
Task<JsonNode?> SendAsync(NexusRequest request, CancellationToken cancellationToken = default)

Executes a request against an endpoint the typed surface does not cover.

Parameters

Prop

Type

Returns Task<JsonNode?>

Track()

method
void Track(string name, object? properties = null, DateTimeOffset? timestamp = null, NexusTelemetryContext? context = null)

Captures one event. Returns as soon as it is buffered.

Parameters

Prop

Type

NexusClient

class
class Inverge.Nexus.NexusClient

One object, every Nexus product.

Build one per process and share it — see INexusClient. In an ASP.NET Core or worker app, prefer services.AddNexus(...) from Inverge.Nexus.Extensions.Logging, which registers it correctly and flushes it on shutdown.

NexusClient

constructor
new NexusClient(string apiKey, Action<NexusOptions>? configure = null)

Creates a client for an API key, layered over the NEXUS_* environment.

Parameters

Prop

Type

NexusClient

constructor
new NexusClient(NexusOptions options)

Creates a client from options.

Parameters

Prop

Type

NexusClient

constructor
new NexusClient(NexusOptions options, HttpClient httpClient)

Creates a client that sends through a caller-supplied HttpClient.

This is the IHttpClientFactory path: the app's own handler pipeline, resilience policies and connection lifetime apply, and the client is not disposed here.

Parameters

Prop

Type

NexusClient

constructor
new NexusClient(NexusOptions options, INexusTransport transport)

Creates a client that sends through a custom transport.

Parameters

Prop

Type

DistinctId

property
string? DistinctId { get; }

The person bound to the current execution flow, if any.

Dropped

property
long Dropped { get; }

Errors

property
ErrorsResource Errors { get; }

Events

property
EventsResource Events { get; }

Flags

property
FlagsResource Flags { get; }

InApp

property
InAppResource InApp { get; }

IsDisposed

property
bool IsDisposed { get; }

Whether the client has been disposed.

property
LinksResource Links { get; }

LiveActivities

property
LiveActivitiesResource LiveActivities { get; }

Logs

property
LogsResource Logs { get; }

Options

property
NexusOptions Options { get; }

Pending

property
int Pending { get; }

Push

property
PushResource Push { get; }

Realtime

property
RealtimeResource Realtime { get; }

RemoteConfig

property
RemoteConfigResource RemoteConfig { get; }

Replay

property
ReplayResource Replay { get; }

Sessions

property
SessionsResource Sessions { get; }

Surveys

property
SurveysResource Surveys { get; }

Voice

property
VoiceResource Voice { get; }

Background()

method
INexusClient Background(int workers = 1)

Parameters

Prop

Type

Returns INexusClient

CaptureExceptionAsync()

method
Task<ErrorCaptureResult> CaptureExceptionAsync(Exception exception, bool handled = true, object? errorContext = null, CancellationToken cancellationToken = default)

Parameters

Prop

Type

Returns Task<ErrorCaptureResult>

Dispose()

method
void Dispose()

Flushes and releases everything. Prefer DisposeAsync.

The flush is genuinely asynchronous, so this runs it on the thread pool and waits. Doing it inline would deadlock under a synchronization context that still has one thread. Hosts that support IAsyncDisposable — which includes the ASP.NET Core and Generic Host containers — take the async path and never reach this.

DisposeAsync()

method
ValueTask DisposeAsync()

Returns ValueTask

EmitAsync()

method
Task<EmitResult> EmitAsync(string room, string eventName, object? payload = null, CancellationToken cancellationToken = default)

Parameters

Prop

Type

Returns Task<EmitResult>

FlushAsync()

method
Task FlushAsync(TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Parameters

Prop

Type

IdentifyAsync()

method
Task<IdentifyResult> IdentifyAsync(string distinctId, string? email = null, string? name = null, string? phone = null, object? traits = null, CancellationToken cancellationToken = default)

Parameters

Prop

Type

Returns Task<IdentifyResult>

IsEnabledAsync()

method
Task<bool> IsEnabledAsync(string key, string? distinctId = null, object? properties = null, bool fallback = false, CancellationToken cancellationToken = default)

Parameters

Prop

Type

Returns Task<bool>

IsServiceEnabled()

method
bool IsServiceEnabled(string service)

Whether a product is on — Enabled, Services and the NEXUS_<SERVICE>_ENABLED environment, off wins. Every service is on by default.

Parameters

Prop

Type

Returns bool

Reset()

method
void Reset()

ResolveContext()

method
NexusTelemetryContext ResolveContext(NexusTelemetryContext? contextOverrides = null)

Parameters

Prop

Type

Returns NexusTelemetryContext

SendAsync()

method
Task<JsonNode?> SendAsync(NexusRequest request, CancellationToken cancellationToken = default)

Parameters

Prop

Type

Returns Task<JsonNode?>

Track()

method
void Track(string name, object? properties = null, DateTimeOffset? timestamp = null, NexusTelemetryContext? context = null)

Parameters

Prop

Type

NexusContext

static class
static class Inverge.Nexus.NexusContext

The ambient telemetry context: bind identity once at the edge of a request, and everything captured underneath inherits it.

Backed by AsyncLocal1, so the context is correct per request and flows across await` boundaries into whatever the handler calls — including work started on the thread pool.

One AsyncLocal1caveat worth knowing: a value set inside anasyncmethod does not flow back out to its caller. Bind at the level that should own the context — the middleware, the job handler — rather than deep inside a helper, or useScope`, whose lifetime is explicit.

Bind()

static method
static void Bind(NexusTelemetryContext context)

Merges values into the current context for the current flow.

Parameters

Prop

Type

Clear()

static method
static void Clear()

Drops the whole context: no person, no session, no device.

Identify()

static method
static void Identify(string? distinctId, IReadOnlyDictionary<string, object?>? properties = null)

Sets the current person for this flow.

This binds local context only. To also create or update the person server-side, call client.IdentifyAsync(...).

Parameters

Prop

Type

NewDeviceKey()

static method
static string NewDeviceKey()

A fresh opaque device key.

Returns string

NewSessionKey()

static method
static string NewSessionKey()

A fresh opaque session key.

Returns string

Reset()

static method
static void Reset(bool keepDevice = true)

Forgets the person and starts a new session — what you want on logout.

Parameters

Prop

Type

Scope()

static method
static IDisposable Scope(NexusTelemetryContext context)

Binds values for the lifetime of the returned scope, restoring the previous context when it is disposed.

Parameters

Prop

Type

Returns IDisposable

Scope()

static method
static IDisposable Scope(string? distinctId = null, string? sessionKey = null, string? deviceKey = null, string? release = null, string? appVersion = null, string? osType = null, string? osVersion = null, string? browser = null, string? country = null, string? url = null, IReadOnlyDictionary<string, object?>? properties = null)

Binds the fields you name for the lifetime of the returned scope.

Parameters

Prop

Type

Returns IDisposable

Set()

static method
static void Set(NexusTelemetryContext? context)

Replaces the context for the current execution flow.

Parameters

Prop

Type

Current

property
NexusTelemetryContext Current { get; }

The context in force for the current execution flow.

NexusOptions

class
class Inverge.Nexus.NexusOptions

Everything the client needs to talk to one Nexus environment.

An API key belongs to a single environment, so one client writes to one environment. The type is mutable so it works with the options pattern (services.AddNexus(o => ...)); the client copies it at construction, which means mutating it afterwards changes nothing already running.

ConstantDescription
const string DefaultBaseUrl = "https://services.inverge.net"The production API origin, used when nothing else is configured.

NexusOptions

constructor
new NexusOptions()

FromEnvironment()

static method
static NexusOptions FromEnvironment(Action<NexusOptions>? configure = null)

Builds options from the NEXUS_* environment, then applies configure on top.

The ordering matters and is the whole point: explicit code wins over the environment for the values it sets, while the values it leaves alone stay environment-driven, so a deployment can change settings such as NEXUS_TIMEOUT or the API key without a rebuild.

Parameters

Prop

Type

Returns NexusOptions

ApiKey

property
string ApiKey { get; set; }

The tenant API key (nxs_...). Required.

AppVersion

property
string? AppVersion { get; set; }

Default appVersion for telemetry that does not set one.

BaseUrl

property
string BaseUrl { get; set; }

The API origin. Point it at a local backend while developing.

Batch

property
bool Batch { get; set; }

Buffer events and log lines and ship them in the background, keeping telemetry off the request's hot path. Turn it off in a short-lived process if you prefer explicit sends; FlushAsync works either way.

Debug

property
bool Debug { get; set; }

Verbose SDK diagnostics.

DefaultHeaders

property
IDictionary<string, string> DefaultHeaders { get; }

Headers merged into every request.

DefaultProperties

property
IDictionary<string, object?> DefaultProperties { get; }

Properties merged into every captured event.

DiagnosticSink

property
NexusDiagnosticSink? DiagnosticSink { get; set; }

Where the SDK reports on itself — dropped batches, retries, delivery failures. Left unset, those messages go nowhere.

Inverge.Nexus.Extensions.Logging wires this to ILogger automatically. Set it yourself when you are not using Microsoft.Extensions.

Enabled

property
bool Enabled { get; set; }

false switches every Nexus service off without removing any code. Defaults to true: every service is on. Also NEXUS_ENABLED=false.

EnvironmentVariables

property
IReadOnlyDictionary<string, string> EnvironmentVariables { get; }

Environment variable names, by the option each one fills.

FlushInterval

property
TimeSpan FlushInterval { get; set; }

How long a partial batch waits before it is sent anyway.

HttpBase

property
string HttpBase { get; }

The API origin without a trailing slash.

MaxBatch

property
int MaxBatch { get; set; }

Maximum items per batched request. The ingest endpoints accept 1000; the default of 50 keeps individual requests small and failures cheap.

MaxQueue

property
int MaxQueue { get; set; }

Buffer capacity. Items beyond it are dropped and counted rather than growing memory without bound — a backend outage costs the memory you chose, not all of it.

MaxRetries

property
int MaxRetries { get; set; }

How many times to retry a safe request — telemetry ingest and reads — on a network error, 429, or 5xx. Calls with a side effect a user would notice twice are never retried, whatever this is set to.

OsType

property
string? OsType { get; set; }

Default osType for telemetry that does not set one.

OsVersion

property
string? OsVersion { get; set; }

Default osVersion for telemetry that does not set one.

RealtimeUrl

property
string? RealtimeUrl { get; set; }

The Socket.IO origin for the realtime listener. Defaults to BaseUrl.

Release

property
string? Release { get; set; }

Default release for telemetry that does not set one.

RemoteConfigCacheTtl

property
TimeSpan RemoteConfigCacheTtl { get; set; }

How long a resolved Remote Config template is reused in-process before it is revalidated. Defaults to 30 seconds.

ResolvedUserAgent

property
string ResolvedUserAgent { get; }

The user agent actually sent.

RetryBackoff

property
TimeSpan RetryBackoff { get; set; }

Base backoff delay; it doubles per attempt and carries jitter.

Services

property
IDictionary<string, bool> Services { get; }

Per-service switches, keyed by NexusServices names, e.g. Services[NexusServices.LiveActivities] = false. Empty by default — every service is on unless switched off here or by its NEXUS_<SERVICE>_ENABLED environment variable (off wins).

Silent

property
bool Silent { get; set; }

Never let a Nexus failure reach your code: calls return a default instead of throwing, and the failure goes to diagnostics. Background delivery is always silent regardless.

SocketBase

property
string SocketBase { get; }

The Socket.IO origin: RealtimeUrl, or the API origin.

Timeout

property
TimeSpan Timeout { get; set; }

Per-request timeout. Defaults to 10 seconds.

UserAgent

property
string? UserAgent { get; set; }

Overrides the default Inverge.Nexus.NET/<version> user agent.

ApplyEnvironment()

method
void ApplyEnvironment(Func<string, string?>? read = null)

Overlays any NEXUS_* variables that are set.

Parameters

Prop

Type

Clone()

method
NexusOptions Clone()

A deep copy, so the client is immune to later mutation.

Returns NexusOptions

IsServiceEnabled()

method
bool IsServiceEnabled(string service)

Whether a service is on: not switched off by Enabled, Services or the environment. Unknown names count as on.

Parameters

Prop

Type

Returns bool

ServiceOffReason()

method
string? ServiceOffReason(string service)

Why a service is off (for diagnostics), or null when it is on.

Parameters

Prop

Type

Returns string?

UrlFor()

method
string UrlFor(string path)

The absolute URL for a request path.

Parameters

Prop

Type

Returns string

Validate()

method
void Validate()

Throws when the options cannot produce a working client.

NexusRequest

class
class Inverge.Nexus.NexusRequest

One call to the Nexus partner API.

Resources build these; the client executes them. Pass one to SendAsync to reach an endpoint the typed surface does not cover yet.

NexusRequest

constructor
new NexusRequest(string method, string path, JsonObject? body = null, IReadOnlyDictionary<string, string>? headers = null, bool retryable = false)

Creates a request.

Parameters

Prop

Type

Body

property
JsonObject? Body { get; }

The JSON body, or null.

Headers

property
IReadOnlyDictionary<string, string>? Headers { get; }

Headers for this request only, merged over the configured defaults.

Method

property
string Method { get; }

The HTTP method, upper-cased.

Path

property
string Path { get; }

The path, rooted at the configured API origin.

Retryable

property
bool Retryable { get; }

Whether a failed attempt may be repeated.

BodyJson()

method
string BodyJson()

The body as compact JSON — useful in assertions and logs.

Returns string

NexusServices

static class
static class Inverge.Nexus.NexusServices

The Nexus products that can be switched off without removing the code that uses them. Every service is on by default.

From the environment (read by FromEnvironment): NEXUS_LIVE_ACTIVITIES_ENABLED=false switches only Live Activities off; NEXUS_ENABLED=false switches everything off. false, 0, off and no mean off; anything else, or unset, means on.

In code: options.Services[NexusServices.Push] = false or options.Enabled = false. Off wins — a service is on only if neither the code nor the environment turns it off, so operations can always switch one off with an environment variable.

A switched-off service makes no request and never throws: calls return their neutral result (flags → your fallback, Remote Config → your default, counts → zero), and events / logs are not even buffered.

ConstantDescription
const string AllEnvironmentVariable = "NEXUS_ENABLED"The master switch: NEXUS_ENABLED.
const string Errors = "errors"Error capture.
const string Events = "events"Product analytics events.
const string Flags = "flags"Feature flags.
const string InApp = "in_app"In-app messages.
const string Links = "links"Deep links.
const string LiveActivities = "live_activities"Live Activities.
const string Logs = "logs"Logs.
const string Push = "push"Push notifications.
const string Realtime = "realtime"Realtime rooms and emits.
const string RemoteConfig = "remote_config"Remote Config.
const string Replay = "replay"Session replay.
const string Sessions = "sessions"Sessions.
const string Surveys = "surveys"Surveys.
const string Telescope = "telescope"Telescope — request-journey tracing.
const string Voice = "voice"Voice.

ForPath()

static method
static string? ForPath(string? path)

The service a /partner/... path belongs to, or null for unswitched paths.

Parameters

Prop

Type

Returns string?

IsOn()

static method
static bool IsOn(string? value)

false / 0 / off / no = off; anything else, or unset, = on.

Parameters

Prop

Type

Returns bool

Normalize()

static method
static string? Normalize(string? service)

The canonical service name (accepts liveActivities etc.), or null if unknown.

Parameters

Prop

Type

Returns string?

EnvironmentVariables

property
IReadOnlyDictionary<string, string> EnvironmentVariables { get; }

Service → the environment variable that switches it.

NexusTelemetryContext

class
class Inverge.Nexus.NexusTelemetryContext

Who and what a piece of telemetry belongs to.

The same type serves two jobs: it is the ambient context bound by NexusContext, and it is the per-call override every resource method accepts. That is why none of the capture methods carry ten identity parameters.

Resolution order, lowest first: client options → ambient context → the context argument passed to the call.

NexusTelemetryContext

constructor
new NexusTelemetryContext()

AppVersion

property
string? AppVersion { get; init; }

The application version.

Browser

property
string? Browser { get; init; }

The browser, for web traffic.

Country

property
string? Country { get; init; }

Two-letter country code.

DeviceKey

property
string? DeviceKey { get; init; }

The device this belongs to.

DistinctId

property
string? DistinctId { get; init; }

The person this belongs to — your own user id.

IsEmpty

property
bool IsEmpty { get; }

Whether every field is unset.

OsType

property
string? OsType { get; init; }

The platform: ios, android, web, server.

OsVersion

property
string? OsVersion { get; init; }

The OS version.

Properties

property
IReadOnlyDictionary<string, object?>? Properties { get; init; }

Properties merged into every event captured in this scope — a request id, a tenant, whatever every event in the scope should carry.

Release

property
string? Release { get; init; }

The build/release that produced it.

SessionKey

property
string? SessionKey { get; init; }

The journey session this belongs to.

Url

property
string? Url { get; init; }

The URL or route in play.

Empty

field
static NexusTelemetryContext Empty

A context with nothing set.

Merge()

method
NexusTelemetryContext Merge(NexusTelemetryContext? other)

This context with every value set on other applied over it. Properties are merged key by key, not replaced wholesale.

Parameters

Prop

Type

Returns NexusTelemetryContext

NexusVersion

static class
static class Inverge.Nexus.NexusVersion

The SDK's own version, as reported to the API.

Current

property
string Current { get; }

The package version, e.g. 1.0.0.

UserAgent

property
string UserAgent { get; }

The User-Agent the SDK sends.

RoomMessage

class
class Inverge.Nexus.RoomMessage

One realtime message: the room, the event name or names, and the payload.

RoomMessage

constructor
new RoomMessage(string room, string event, object? payload = null)

Creates a message carrying one event name.

Parameters

Prop

Type

RoomMessage

constructor
new RoomMessage(string room, IEnumerable<string> events, object? payload = null)

Creates a message carrying several event names.

Parameters

Prop

Type

Events

property
IReadOnlyList<string> Events { get; }

The event names to emit.

Payload

property
object? Payload { get; }

The payload delivered to subscribers.

Room

property
string Room { get; }

The room name, as joined by subscribers.

On this page