Azure / Azure/azure-dev

feat: support extension-defined hook names in telemetry logging

Open
#7,348 2 comments 0 reactions 1 assignee Claimed by @JeffreyCA View on GitHub
area/telemetry enhancement
Dominant language
Go
Stars
569
Forks
364
Avg merge
2d 19h
Merged PRs (30d)
136

Description

## Problem

When logging hook names in telemetry (hooks.name attribute), we currently validate against a static list of 16 known built-in azd hook names (prebuild, postbuild, predeploy, etc.). Unknown hook names are SHA-256 hashed to prevent logging arbitrary user input as customer content.

However, **extensions can define custom hook names** via:
- `azure.yaml` project/service hook configurations
- Runtime event handlers registered through `azdext.ExtensionHost.WithProjectEventHandler()` / `WithServiceEventHandler()`

These extension-defined hooks are legitimate hook names that would be useful to see in telemetry in plain text, but they currently get hashed because they're not in the built-in known-names list.

## Current Behavior

- Built-in hook names (`prebuild`, `postdeploy`, etc.) → logged raw ✅
- Extension-defined hook names from `azure.yaml` → **hashed** (not ideal)
- Arbitrary user input (`azd hooks run asdf`) → **hashed** ✅

## Desired Behavior

Extension-defined hook names should also be logged in plain text when they can be validated as legitimate (i.e., defined in project config or registered by an extension).

## Options to Investigate

1. **Validate against project config at telemetry time** — Check `projectConfig.Hooks` and all `service.Hooks` maps. If the hook name exists there, log raw; otherwise hash. This covers extension hooks defined in `azure.yaml` but not runtime-only handlers.

2. **Extension hook name registry** — Provide an API for extensions to register their custom hook names, making them available for telemetry validation.

3. **Accept hashing for extension hooks** — If extension hook telemetry isn't critical, the current approach (hash unknown names) may be acceptable.

## Context

- PR: https://github.com/Azure/azure-dev/pull/7299
- Review comment: https://github.com/Azure/azure-dev/pull/7299/files#r2996272790
- Current implementation: `cli/azd/cmd/hooks.go` — `knownHookNames` map + `StringHashed` fallback

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.