Skip to content

Commit

Permalink
Merge pull request #516 from maester365/telemetry
Browse files Browse the repository at this point in the history
Added v1 of telemetry with option to skip when invoking
  • Loading branch information
merill authored Nov 5, 2024
2 parents 321c049 + 876f287 commit cb15c2c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
36 changes: 36 additions & 0 deletions powershell/internal/Write-Telemetry.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
function Write-Telemetry {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[ValidateSet("InvokeMaester")]
[string]
$EventName
)
Write-Verbose "Sending telemetry event: $EventName"

$tenantId = Get-MgContext | Select-Object -ExpandProperty TenantId
if (-not $tenantId) {
$tenantId = "unknown"
}
# Define the JSON data
$jsonData = @{
api_key = "phc_VxA235FsdurMGycf9DHjlUeZeIhLuC7r11Ptum0WjRK"
distinct_id = $tenantId
event = $EventName
}

# Convert the data to JSON format
$jsonBody = $jsonData | ConvertTo-Json

# Define the URL
$url = "https://us.i.posthog.com/capture/"

# Send the POST request
try {
Invoke-RestMethod -Uri $url -Method Post -ContentType "application/json" -Body $jsonBody
}
catch {
Write-Verbose $_
}

}
11 changes: 10 additions & 1 deletion powershell/public/Invoke-Maester.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,12 @@ function Invoke-Maester {

# Skip the graph connection check.
# This is used for running tests that does not require a graph connection.
[switch] $SkipGraphConnect
[switch] $SkipGraphConnect,

# Disable Telemetry
# If set, telemetry information will not be logged.
[switch] $DisableTelemetry

)

function GetDefaultFileName() {
Expand Down Expand Up @@ -233,6 +238,10 @@ function Invoke-Maester {

Clear-ModuleVariable # Reset the graph cache and urls to avoid stale data

if (-not $DisableTelemetry) {
Write-Telemetry -EventName InvokeMaester
}

$isMail = $null -ne $MailRecipient

$isTeamsChannelMessage = -not ([String]::IsNullOrEmpty($TeamId) -or [String]::IsNullOrEmpty($TeamChannelId))
Expand Down

0 comments on commit cb15c2c

Please sign in to comment.