|
17 | 17 | using Microsoft.HttpRepl.Preferences; |
18 | 18 | using Microsoft.HttpRepl.Resources; |
19 | 19 | using Microsoft.HttpRepl.Suggestions; |
| 20 | +using Microsoft.HttpRepl.Telemetry; |
| 21 | +using Microsoft.HttpRepl.Telemetry.Events; |
20 | 22 | using Microsoft.Repl; |
21 | 23 | using Microsoft.Repl.Commanding; |
22 | 24 | using Microsoft.Repl.ConsoleHandling; |
@@ -49,17 +51,19 @@ public abstract class BaseHttpCommand : CommandWithStructuredInputBase<HttpState |
49 | 51 |
|
50 | 52 | private readonly IFileSystem _fileSystem; |
51 | 53 | private readonly IPreferences _preferences; |
| 54 | + private readonly ITelemetry _telemetry; |
52 | 55 |
|
53 | 56 | public override string Name => Verb; |
54 | 57 |
|
55 | 58 | protected abstract string Verb { get; } |
56 | 59 |
|
57 | 60 | protected abstract bool RequiresBody { get; } |
58 | 61 |
|
59 | | - protected BaseHttpCommand(IFileSystem fileSystem, IPreferences preferences) |
| 62 | + protected BaseHttpCommand(IFileSystem fileSystem, IPreferences preferences, ITelemetry telemetry) |
60 | 63 | { |
61 | 64 | _fileSystem = fileSystem; |
62 | 65 | _preferences = preferences; |
| 66 | + _telemetry = telemetry; |
63 | 67 | } |
64 | 68 |
|
65 | 69 | public override CommandInputSpecification InputSpec |
@@ -101,10 +105,12 @@ protected override async Task ExecuteAsync(IShellState shellState, HttpState pro |
101 | 105 |
|
102 | 106 | if (programState.BaseAddress == null && (commandInput.Arguments.Count == 0 || !Uri.TryCreate(commandInput.Arguments[0].Text, UriKind.Absolute, out _))) |
103 | 107 | { |
104 | | - shellState.ConsoleManager.Error.WriteLine(Resources.Strings.Error_NoBasePath.SetColor(programState.ErrorColor)); |
| 108 | + shellState.ConsoleManager.Error.WriteLine(Strings.Error_NoBasePath.SetColor(programState.ErrorColor)); |
105 | 109 | return; |
106 | 110 | } |
107 | 111 |
|
| 112 | + SendTelemetry(commandInput); |
| 113 | + |
108 | 114 | if (programState.SwaggerEndpoint != null) |
109 | 115 | { |
110 | 116 | await CreateDirectoryStructureForSwaggerEndpointAsync(shellState, programState, cancellationToken).ConfigureAwait(false); |
@@ -750,5 +756,23 @@ private static string GetExampleBody(string path, ref string contentType, string |
750 | 756 | IDirectoryStructure structure = httpState.Structure?.TraverseTo(rootRelativePath); |
751 | 757 | return structure?.RequestInfo?.GetRequestBodyForContentType(ref contentType, method); |
752 | 758 | } |
| 759 | + |
| 760 | + private void SendTelemetry(DefaultCommandInput<ICoreParseResult> commandInput) |
| 761 | + { |
| 762 | + HttpCommandEvent httpCommandEvent = new HttpCommandEvent( |
| 763 | + method: Verb.ToUpperInvariant(), |
| 764 | + isPathSpecified: commandInput.Arguments.Count > 0, |
| 765 | + isHeaderSpecified: commandInput.Options[HeaderOption].Any(), |
| 766 | + isResponseHeadersFileSpecified: commandInput.Options[ResponseHeadersFileOption].Any(), |
| 767 | + isResponseBodyFileSpecified: commandInput.Options[ResponseBodyFileOption].Any(), |
| 768 | + isNoFormattingSpecified: commandInput.Options[NoFormattingOption].Any(), |
| 769 | + isStreamingSpecified: commandInput.Options[StreamingOption].Any(), |
| 770 | + isNoBodySpecified: RequiresBody && commandInput.Options[NoBodyOption].Any(), |
| 771 | + isRequestBodyFileSpecified: RequiresBody && commandInput.Options[BodyFileOption].Any(), |
| 772 | + isRequestBodyContentSpecified: RequiresBody && commandInput.Options[BodyContentOption].Any() |
| 773 | + ); |
| 774 | + |
| 775 | + _telemetry.TrackEvent(httpCommandEvent); |
| 776 | + } |
753 | 777 | } |
754 | 778 | } |
0 commit comments