Skip to content

Fix OTEL metric names and parameter types#452

Merged
satyakigh merged 1 commit intomainfrom
param-fix
Feb 26, 2026
Merged

Fix OTEL metric names and parameter types#452
satyakigh merged 1 commit intomainfrom
param-fix

Conversation

@satyakigh
Copy link
Collaborator

@satyakigh satyakigh commented Feb 24, 2026

What changed

  1. OTEL metric name sanitization (ScopedTelemetry.ts) — Added a sanitizeMetricName() function that lowercases metric names and replaces invalid characters with underscores
    to comply with the OpenTelemetry naming spec (/^[a-z][a-z0-9_.-/]{0,254}$/i). This sanitization is now applied in all four metric creation paths: counters, up-down
    counters, histograms, and observable gauges.

  2. Parameter type coercion hardening (ParameterType.ts) — Two fixes:

    • isNumericType() was using .includes('Number') which could false-positive on types like AWS::SSM::Parameter::Value<List>. Now it strictly checks
      === ParameterType.Number.
    • coerceParameterToTypedValues() now validates the types of Default and AllowedValues before using them (guards against unexpected types sneaking through), and fixes the
      boolean detection logic so AllowedValues takes precedence over Default when both are present.
  3. Constructor visibility (ScopedTelemetry.ts / TelemetryService.ts) — Made the ScopedTelemetry constructor private so only TelemetryService (the intended owner) can
    instantiate it. TelemetryService and tests use @ts-expect-error to bypass this.

Why / What it fixes

  • Metric names with characters outside the OTEL spec (e.g., spaces, special chars) would silently create invalid metrics or get rejected by OTEL exporters. The sanitizer
    prevents that.
  • The loose isNumericType check and unguarded type coercion could misclassify parameter types, leading to incorrect completions or validation behavior for CloudFormation
    template parameters.
  • Making the constructor private enforces the design intent that ScopedTelemetry instances should only be created through TelemetryService.

@satyakigh satyakigh requested a review from a team as a code owner February 24, 2026 20:45
@satyakigh satyakigh merged commit 68a7a48 into main Feb 26, 2026
16 checks passed
@satyakigh satyakigh deleted the param-fix branch February 26, 2026 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants