-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update environments telemetry to add hresults (#3804)
* update telemetry to add hresults * update based on comments * Fix whitespace --------- Co-authored-by: Kristen Schau <47155823+krschau@users.noreply.github.com>
- Loading branch information
Showing
12 changed files
with
244 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,4 @@ GetWindowRect | |
GetMonitorInfo | ||
SetWindowPos | ||
MonitorFromWindow | ||
E_INVALIDARG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using Microsoft.Windows.DevHome.SDK; | ||
using Windows.Win32.Foundation; | ||
|
||
namespace DevHome.Common.TelemetryEvents; | ||
|
||
public class TelemetryResult | ||
{ | ||
private const int SuccessHResult = 0; | ||
|
||
public int HResult { get; private set; } | ||
|
||
public ProviderOperationStatus Status { get; private set; } | ||
|
||
public string? DisplayMessage { get; private set; } | ||
|
||
public string? DiagnosticText { get; private set; } | ||
|
||
public TelemetryResult(ProviderOperationResult? result) | ||
{ | ||
UpdateProperties(result); | ||
} | ||
|
||
public TelemetryResult(int hResult, string displayMessage, string diagnosticText) | ||
{ | ||
HResult = hResult; | ||
Status = ProviderOperationStatus.Failure; | ||
DisplayMessage = displayMessage; | ||
DiagnosticText = diagnosticText; | ||
} | ||
|
||
public TelemetryResult() | ||
{ | ||
HResult = SuccessHResult; | ||
Status = ProviderOperationStatus.Success; | ||
} | ||
|
||
private void UpdateProperties(ProviderOperationResult? result) | ||
{ | ||
if (result == null) | ||
{ | ||
// The extension provided us with a null ProviderOperationResult, | ||
// so the telemetry should state this explicitly. | ||
Status = ProviderOperationStatus.Failure; | ||
HResult = HRESULT.E_INVALIDARG; | ||
DiagnosticText = "ProviderOperationResult was null"; | ||
DisplayMessage = "ProviderOperationResult was null"; | ||
return; | ||
} | ||
|
||
Status = result.Status; | ||
DiagnosticText = result.DiagnosticText; | ||
DisplayMessage = result.DisplayMessage; | ||
HResult = SuccessHResult; | ||
|
||
if (Status == ProviderOperationStatus.Failure) | ||
{ | ||
HResult = result.ExtendedError.HResult; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# TelemetryResult | ||
Used to extract data from a `ProviderOperationResult` object returned by an SDK method or wrapper class. This can also be used as a general class to store error information that can be sent in a telemetry payload. | ||
|
||
## Properties | ||
| Property | Type | Description | | ||
| -------- | -------- | -------- | | ||
| HResult | Integer | HRESULT code returned by an operation to Dev Home or an extension. | ||
| Status | ProviderOperationStatus | Enum used to dictate whether an operation succeeded or failed. | | ||
| DisplayMessage | String? | Optional display message returned to the user from an interaction with Dev Home. This may be localized. | | ||
| DiagnosticText | String? | Optional diagnostic text return by an operation. This can be used to gain insights into errors that occur in an extension, after an operation is initiated by Dev Home. | | ||
|
||
## Usage | ||
#### ComputeSystemViewModel.cs | ||
```C# | ||
// Using the parameterless constructor. This is optional. Most events in Dev Home only care about the result of the operation and not that the operation started. | ||
var startLaunchEvent = new EnvironmentLaunchEvent( | ||
ComputeSystemProviderId, | ||
EnvironmentsTelemetryStatus.Started, | ||
new TelemetryResult()); | ||
|
||
// Send the telemetry stating that the operation has started. | ||
TelemetryFactory.Get<ITelemetry>().Log( | ||
"Environment_Launch_Event", | ||
LogLevel.Critical, | ||
startLaunchEvent); | ||
|
||
// It's good practise to wrap the out of proc COM object in a wrapper class and return the associated SDK result. Exceptions caught by the wrapper can then be used to return an SDK result that indicates that the operation failed. | ||
var launchResponse = await ComputeSystemWrapper.ConnectAsync(string.Empty); | ||
|
||
// ... Handle any post operation logic.. | ||
// Use the TelemetryResult to extract data from the ProviderOperationResult, so it can be used in an Event payload. | ||
var endLaunchEvent = new EnvironmentLaunchEvent( | ||
ComputeSystemProviderId, | ||
telemetryStatusBasedOnResponse, | ||
new TelemetryResult(launchResponse?.Result)); | ||
|
||
// Operation is completed and the payload for ending the event can be sent. | ||
TelemetryFactory.Get<ITelemetry>().Log( | ||
"Environment_Launch_Event", | ||
LogLevel.Critical, | ||
endLaunchEvent); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.