How is your experience with the OutSystems Community?
RuntimeContext

RuntimeContext (ODC)

Stable version 1.2.0 (Compatible with ODC)
Uploaded on 22 Sep by Ricardo Monteiro
RuntimeContext

RuntimeContext (ODC)

Documentation
1.2.0

Overview

Runtime Context is a lightweight ODC External Logic library that lets any app discover which stage it is running on — and whether it is Production — at runtime, with zero configuration.

No per-stage settings. No app config files. Call an action and get the answer.

The Problem It Solves

ODC has no built-in, runtime-readable way to know the current stage. The typical workaround is a per-stage app setting that must be manually configured on every stage. This works but adds operational overhead and is easy to misconfigure.

Runtime Context reads the stage tier directly from the platform-injected execution environment, so it works on every stage with no setup required from the deploying team.

Requirements

  • .NET 10. No third-party dependencies beyond the ODC External Libraries SDK.
  • Secure Gateway configured on the stage. Classification reads a signal that only exists when Secure Gateway is enabled. On a stage without it — a personal or trial tenant, typically — classification returns Unknown and IsProductionStage() returns False. Every non-classification action still returns real values. Run ExplainClassification to confirm which case you are in.

Read This First

IsProductionStage() is directional. It returns False both when the stage is confirmed non-production and when the stage could not be determined at all.

  • Safe: If IsProductionStage() Then
  • Unsafe: If Not IsProductionStage() Then

The unsafe pattern routes real production traffic into test behavior on any stage where the platform signal is missing. When the distinction matters, read GetCurrentStage() and branch on IsClassified, which is True only when the stage was positively identified.

Features

  • Detect whether the current stage is Production, NonProduction, Development, or Unknown
  • Read the stage identifier and runtime URL without any per-stage configuration
  • Inspect server runtime details: .NET version, OS, CPU, memory, and cloud region
  • Correlate ODC logs with AWS infrastructure traces via X-Ray and CloudWatch identifiers
  • Diagnose an unexpected classification by reading the raw platform signals directly
  • Zero input parameters on every action — call and use the result directly
  • Fails closed: the library never reports Production unless the stage is positively identified as Production, so there are no false positives. Anything it cannot identify is reported as Unknown — which is not a claim that the stage is non-production, and must not be read as one

Actions

All actions take no input parameters. They can be called directly in any server-side logic flow.

GetCurrentStage

Returns the full classification and context of the stage the app is running on.

Output: Stage (StageDetails) — classification, production flag, IsClassified flag, identifier, URL, subdomain, and infrastructure realm.

IsProductionStage

Quick boolean check. Use this to guard logic that should only run on Production. See Read This First above before using it.

Output: IsProduction (Boolean) — True only when the app is positively identified as running on a Production stage.

ExplainClassification

Returns the raw platform signals and the rule that produced the classification. Reach for this first when stage detection returns something unexpected — it tells you whether the signal was absent, or present but carrying a realm token this version does not recognize.

Output: Diagnostics (StageDiagnostics) — raw signals, extracted realm, recognized flag, reason, resolved host, and the realms this version knows.

GetTraceContext

Returns the underlying AWS trace and log context, for correlating ODC logs with infrastructure traces in Datadog, New Relic or the AWS console. The trace identifier changes on every invocation, so read it at the moment you log rather than caching it.

Output: Trace (TraceContext) — X-Ray trace identifier, CloudWatch log group, and log stream.

GetRuntimeLifecycle

Returns facts about the lifetime of the runtime process serving this library, for reasoning about warm reuse of the underlying serverless worker. This describes the External Logic runtime, which is a separate serverless function from your app — it is not your app's cold start.

Output: Lifecycle (RuntimeLifecycle) — process uptime and whether this is the first call within the process.

GetStageId

Returns the unique identifier of the current stage.

Output: StageId (Text) — unique identifier (GUID) of the current stage.

GetRuntimeUrl

Returns the URL the current stage is served from.

Output: RuntimeUrl (Text) — URL the current stage is served from.

GetRuntimeDetails

Returns technical details about the server runtime that executes the external logic.

Output: Runtime (RuntimeDetails) — .NET version, OS, CPU count, cloud region, and serverless function name and memory.

Classification Values

StageDetails.Classification is one of Production, NonProduction, Development or Unknown.

Unknown means the stage was not identified — either the signal was absent, or it carried a realm token this version does not recognize, so a future ODC tier is never reported as a stage the library claims to understand. Read IsClassified rather than inferring anything from Unknown: it is False in exactly those cases.

StageRealmClassificationIsProduction
DevelopmentrundevDevelopmentFalse
TestingrunnpNonProductionFalse
Pre-ProductionrunnpNonProductionFalse
ProductionrunpProductionTrue

Notes and Best Practices

  • Production gating. Use IsProductionStage to guard logic that should only run on Production. Because classification fails closed, it will never grant production-only behavior incorrectly. Do not invert it to enable test behavior — see Read This First.
  • Testing and Pre-Production are indistinguishable. Both report NonProduction, because they share one infrastructure realm. If you need to tell them apart, branch on StageId or use a per-stage app setting.
  • High-stakes operations. For irreversible, production-only operations such as sending transactional communications or triggering billing flows, combine this library with a per-stage app setting as a second gate. Runtime Context is reliable, but it reads an internal platform signal that is not part of a public ODC contract and may change on a platform update.
  • Not a security boundary. Use it for logging, banners, diagnostics and feature flags — never as the sole control for anything security- or money-critical.
  • Do not cache the trace identifier. It is rewritten on every invocation; holding it would pin every correlation to the first request the worker served.
  • RuntimeDetails.MachineName is not meaningful on ODC. The runtime's hostname is an IP-derived label and .NET truncates a hostname at its first period, so the field returns a fragment such as 169 on every stage. Use LambdaFunctionName or AwsRegion to identify the runtime.