Module: BetterAuth::Telemetry::Env

Defined in:
lib/better_auth/telemetry/env.rb

Overview

Telemetry-side wrapper around Env that exposes the two helpers the rest of the telemetry pipeline depends on:

  • Env.get — read a ‘BETTER_AUTH_*` environment variable while transparently honoring the `OPEN_AUTH_*` alias prefix.

  • Env.truthy? — classify a resolved env string as truthy using the same rules upstream applies in ‘packages/core/src/env/env-impl.ts:getBooleanEnvVar`.

The wrapper is intentionally thin: Env.get already implements the dual-prefix resolution, so Env.get just delegates. Wrapping it here gives the telemetry package a single, named seam the orchestrator code can reach for and the tests can drive against, without leaking the core env module into every detector.

## Truthy semantics

An environment value is considered a ‘Truthy_Env_Value` (Requirement 3.6) when **all three** of these conditions hold for the resolved string:

  1. it is not empty,

  2. it is not the literal ‘“0”`, and

  3. ‘value.casecmp(“false”) != 0` (i.e. not `“false”` / `“FALSE”` / `“False”` / etc).

Anything else — including ‘nil`, `“”`, `“0”`, and any casing of `“false”` — is falsy. This mirrors the upstream behavior so the Ruby port classifies opt-in toggles identically to the Node port.

The classifier accepts any input type: non-string values are coerced via ‘#to_s` before classification. That makes it safe to forward boolean defaults straight from option hashes (`Env.truthy?(options[:debug])`) without callers having to type-check first.

Class Method Summary collapse

Class Method Details

.get(name) ⇒ String?

Resolve the value of a telemetry environment variable.

Accepts the canonical ‘BETTER_AUTH_*` name and delegates to Env.get, which checks the `OPEN_AUTH_*` alias first and falls back to the canonical name. Returns `nil` when neither variant is set (or both are empty).

Parameters:

  • name (String, Symbol)

    canonical ‘BETTER_AUTH_*` environment variable name (e.g. `“BETTER_AUTH_TELEMETRY”`).

Returns:

  • (String, nil)

    the resolved value, or ‘nil` when absent.



55
56
57
# File 'lib/better_auth/telemetry/env.rb', line 55

def get(name)
  ::BetterAuth::Env.get(name)
end

.truthy?(value) ⇒ Boolean

Classify an environment value as truthy.

Parameters:

  • value (Object, nil)

    typically a ‘String` returned from get, but any value is accepted; non-strings are coerced via `#to_s`. `nil` coerces to `“”` and is falsy.

Returns:

  • (Boolean)

    ‘true` when the resolved string is non-empty, not `“0”`, and not (case-insensitively) `“false”`. `false` otherwise.



67
68
69
70
71
72
73
74
# File 'lib/better_auth/telemetry/env.rb', line 67

def truthy?(value)
  string = value.to_s
  return false if string.empty?
  return false if string == "0"
  return false if string.casecmp("false") == 0

  true
end