AppSurfaceOtlpExporterMode ExporterMode { get; set; }
Source
Gets or sets when AppSurface should add OTLP exporters.
Provides host-builder extensions for enabling AppSurface observability outside module discovery.
IHostBuilder ConfigureAppSurfaceObservability(this IHostBuilder builder, StartupContext context, Action<AppSurfaceObservabilityOptions>? configure = null)
Configures OpenTelemetry logging, tracing, and metrics for an AppSurface host.
builder
context
configure
The supplied builder
.
Use this extension when a custom host does not activate AppSurfaceObservabilityModule
through the module dependency graph. Multiple calls are safe and first registration wins, which keeps configured options aligned with the OpenTelemetry providers and exporters captured during registration.
ResourceBuilder Create(AppSurfaceObservabilityPlan plan)
Creates the shared OpenTelemetry resource builder for AppSurface observability providers.
plan
A resource builder containing OpenTelemetry defaults plus AppSurface service identity values.
Use this factory when logging, tracing, or metrics registration must share the same resource identity. It starts from ResourceBuilder.CreateDefault
so OpenTelemetry's standard SDK, process, and host defaults remain available, then applies the AppSurface service name and optional version. Hosts that need additional attributes can still add them through their own OpenTelemetry configuration after AppSurface registration.
Reads environment variables for observability plan resolution.
This internal seam keeps endpoint precedence tests deterministic without mutating process-wide environment state. Implementations should preserve the platform behavior of returning null
when a variable is not set; callers normalize blank values separately so empty environment variables do not become configured endpoints.
string? GetEnvironmentVariable(string variable)
Gets the value of an environment variable.
variable
The configured value, or null
when the variable is not present.
Default process environment reader used by AppSurface observability.
The singleton Instance
avoids repeated allocation while keeping the production path explicit. Tests should use IAppSurfaceEnvironmentReader
rather than changing real environment variables.
Configures AppSurface's application-side OpenTelemetry registration.
These options live under the AppSurfaceObservability
configuration section. The default exporter mode keeps local and test runs quiet unless Aspire or another host supplies an OTLP endpoint. The service identity values are written to OpenTelemetry resource metadata; they do not change the .NET Generic Host application identity used for static web assets or framework hosting behavior.
AppSurfaceOtlpExporterMode ExporterMode { get; set; }
Source
Gets or sets when AppSurface should add OTLP exporters.
Uri? OtlpEndpoint { get; set; }
Source
Gets or sets the AppSurface-owned OTLP endpoint.
When set, this endpoint takes precedence over OTEL_EXPORTER_OTLP_ENDPOINT
. Use AppSurfaceObservability:OtlpEndpoint
in JSON-style configuration or AppSurfaceOtlpEndpointEnvironmentVariable
in environment-variable configuration.
string? ServiceName { get; set; }
Source
Gets or sets the OpenTelemetry resource service name.
When omitted, AppSurface uses Core.StartupContext.ApplicationName
and then the root module assembly name fallback.
string? ServiceVersion { get; set; }
Source
Gets or sets the OpenTelemetry resource service version.
AppSurface emits service.version
only when this value is configured.
Marks that AppSurface tracing, metrics, resource, and startup-diagnostic services have already been registered.
The service-collection extension uses this marker to make provider registration idempotent. First registration wins because OpenTelemetry captures resource and exporter setup when providers are configured; later calls should not silently replace the plan or create duplicate providers.
Marks that AppSurface OpenTelemetry logging has already been registered.
The logging extension uses this marker to preserve first-registration-wins behavior for log exporter setup. Keep this marker separate from AppSurfaceObservabilityServicesRegistrationMarker
because logging is registered through ILoggingBuilder
before the tracing and metrics service path in module-based hosts.
Provides service-registration extensions for AppSurface observability.
IServiceCollection AddAppSurfaceObservability(this IServiceCollection services, StartupContext context, IConfiguration configuration, Action<AppSurfaceObservabilityOptions>? configure = null)
Adds AppSurface OpenTelemetry tracing and metrics to the service collection.
services
context
configuration
AppSurfaceObservabilityOptions
.configure
The supplied services
.
This extension is the app-runtime side of Aspire observability: it never references Aspire hosting packages and it registers OTLP exporters only according to AppSurfaceObservabilityOptions.ExporterMode
. Repeated calls are idempotent and first registration wins, which keeps configured options aligned with the captured OpenTelemetry resource, tracing, and metrics setup.
IServiceCollection AddAppSurfaceObservability(this IServiceCollection services, StartupContext context, IConfiguration configuration, Action<AppSurfaceObservabilityOptions>? configure, bool registerOptions)
Adds AppSurface tracing and metrics with explicit control over options registration.
services
context
configuration
configure
registerOptions
true
to bind and validate options in DI; false
when logging or a host hook has already registered them.
The supplied services
.
The registration marker makes this path idempotent. First registration wins because OpenTelemetry captures resource, tracing, metrics, and exporter setup when providers are registered.
IServiceCollection ConfigureAppSurfaceObservability(this IServiceCollection services, Action<AppSurfaceObservabilityOptions>? configure = null)
Registers and validates AppSurfaceObservabilityOptions
without adding OpenTelemetry providers.
services
configure
The supplied services
.
Use this extension for consumers that read IOptions{TOptions}
directly. Values that should affect AppSurface-owned OpenTelemetry resource or exporter setup must be supplied through the first provider-registration call, because OpenTelemetry captures that setup when providers are registered.
IServiceCollection ConfigureAppSurfaceObservability(this IServiceCollection services, IConfiguration configuration, Action<AppSurfaceObservabilityOptions>? configure = null)
Registers and validates AppSurface observability options from a supplied configuration instance.
services
configuration
configure
The supplied services
.
This overload avoids DI configuration split-brain for hosts that pass a specific configuration object into registration. Provider setup must use the same configuration instance that options binding uses.
OptionsBuilder<AppSurfaceObservabilityOptions> AddOptionsBuilder(IServiceCollection services)
Creates the shared options builder and validation rules.
services
The configured options builder.
Validation fails closed for undefined exporter modes and relative OTLP endpoints so invalid telemetry configuration is surfaced during options validation or plan resolution rather than producing partial provider setup.
void ConfigureOptionsBuilder(OptionsBuilder<AppSurfaceObservabilityOptions> builder, Action<AppSurfaceObservabilityOptions>? configure)
Applies optional code configuration to the shared options builder.
builder
configure
Code configuration composes after bound values so applications can set environment-specific defaults in configuration and still make last-mile adjustments in startup code.
void ConfigureTracing(TracerProviderBuilder tracing, AppSurfaceObservabilityPlan plan)
Adds AppSurface tracing sources and the optional OTLP trace exporter.
tracing
plan
This method always registers AppSurface's standard activity sources. It adds an OTLP exporter only when plan
requires AppSurface-owned export; otherwise hosts may add their own exporters.
void ConfigureTracing(TracerProviderBuilder tracing, AppSurfaceObservabilityPlan plan, Action<TracerProviderBuilder, AppSurfaceObservabilityPlan> addExporter)
Adds AppSurface tracing sources and delegates optional exporter registration.
tracing
plan
addExporter
The callback is an internal test seam. Production passes the OpenTelemetry OTLP exporter registration callback, and tests can assert that exporter registration was requested without depending on OpenTelemetry internals.
void ConfigureMetrics(MeterProviderBuilder metrics, AppSurfaceObservabilityPlan plan)
Adds AppSurface metric meters and the optional OTLP metric exporter.
metrics
plan
This method always registers AppSurface's standard meter names. It adds an OTLP exporter only when plan
requires AppSurface-owned export; otherwise hosts may add their own exporters.
void ConfigureMetrics(MeterProviderBuilder metrics, AppSurfaceObservabilityPlan plan, Action<MeterProviderBuilder, AppSurfaceObservabilityPlan> addExporter)
Adds AppSurface metric meters and delegates optional exporter registration.
metrics
plan
addExporter
The callback is an internal test seam. Production passes the OpenTelemetry OTLP exporter registration callback, and tests can assert that exporter registration was requested without depending on OpenTelemetry internals.
void ConfigureExporter(OtlpExporterOptions options, AppSurfaceObservabilityPlan plan)
Applies AppSurface endpoint configuration to an OTLP exporter.
options
plan
When no endpoint is present, this method intentionally leaves OpenTelemetry defaults untouched so hosts can rely on standard OTEL environment variables or SDK defaults in AppSurfaceOtlpExporterMode.Always
mode.
void ConfigureResource(ResourceBuilder resource, AppSurfaceObservabilityPlan plan)
Adds AppSurface service identity metadata to an OpenTelemetry resource builder.
resource
plan
AppSurface does not set a service instance id. Hosts that need per-instance identity should add it in their own OpenTelemetry resource configuration after AppSurface registration.
AppSurface host module that registers application-side OpenTelemetry logging, tracing, and metrics.
Add this module to an AppSurface application's dependency graph when the app should publish operational telemetry to Aspire or another OTLP collector. The module reads AppSurfaceObservabilityOptions
from configuration, uses StartupContext.ApplicationName
as the default service name, and skips exporter registration when AppSurfaceOtlpExporterMode.WhenEndpointConfigured
is active without an endpoint. It does not define Aspire resources, dashboards, product analytics, request-body capture, or package-specific AppSurface spans.
void ConfigureServices(StartupContext context, IServiceCollection services)
Registers options metadata for service consumers that inspect AppSurfaceObservabilityOptions
.
context
services
void ConfigureHostBeforeServices(StartupContext context, IHostBuilder builder)
Registers OpenTelemetry logging with access to host configuration.
context
builder
void ConfigureHostAfterServices(StartupContext context, IHostBuilder builder)
Registers OpenTelemetry tracing and metrics with access to host configuration.
context
builder
void RegisterDependentModules(ModuleDependencyBuilder builder)
Registers dependent modules; no dependencies are required.
builder
Provides compatible OpenTelemetry source and meter name surfaces for AppSurface-owned instrumentation.
This type keeps the existing v1 public shape for telemetry names while delegating the canonical AppSurface source name to AppSurfaceActivitySources
to avoid a hard dependency on this package from framework code.
The v1 observability package registers these names so future AppSurface packages can add spans and metrics without forcing each application to rediscover source names. This package does not add Flow, Auth, Docs, Intelligence, or other package-specific telemetry yet.
IReadOnlyList<string> StandardActivitySourceNames { get; }
Source
Gets common .NET activity source names that AppSurface opts into when they are emitted by the host runtime.
The returned list is read-only so callers cannot mutate global source registration for the current process. Copy the values into a new collection before adding application-specific sources.
IReadOnlyList<string> StandardMeterNames { get; }
Source
Gets common .NET meter names that AppSurface opts into when they are emitted by the host runtime.
The returned list is read-only so callers cannot mutate global meter registration for the current process. Copy the values into a new collection before adding application-specific meters.
Provides logging-builder extensions for AppSurface observability.
ILoggingBuilder AddAppSurfaceObservabilityLogging(this ILoggingBuilder builder, StartupContext context, IConfiguration configuration, Action<AppSurfaceObservabilityOptions>? configure = null)
Adds AppSurface OpenTelemetry logging.
builder
context
configuration
AppSurfaceObservabilityOptions
.configure
The supplied builder
.
Repeated calls are safe and first registration wins, which keeps configured options aligned with the captured OpenTelemetry logger setup.
ILoggingBuilder AddAppSurfaceObservabilityLogging(this ILoggingBuilder builder, StartupContext context, IConfiguration configuration, Action<AppSurfaceObservabilityOptions>? configure, bool registerOptions)
Adds AppSurface OpenTelemetry logging with explicit control over options registration.
builder
context
configuration
configure
registerOptions
true
to bind and validate options in DI; false
when another AppSurface registration path has already registered the same options.
The supplied builder
.
This overload is used by the host module so logging can be configured before service-provider OpenTelemetry. Registration is idempotent and first registration wins. The resolved plan is captured by the logging options callback, so callers should supply their intended endpoint and service identity on the first call.
void ConfigureLogging(OpenTelemetryLoggerOptions options, AppSurfaceObservabilityPlan plan)
Applies AppSurface OpenTelemetry logging defaults to logger options.
options
plan
AppSurface opts into formatted messages, scopes, and parsed state values so structured log attributes remain useful when exported through OTLP. Exporter registration follows plan
: when the plan skips export, the host can still add its own logging exporter later.
Captures the immutable observability registration plan resolved from AppSurface configuration.
ExporterMode
Endpoint
null
when the host should use OpenTelemetry defaults or skip export.ServiceName
ServiceVersion
ShouldRegisterExporter
ShouldLogSkippedExporterDiagnostic
The plan is resolved once per first registration path. Later option registrations do not rewrite providers because OpenTelemetry captures resource and exporter setup when providers are built.
AppSurfaceObservabilityPlan Resolve(StartupContext context, IConfiguration configuration, Action<AppSurfaceObservabilityOptions>? configure = null, IAppSurfaceEnvironmentReader? environment = null)
Resolves the effective OpenTelemetry registration plan.
context
configuration
configure
environment
The resolved immutable plan used by logging, tracing, metrics, and resource registration.
ArgumentNullException
context
or configuration
is null
. InvalidOperationException
AppSurfaceObservabilityOptions.ExporterMode
is undefined or an endpoint value is not an absolute URI.
Endpoint precedence is AppSurface options first, then the raw AppSurfaceObservabilityOptions.AppSurfaceOtlpEndpointEnvironmentVariable
environment variable for hosts that did not add environment variables to configuration, then the standard AppSurfaceObservabilityOptions.OtlpEndpointEnvironmentVariable
value from configuration, then the same standard variable from the process environment. This keeps AppSurface-owned endpoint configuration more specific than generic OTEL defaults while still honoring collector settings supplied by Aspire.
Uri? ResolveUri(string? value, string settingName = AppSurfaceObservabilityOptions.OtlpEndpointEnvironmentVariable)
Resolves an optional absolute URI from configuration or environment input.
value
settingName
The parsed absolute URI, or null
when value
is blank.
InvalidOperationException
value
is present but is not an absolute URI. Blank values are treated as absent so an empty environment variable does not accidentally enable export. Relative URI values fail closed because OTLP exporters need a concrete collector endpoint.
Controls when AppSurface configures OpenTelemetry Protocol exporters.
The default, WhenEndpointConfigured
, is designed for Aspire and other collector-backed development environments: export is enabled only when an OTLP endpoint is present in AppSurface configuration or the standard OTEL_EXPORTER_OTLP_ENDPOINT
environment variable. Use Always
only when the host intentionally wants OpenTelemetry's exporter defaults or host-owned OTLP configuration to apply. Use Never
for tests and hosts that install their own exporters.