Skip to content

Fix doubled log prefixes and isolate the telemetry opt-in setting - #191

Merged
satyakigh merged 3 commits into
mainfrom
logs
Oct 2, 2026
Merged

satyakigh merged 3 commits into
mainfrom
logs

Conversation

@satyakigh

@satyakigh satyakigh commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Every line in the AWS CloudFormation output channel carried two timestamps and two levels, for example 2026-10-02 13:25:35.011 [info] [01:25:34 PM] Info: [Extension] Activating v1.0.0. Since #187 the channel is a LogOutputChannel, which stamps the time and level on each entry itself, but Logger still prepended its own [time] Level: [Component] prefix and wrote through appendLine. A LogOutputChannel records appendLine output at info level, so every warning and error was tagged [info] and the Output view's level filter and coloring were wrong for them. Two further bugs sat in the same method: line += `${line} ${message}` repeated the whole prefix whenever a message accompanied the data, which is the shape of every log.warn(err, '...') and log.error(err, '...') call, and toString(error) rendered an Error as {} because the pretty-printer only sees enumerable properties, so error logs lost the error itself.

The telemetry opt-in was stored in aws.cloudformation.telemetry.enabled. Other IDE clients of the language server contribute a setting with that exact id, so a choice recorded by one extension switched telemetry on or off for the other, and whichever wrote last won.

Solution

Logger takes a LogOutputChannel and writes through its debug, info, warn and error methods, adding only the [Component] prefix. The hand-rolled time and level formatting is gone, the message is appended once, and an Error prints its stack, falling back to extractErrorMessage. The aws.cloudformation.telemetry.logLevel gate is unchanged. tst/utils/Logger.test.ts covers the level routing, the single prefix, the error rendering and the configured level; the vscode mock gains the LogOutputChannel methods and the existing test call sites create their channel with { log: true } so they type-check against it.

The opt-in setting moves to aws.iac.telemetry.enabled, a namespace this extension already owns (aws-iac-vscode, iac-vscode). TelemetryOptIn.ts reads and writes the new key, the prompt names the setting it writes, the package.json contribution replaces the stale description, and the README settings table and Telemetry section follow. The globalState keys are unchanged because VS Code scopes them per extension, so they never collided. tst/telemetry/TelemetryOptIn.test.ts pins the key: a recorded choice is read from aws.iac.telemetry.enabled, a value under aws.cloudformation.telemetry.enabled is ignored, and a prompt answer is persisted only under the new key.

The README also drops the Downloads badge.

Behavior changes

Output lines read 2026-10-02 13:25:35.011 [info] [Extension] Activating v1.0.0, and warnings and errors carry their real level, so the Output view's level filter and coloring apply to them. Errors logged with data print their stack instead of {}. Debug lines go through LogOutputChannel.debug, which VS Code shows only when the channel's log level is set to Debug or Trace (Output view, "Set Log Level..."); with the default Info level, setting aws.cloudformation.telemetry.logLevel to debug alone no longer surfaces them.

A user who enabled telemetry on 1.0.0 is not prompted again: the hasResponded flag persists in globalState and the new setting reads as its default, so telemetry stays off until aws.iac.telemetry.enabled is turned on. A value left under aws.cloudformation.telemetry.enabled is no longer read by this extension.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

The output channel is a LogOutputChannel, which already stamps the time
and level on every line, yet the logger prepended its own and wrote
through appendLine, so every line carried two timestamps and two levels
and warnings and errors were recorded as info. A concatenation bug also
repeated the whole prefix whenever a message accompanied the data. The
logger now writes through the channel's own debug/info/warn/error with
only the component name, and errors print their stack instead of "{}".

Other IDE clients of the language server contribute the identical
aws.cloudformation.telemetry.enabled setting, so a choice recorded by one
extension switched telemetry on or off for the other. The opt-in setting
now lives in this extension's own namespace as aws.iac.telemetry.enabled.
The globalState keys are unchanged: VS Code scopes them per extension.
Users who answered the 1.0.0 prompt are asked once more, since their
choice is stored under the old key.
@satyakigh
satyakigh requested a review from a team as a code owner October 2, 2026 17:46
@satyakigh satyakigh changed the title Logs Fix doubled log prefixes and isolate the telemetry opt-in setting Oct 2, 2026
@github-code-quality

Copy link
Copy Markdown

Code Coverage Overview

Languages: TypeScript

TypeScript / code-coverage/vitest

The overall line coverage in commit ababb94 in the logs branch is 78%. The line coverage in commit c3f0e9e in the main branch is 73%.

Show a line coverage summary of the most impacted files.
File main c3f0e9e logs ababb94 +/-
src/utils/Utils.ts 50% 75% +25%
src/utils/Logger.ts 68% 96% +28%
src/telemetry/T...lemetryOptIn.ts 0% 60% +60%

@satyakigh
satyakigh merged commit dfc611c into main Oct 2, 2026
8 checks passed
@satyakigh
satyakigh deleted the logs branch October 2, 2026 17:57
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.

1 participant