NexusClient & options
NexusClient & options in the .NET SDK.
| Symbol | Kind | Summary |
|---|---|---|
INexusClient | interface | A configured connection to one Nexus environment. |
NexusClient | class | One object, every Nexus product. |
NexusContext | static class | The ambient telemetry context: bind identity once at the edge of a request, and everything captured underneath inherits it. |
NexusOptions | class | Everything the client needs to talk to one Nexus environment. |
NexusRequest | class | One call to the Nexus partner API. |
NexusServices | static class | The Nexus products that can be switched off without removing the code that uses them. |
NexusTelemetryContext | class | Who and what a piece of telemetry belongs to. |
NexusVersion | static class | The SDK's own version, as reported to the API. |
RoomMessage | class | One realtime message: the room, the event name or names, and the payload. |
INexusClient
interfaceinterface Inverge.Nexus.INexusClientA 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
propertylong 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
propertyErrorsResource Errors { get; }Error monitoring.
Events
propertyEventsResource Events { get; }Product analytics.
Flags
propertyFlagsResource Flags { get; }Feature flags.
InApp
propertyInAppResource InApp { get; }In-app messages.
Links
propertyLinksResource Links { get; }Deep links and attribution.
LiveActivities
propertyLiveActivitiesResource LiveActivities { get; }Live Activities.
Logs
propertyLogsResource Logs { get; }Structured logging.
Options
propertyNexusOptions Options { get; }The options this client was built with.
Pending
propertyint Pending { get; }How many buffered telemetry items are waiting to be sent.
Push
propertyPushResource Push { get; }Push notifications.
Realtime
propertyRealtimeResource Realtime { get; }Realtime rooms.
RemoteConfig
propertyRemoteConfigResource RemoteConfig { get; }Remote Config.
Replay
propertyReplayResource Replay { get; }Session replay ingestion.
Sessions
propertySessionsResource Sessions { get; }People and journey sessions.
Surveys
propertySurveysResource Surveys { get; }In-product surveys.
Voice
propertyVoiceResource Voice { get; }Voice (CPaaS) call control.
Background()
methodINexusClient 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()
methodTask<ErrorCaptureResult> CaptureExceptionAsync(Exception exception, bool handled = true, object? errorContext = null, CancellationToken cancellationToken = default)Reports a caught exception.
Parameters
Prop
Type
Returns Task<ErrorCaptureResult>
EmitAsync()
methodTask<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()
methodTask 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()
methodTask<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()
methodTask<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()
methodvoid Reset()Forgets the person and starts a new session — what you want on logout.
ResolveContext()
methodNexusTelemetryContext 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()
methodTask<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()
methodvoid 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
classclass Inverge.Nexus.NexusClientOne 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
constructornew NexusClient(string apiKey, Action<NexusOptions>? configure = null)Creates a client for an API key, layered over the NEXUS_* environment.
Parameters
Prop
Type
NexusClient
constructornew NexusClient(NexusOptions options)Creates a client from options.
Parameters
Prop
Type
NexusClient
constructornew 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
constructornew NexusClient(NexusOptions options, INexusTransport transport)Creates a client that sends through a custom transport.
Parameters
Prop
Type
DistinctId
propertystring? DistinctId { get; }The person bound to the current execution flow, if any.
Dropped
propertylong Dropped { get; }Errors
propertyErrorsResource Errors { get; }Events
propertyEventsResource Events { get; }Flags
propertyFlagsResource Flags { get; }InApp
propertyInAppResource InApp { get; }IsDisposed
propertybool IsDisposed { get; }Whether the client has been disposed.
Links
propertyLinksResource Links { get; }LiveActivities
propertyLiveActivitiesResource LiveActivities { get; }Logs
propertyLogsResource Logs { get; }Options
propertyNexusOptions Options { get; }Pending
propertyint Pending { get; }Push
propertyPushResource Push { get; }Realtime
propertyRealtimeResource Realtime { get; }RemoteConfig
propertyRemoteConfigResource RemoteConfig { get; }Replay
propertyReplayResource Replay { get; }Sessions
propertySessionsResource Sessions { get; }Surveys
propertySurveysResource Surveys { get; }Voice
propertyVoiceResource Voice { get; }Background()
methodINexusClient Background(int workers = 1)Parameters
Prop
Type
Returns INexusClient
CaptureExceptionAsync()
methodTask<ErrorCaptureResult> CaptureExceptionAsync(Exception exception, bool handled = true, object? errorContext = null, CancellationToken cancellationToken = default)Parameters
Prop
Type
Returns Task<ErrorCaptureResult>
Dispose()
methodvoid 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()
methodValueTask DisposeAsync()Returns ValueTask
EmitAsync()
methodTask<EmitResult> EmitAsync(string room, string eventName, object? payload = null, CancellationToken cancellationToken = default)Parameters
Prop
Type
Returns Task<EmitResult>
FlushAsync()
methodTask FlushAsync(TimeSpan? timeout = null, CancellationToken cancellationToken = default)Parameters
Prop
Type
IdentifyAsync()
methodTask<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()
methodTask<bool> IsEnabledAsync(string key, string? distinctId = null, object? properties = null, bool fallback = false, CancellationToken cancellationToken = default)Parameters
Prop
Type
Returns Task<bool>
IsServiceEnabled()
methodbool 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()
methodvoid Reset()ResolveContext()
methodNexusTelemetryContext ResolveContext(NexusTelemetryContext? contextOverrides = null)Parameters
Prop
Type
Returns NexusTelemetryContext
SendAsync()
methodTask<JsonNode?> SendAsync(NexusRequest request, CancellationToken cancellationToken = default)Parameters
Prop
Type
Returns Task<JsonNode?>
Track()
methodvoid Track(string name, object? properties = null, DateTimeOffset? timestamp = null, NexusTelemetryContext? context = null)Parameters
Prop
Type
NexusContext
static classstatic class Inverge.Nexus.NexusContextThe 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 methodstatic void Bind(NexusTelemetryContext context)Merges values into the current context for the current flow.
Parameters
Prop
Type
Clear()
static methodstatic void Clear()Drops the whole context: no person, no session, no device.
Identify()
static methodstatic 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 methodstatic string NewDeviceKey()A fresh opaque device key.
Returns string
NewSessionKey()
static methodstatic string NewSessionKey()A fresh opaque session key.
Returns string
Reset()
static methodstatic void Reset(bool keepDevice = true)Forgets the person and starts a new session — what you want on logout.
Parameters
Prop
Type
Scope()
static methodstatic 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 methodstatic 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 methodstatic void Set(NexusTelemetryContext? context)Replaces the context for the current execution flow.
Parameters
Prop
Type
Current
propertyNexusTelemetryContext Current { get; }The context in force for the current execution flow.
NexusOptions
classclass Inverge.Nexus.NexusOptionsEverything 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.
| Constant | Description |
|---|---|
const string DefaultBaseUrl = "https://services.inverge.net" | The production API origin, used when nothing else is configured. |
NexusOptions
constructornew NexusOptions()FromEnvironment()
static methodstatic 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
propertystring ApiKey { get; set; }The tenant API key (nxs_...). Required.
AppVersion
propertystring? AppVersion { get; set; }Default appVersion for telemetry that does not set one.
BaseUrl
propertystring BaseUrl { get; set; }The API origin. Point it at a local backend while developing.
Batch
propertybool 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
propertybool Debug { get; set; }Verbose SDK diagnostics.
DefaultHeaders
propertyIDictionary<string, string> DefaultHeaders { get; }Headers merged into every request.
DefaultProperties
propertyIDictionary<string, object?> DefaultProperties { get; }Properties merged into every captured event.
DiagnosticSink
propertyNexusDiagnosticSink? 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
propertybool 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
propertyIReadOnlyDictionary<string, string> EnvironmentVariables { get; }Environment variable names, by the option each one fills.
FlushInterval
propertyTimeSpan FlushInterval { get; set; }How long a partial batch waits before it is sent anyway.
HttpBase
propertystring HttpBase { get; }The API origin without a trailing slash.
MaxBatch
propertyint 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
propertyint 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
propertyint 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
propertystring? OsType { get; set; }Default osType for telemetry that does not set one.
OsVersion
propertystring? OsVersion { get; set; }Default osVersion for telemetry that does not set one.
RealtimeUrl
propertystring? RealtimeUrl { get; set; }The Socket.IO origin for the realtime listener. Defaults to BaseUrl.
Release
propertystring? Release { get; set; }Default release for telemetry that does not set one.
RemoteConfigCacheTtl
propertyTimeSpan RemoteConfigCacheTtl { get; set; }How long a resolved Remote Config template is reused in-process before it is revalidated. Defaults to 30 seconds.
ResolvedUserAgent
propertystring ResolvedUserAgent { get; }The user agent actually sent.
RetryBackoff
propertyTimeSpan RetryBackoff { get; set; }Base backoff delay; it doubles per attempt and carries jitter.
Services
propertyIDictionary<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
propertybool 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
propertystring SocketBase { get; }The Socket.IO origin: RealtimeUrl, or the API origin.
Timeout
propertyTimeSpan Timeout { get; set; }Per-request timeout. Defaults to 10 seconds.
UserAgent
propertystring? UserAgent { get; set; }Overrides the default Inverge.Nexus.NET/<version> user agent.
ApplyEnvironment()
methodvoid ApplyEnvironment(Func<string, string?>? read = null)Overlays any NEXUS_* variables that are set.
Parameters
Prop
Type
Clone()
methodNexusOptions Clone()A deep copy, so the client is immune to later mutation.
Returns NexusOptions
IsServiceEnabled()
methodbool 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()
methodstring? ServiceOffReason(string service)Why a service is off (for diagnostics), or null when it is on.
Parameters
Prop
Type
Returns string?
UrlFor()
methodstring UrlFor(string path)The absolute URL for a request path.
Parameters
Prop
Type
Returns string
Validate()
methodvoid Validate()Throws when the options cannot produce a working client.
NexusRequest
classclass Inverge.Nexus.NexusRequestOne 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
constructornew NexusRequest(string method, string path, JsonObject? body = null, IReadOnlyDictionary<string, string>? headers = null, bool retryable = false)Creates a request.
Parameters
Prop
Type
Body
propertyJsonObject? Body { get; }The JSON body, or null.
Headers
propertyIReadOnlyDictionary<string, string>? Headers { get; }Headers for this request only, merged over the configured defaults.
Method
propertystring Method { get; }The HTTP method, upper-cased.
Path
propertystring Path { get; }The path, rooted at the configured API origin.
Retryable
propertybool Retryable { get; }Whether a failed attempt may be repeated.
BodyJson()
methodstring BodyJson()The body as compact JSON — useful in assertions and logs.
Returns string
NexusServices
static classstatic class Inverge.Nexus.NexusServicesThe 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.
| Constant | Description |
|---|---|
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 methodstatic string? ForPath(string? path)The service a /partner/... path belongs to, or null for unswitched paths.
Parameters
Prop
Type
Returns string?
IsOn()
static methodstatic bool IsOn(string? value)false / 0 / off / no = off; anything else, or unset, = on.
Parameters
Prop
Type
Returns bool
Normalize()
static methodstatic string? Normalize(string? service)The canonical service name (accepts liveActivities etc.), or null if unknown.
Parameters
Prop
Type
Returns string?
EnvironmentVariables
propertyIReadOnlyDictionary<string, string> EnvironmentVariables { get; }Service → the environment variable that switches it.
NexusTelemetryContext
classclass Inverge.Nexus.NexusTelemetryContextWho 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
constructornew NexusTelemetryContext()AppVersion
propertystring? AppVersion { get; init; }The application version.
Browser
propertystring? Browser { get; init; }The browser, for web traffic.
Country
propertystring? Country { get; init; }Two-letter country code.
DeviceKey
propertystring? DeviceKey { get; init; }The device this belongs to.
DistinctId
propertystring? DistinctId { get; init; }The person this belongs to — your own user id.
IsEmpty
propertybool IsEmpty { get; }Whether every field is unset.
OsType
propertystring? OsType { get; init; }The platform: ios, android, web, server.
OsVersion
propertystring? OsVersion { get; init; }The OS version.
Properties
propertyIReadOnlyDictionary<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
propertystring? Release { get; init; }The build/release that produced it.
SessionKey
propertystring? SessionKey { get; init; }The journey session this belongs to.
Url
propertystring? Url { get; init; }The URL or route in play.
Empty
fieldstatic NexusTelemetryContext EmptyA context with nothing set.
Merge()
methodNexusTelemetryContext 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 classstatic class Inverge.Nexus.NexusVersionThe SDK's own version, as reported to the API.
Current
propertystring Current { get; }The package version, e.g. 1.0.0.
UserAgent
propertystring UserAgent { get; }The User-Agent the SDK sends.
RoomMessage
classclass Inverge.Nexus.RoomMessageOne realtime message: the room, the event name or names, and the payload.
RoomMessage
constructornew RoomMessage(string room, string event, object? payload = null)Creates a message carrying one event name.
Parameters
Prop
Type
RoomMessage
constructornew RoomMessage(string room, IEnumerable<string> events, object? payload = null)Creates a message carrying several event names.
Parameters
Prop
Type
Events
propertyIReadOnlyList<string> Events { get; }The event names to emit.
Payload
propertyobject? Payload { get; }The payload delivered to subscribers.
Room
propertystring Room { get; }The room name, as joined by subscribers.
