BCPFR4 - Telemetry Enablement
ID: BCPFR4 - Category: Composition - Telemetry Enablement
To comply with specifications outlined in SFR3 & SFR4 you MUST incorporate the following code snippet into your modules. Place this code sample in the “top level” main.bicep file; it is not necessary to include it in any nested Bicep files (child modules), unless they are marked for direct publishing (Ref Child module publishing).
Before compiling, ensure the module’s metadata.json exists alongside its main.bicep and contains its assigned telemetryIdPrefix. The example uses the jsonPath argument of loadJsonContent to load only that value. Do not load the full metadata object: that embeds unrelated values, including owners and descriptions, in the compiled ARM template. If an assigned prefix is missing or conflicts with the module index, follow the module metadata guidance rather than hardcoding or inventing one.
The current Bicep telemetryIdPrefix MUST use 46d3xbcp.<res|ptn|utl>.<seven lowercase hexadecimal characters> (20 characters). When replacing a previously assigned identifier, retain it and any earlier prefixes in alternativeTelemetryIdPrefixes in the same metadata.json; the deployment uses only the current prefix. Check that the complete deployment name fits within 64 characters without truncation.
After changing telemetryIdPrefix, regenerate main.json with Set-AVMModule.ps1 without -SkipBuild. Consumers deploying the compiled main.json do not need metadata.json.
@description('Optional. Location for all resources.')
param location string = resourceGroup().location
@description('Optional. Enable/Disable usage telemetry for module.')
param enableTelemetry bool = true
var telemetryIdPrefix = loadJsonContent('metadata.json', 'telemetryIdPrefix')
#disable-next-line no-deployments-resources
resource avmTelemetry 'Microsoft.Resources/deployments@2025-04-01' = if (enableTelemetry) {
name: '${telemetryIdPrefix}.${replace('-..--..-', '.', '-')}.${substring(uniqueString(deployment().name, location), 0, 4)}'
properties: {
mode: 'Incremental'
template: {
'$schema': 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#'
contentVersion: '1.0.0.0'
resources: []
outputs: {
telemetry: {
type: 'String'
value: 'For more information, see https://aka.ms/avm/TelemetryInfo'
}
}
}
}
}