Skip to content

observability: Init does not default MetricsMode; unset mode is a hard error #192

@Lutherwaves

Description

@Lutherwaves

Background

While fact-checking the docs in #189 against the source, we found the design-internals doc described behavior the code does not implement. The doc has been corrected to match the code (in #189), but the underlying API ergonomics question is worth a decision.

Current behavior (verified against source)

  • observability.Init (observability/observability.go:102) calls only cfg.validate().
  • Config.validate() (observability/config.go:151) does not mutate the config — its own comment says callers "should compose with DefaultConfig".
  • DefaultConfig() (observability/config.go:134) sets only EnableRuntimeMetrics=true, EnableProcessMetrics=true, MetricsPushInterval=30s. It does not set MetricsMode.
  • A zero/empty MetricsMode is therefore rejected: validate() returns invalid MetricsMode (config.go:158), and Init's switch has a default error case (observability.go:150).

There is no applyDefaults function and no defaults.go file — the old doc invented both.

Why it's a papercut

DefaultConfig() reads as "supply ServiceName and MetricsMode and you're good." But:

cfg := observability.DefaultConfig()
cfg.ServiceName = "tasks-svc"
// forgets MetricsMode
obs, err := observability.Init(ctx, cfg) // -> error: invalid MetricsMode ""

fails at runtime for what looks like a reasonable default path. Prometheus is the obvious default mode.

Decision needed

Option A — make code match the (old) doc intent: have DefaultConfig() set MetricsMode = MetricsModePrometheus (and/or have Init default a zero value). Friendlier; one fewer required field.

Option B — keep MetricsMode required: current behavior; explicit over implicit. Docs already corrected to state this.

If A: implement in DefaultConfig() (no mutation in Init), add a test, re-document MetricsMode as defaulted. If B: no code change — close this issue; the #189 doc fix already reflects it.

Refs: #189 (doc correction).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestquestionFurther information is requested

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions