diff --git a/TELEMETRY.md b/TELEMETRY.md index 3d47a3a4a..20750d98e 100644 --- a/TELEMETRY.md +++ b/TELEMETRY.md @@ -40,6 +40,7 @@ The telemetry feature collects the following data: | >=5.0 | For the `pref` command, whether a `get` or `set` was issued and which preference was accessed. If not a well-known preference, the name is hashed. The value is not collected. | | >=5.0 | For the `set header` command, the header name being set. If not a well-known header, the name is hashed. The value is not collected. | | >=5.0 | For the `connect` command, whether or not a specific special-case for `dotnet new webapi` was used and, whether or not it was bypassed via preference. | +| >=5.0 | For all HTTP commands (e.g. GET, POST, PUT, etc), whether or not each of the options was specified. The values of the options are not collected. | ## See also diff --git a/src/Microsoft.HttpRepl/Commands/BaseHttpCommand.cs b/src/Microsoft.HttpRepl/Commands/BaseHttpCommand.cs index 3912c233d..51cb85a5f 100644 --- a/src/Microsoft.HttpRepl/Commands/BaseHttpCommand.cs +++ b/src/Microsoft.HttpRepl/Commands/BaseHttpCommand.cs @@ -17,6 +17,8 @@ using Microsoft.HttpRepl.Preferences; using Microsoft.HttpRepl.Resources; using Microsoft.HttpRepl.Suggestions; +using Microsoft.HttpRepl.Telemetry; +using Microsoft.HttpRepl.Telemetry.Events; using Microsoft.Repl; using Microsoft.Repl.Commanding; using Microsoft.Repl.ConsoleHandling; @@ -49,6 +51,7 @@ public abstract class BaseHttpCommand : CommandWithStructuredInputBase Verb; @@ -56,10 +59,11 @@ public abstract class BaseHttpCommand : CommandWithStructuredInputBase commandInput) + { + HttpCommandEvent httpCommandEvent = new HttpCommandEvent( + method: Verb.ToUpperInvariant(), + isPathSpecified: commandInput.Arguments.Count > 0, + isHeaderSpecified: commandInput.Options[HeaderOption].Any(), + isResponseHeadersFileSpecified: commandInput.Options[ResponseHeadersFileOption].Any(), + isResponseBodyFileSpecified: commandInput.Options[ResponseBodyFileOption].Any(), + isNoFormattingSpecified: commandInput.Options[NoFormattingOption].Any(), + isStreamingSpecified: commandInput.Options[StreamingOption].Any(), + isNoBodySpecified: RequiresBody && commandInput.Options[NoBodyOption].Any(), + isRequestBodyFileSpecified: RequiresBody && commandInput.Options[BodyFileOption].Any(), + isRequestBodyContentSpecified: RequiresBody && commandInput.Options[BodyContentOption].Any() + ); + + _telemetry.TrackEvent(httpCommandEvent); + } } } diff --git a/src/Microsoft.HttpRepl/Commands/DeleteCommand.cs b/src/Microsoft.HttpRepl/Commands/DeleteCommand.cs index fc069ed1b..a7ac38046 100644 --- a/src/Microsoft.HttpRepl/Commands/DeleteCommand.cs +++ b/src/Microsoft.HttpRepl/Commands/DeleteCommand.cs @@ -3,12 +3,13 @@ using Microsoft.HttpRepl.FileSystem; using Microsoft.HttpRepl.Preferences; +using Microsoft.HttpRepl.Telemetry; namespace Microsoft.HttpRepl.Commands { public class DeleteCommand : BaseHttpCommand { - public DeleteCommand(IFileSystem fileSystem, IPreferences preferences) : base(fileSystem, preferences) { } + public DeleteCommand(IFileSystem fileSystem, IPreferences preferences, ITelemetry telemetry) : base(fileSystem, preferences, telemetry) { } protected override string Verb => "delete"; diff --git a/src/Microsoft.HttpRepl/Commands/GetCommand.cs b/src/Microsoft.HttpRepl/Commands/GetCommand.cs index 52a2e4b2c..f013eb75e 100644 --- a/src/Microsoft.HttpRepl/Commands/GetCommand.cs +++ b/src/Microsoft.HttpRepl/Commands/GetCommand.cs @@ -3,12 +3,13 @@ using Microsoft.HttpRepl.FileSystem; using Microsoft.HttpRepl.Preferences; +using Microsoft.HttpRepl.Telemetry; namespace Microsoft.HttpRepl.Commands { public class GetCommand : BaseHttpCommand { - public GetCommand(IFileSystem fileSystem, IPreferences preferences) : base(fileSystem, preferences) { } + public GetCommand(IFileSystem fileSystem, IPreferences preferences, ITelemetry telemetry) : base(fileSystem, preferences, telemetry) { } protected override string Verb => "get"; diff --git a/src/Microsoft.HttpRepl/Commands/HeadCommand.cs b/src/Microsoft.HttpRepl/Commands/HeadCommand.cs index 4a84dc64d..9e31e5088 100644 --- a/src/Microsoft.HttpRepl/Commands/HeadCommand.cs +++ b/src/Microsoft.HttpRepl/Commands/HeadCommand.cs @@ -3,12 +3,13 @@ using Microsoft.HttpRepl.FileSystem; using Microsoft.HttpRepl.Preferences; +using Microsoft.HttpRepl.Telemetry; namespace Microsoft.HttpRepl.Commands { public class HeadCommand : BaseHttpCommand { - public HeadCommand(IFileSystem fileSystem, IPreferences preferences) : base(fileSystem, preferences) { } + public HeadCommand(IFileSystem fileSystem, IPreferences preferences, ITelemetry telemetry) : base(fileSystem, preferences, telemetry) { } protected override string Verb => "head"; diff --git a/src/Microsoft.HttpRepl/Commands/OptionsCommand.cs b/src/Microsoft.HttpRepl/Commands/OptionsCommand.cs index 0cfe697cf..61beb956f 100644 --- a/src/Microsoft.HttpRepl/Commands/OptionsCommand.cs +++ b/src/Microsoft.HttpRepl/Commands/OptionsCommand.cs @@ -3,12 +3,13 @@ using Microsoft.HttpRepl.FileSystem; using Microsoft.HttpRepl.Preferences; +using Microsoft.HttpRepl.Telemetry; namespace Microsoft.HttpRepl.Commands { public class OptionsCommand : BaseHttpCommand { - public OptionsCommand(IFileSystem fileSystem, IPreferences preferences) : base(fileSystem, preferences) { } + public OptionsCommand(IFileSystem fileSystem, IPreferences preferences, ITelemetry telemetry) : base(fileSystem, preferences, telemetry) { } protected override string Verb => "options"; diff --git a/src/Microsoft.HttpRepl/Commands/PatchCommand.cs b/src/Microsoft.HttpRepl/Commands/PatchCommand.cs index d521e3496..e4c707308 100644 --- a/src/Microsoft.HttpRepl/Commands/PatchCommand.cs +++ b/src/Microsoft.HttpRepl/Commands/PatchCommand.cs @@ -3,12 +3,13 @@ using Microsoft.HttpRepl.FileSystem; using Microsoft.HttpRepl.Preferences; +using Microsoft.HttpRepl.Telemetry; namespace Microsoft.HttpRepl.Commands { public class PatchCommand : BaseHttpCommand { - public PatchCommand(IFileSystem fileSystem, IPreferences preferences) : base(fileSystem, preferences) { } + public PatchCommand(IFileSystem fileSystem, IPreferences preferences, ITelemetry telemetry) : base(fileSystem, preferences, telemetry) { } protected override string Verb => "patch"; diff --git a/src/Microsoft.HttpRepl/Commands/PostCommand.cs b/src/Microsoft.HttpRepl/Commands/PostCommand.cs index 063618451..1c2dc90b5 100644 --- a/src/Microsoft.HttpRepl/Commands/PostCommand.cs +++ b/src/Microsoft.HttpRepl/Commands/PostCommand.cs @@ -3,12 +3,13 @@ using Microsoft.HttpRepl.FileSystem; using Microsoft.HttpRepl.Preferences; +using Microsoft.HttpRepl.Telemetry; namespace Microsoft.HttpRepl.Commands { public class PostCommand : BaseHttpCommand { - public PostCommand(IFileSystem fileSystem, IPreferences preferences) : base(fileSystem, preferences) { } + public PostCommand(IFileSystem fileSystem, IPreferences preferences, ITelemetry telemetry) : base(fileSystem, preferences, telemetry) { } protected override string Verb => "post"; diff --git a/src/Microsoft.HttpRepl/Commands/PutCommand.cs b/src/Microsoft.HttpRepl/Commands/PutCommand.cs index 45b2196e1..1f700f829 100644 --- a/src/Microsoft.HttpRepl/Commands/PutCommand.cs +++ b/src/Microsoft.HttpRepl/Commands/PutCommand.cs @@ -3,12 +3,13 @@ using Microsoft.HttpRepl.FileSystem; using Microsoft.HttpRepl.Preferences; +using Microsoft.HttpRepl.Telemetry; namespace Microsoft.HttpRepl.Commands { public class PutCommand : BaseHttpCommand { - public PutCommand(IFileSystem fileSystem, IPreferences preferences) : base(fileSystem, preferences) { } + public PutCommand(IFileSystem fileSystem, IPreferences preferences, ITelemetry telemetry) : base(fileSystem, preferences, telemetry) { } protected override string Verb => "put"; diff --git a/src/Microsoft.HttpRepl/Program.cs b/src/Microsoft.HttpRepl/Program.cs index afedbbacc..6a11ce681 100644 --- a/src/Microsoft.HttpRepl/Program.cs +++ b/src/Microsoft.HttpRepl/Program.cs @@ -110,18 +110,18 @@ private static void ComposeDependencies(ref IConsoleManager consoleManager, ref dispatcher.AddCommandWithTelemetry(telemetry, new ChangeDirectoryCommand()); dispatcher.AddCommandWithTelemetry(telemetry, new ClearCommand()); dispatcher.AddCommandWithTelemetry(telemetry, new ConnectCommand(preferences, telemetry)); - dispatcher.AddCommandWithTelemetry(telemetry, new DeleteCommand(fileSystem, preferences)); + dispatcher.AddCommandWithTelemetry(telemetry, new DeleteCommand(fileSystem, preferences, telemetry)); dispatcher.AddCommandWithTelemetry(telemetry, new EchoCommand()); dispatcher.AddCommandWithTelemetry(telemetry, new ExitCommand()); - dispatcher.AddCommandWithTelemetry(telemetry, new HeadCommand(fileSystem, preferences)); + dispatcher.AddCommandWithTelemetry(telemetry, new HeadCommand(fileSystem, preferences, telemetry)); dispatcher.AddCommandWithTelemetry(telemetry, new HelpCommand()); - dispatcher.AddCommandWithTelemetry(telemetry, new GetCommand(fileSystem, preferences)); + dispatcher.AddCommandWithTelemetry(telemetry, new GetCommand(fileSystem, preferences, telemetry)); dispatcher.AddCommandWithTelemetry(telemetry, new ListCommand(preferences)); - dispatcher.AddCommandWithTelemetry(telemetry, new OptionsCommand(fileSystem, preferences)); - dispatcher.AddCommandWithTelemetry(telemetry, new PatchCommand(fileSystem, preferences)); + dispatcher.AddCommandWithTelemetry(telemetry, new OptionsCommand(fileSystem, preferences, telemetry)); + dispatcher.AddCommandWithTelemetry(telemetry, new PatchCommand(fileSystem, preferences, telemetry)); dispatcher.AddCommandWithTelemetry(telemetry, new PrefCommand(preferences, telemetry)); - dispatcher.AddCommandWithTelemetry(telemetry, new PostCommand(fileSystem, preferences)); - dispatcher.AddCommandWithTelemetry(telemetry, new PutCommand(fileSystem, preferences)); + dispatcher.AddCommandWithTelemetry(telemetry, new PostCommand(fileSystem, preferences, telemetry)); + dispatcher.AddCommandWithTelemetry(telemetry, new PutCommand(fileSystem, preferences, telemetry)); dispatcher.AddCommandWithTelemetry(telemetry, new RunCommand(fileSystem)); dispatcher.AddCommandWithTelemetry(telemetry, new SetHeaderCommand(telemetry)); dispatcher.AddCommandWithTelemetry(telemetry, new UICommand(new UriLauncher(), preferences)); diff --git a/src/Microsoft.HttpRepl/Telemetry/Events/HttpCommandEvent.cs b/src/Microsoft.HttpRepl/Telemetry/Events/HttpCommandEvent.cs new file mode 100644 index 000000000..288ce37b7 --- /dev/null +++ b/src/Microsoft.HttpRepl/Telemetry/Events/HttpCommandEvent.cs @@ -0,0 +1,25 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.HttpRepl.Telemetry.Events +{ + internal class HttpCommandEvent : TelemetryEventBase + { + public HttpCommandEvent(string method, bool isPathSpecified, bool isHeaderSpecified, bool isResponseHeadersFileSpecified, + bool isResponseBodyFileSpecified, bool isNoFormattingSpecified, bool isStreamingSpecified, + bool isNoBodySpecified, bool isRequestBodyFileSpecified, bool isRequestBodyContentSpecified) + : base(TelemetryEventNames.HttpCommand) + { + SetProperty(TelemetryPropertyNames.HttpCommand_Method, method); + SetProperty(TelemetryPropertyNames.HttpCommand_PathSpecified, isPathSpecified); + SetProperty(TelemetryPropertyNames.HttpCommand_HeaderSpecified, isHeaderSpecified); + SetProperty(TelemetryPropertyNames.HttpCommand_ResponseHeadersFileSpecified, isResponseHeadersFileSpecified); + SetProperty(TelemetryPropertyNames.HttpCommand_ResponseBodyFileSpecified, isResponseBodyFileSpecified); + SetProperty(TelemetryPropertyNames.HttpCommand_NoFormattingSpecified, isNoFormattingSpecified); + SetProperty(TelemetryPropertyNames.HttpCommand_StreamingSpecified, isStreamingSpecified); + SetProperty(TelemetryPropertyNames.HttpCommand_NoBodySpecified, isNoBodySpecified); + SetProperty(TelemetryPropertyNames.HttpCommand_RequestBodyFileSpecified, isRequestBodyFileSpecified); + SetProperty(TelemetryPropertyNames.HttpCommand_RequestBodyContentSpecified, isRequestBodyContentSpecified); + } + } +} diff --git a/src/Microsoft.HttpRepl/Telemetry/TelemetryConstants.cs b/src/Microsoft.HttpRepl/Telemetry/TelemetryConstants.cs index 94f12edbb..4356a14af 100644 --- a/src/Microsoft.HttpRepl/Telemetry/TelemetryConstants.cs +++ b/src/Microsoft.HttpRepl/Telemetry/TelemetryConstants.cs @@ -7,6 +7,7 @@ internal class TelemetryEventNames { public const string CommandExecuted = nameof(CommandExecuted); public const string Connect = nameof(Connect); + public const string HttpCommand = nameof(HttpCommand); public const string Preference = nameof(Preference); public const string SetHeader = nameof(SetHeader); public const string Started = nameof(Started); @@ -23,6 +24,17 @@ internal class TelemetryPropertyNames public const string Connect_OpenApiSpecified = "OpenApiSpecified"; public const string Connect_RootSpecified = "RootSpecified"; + public const string HttpCommand_HeaderSpecified = "HeaderSpecified"; + public const string HttpCommand_Method = "Method"; + public const string HttpCommand_NoBodySpecified = "NoBodySpecified"; + public const string HttpCommand_NoFormattingSpecified = "NoFormattingSpecified"; + public const string HttpCommand_PathSpecified = "PathSpecified"; + public const string HttpCommand_RequestBodyContentSpecified = "RequestBodyContentSpecified"; + public const string HttpCommand_RequestBodyFileSpecified = "RequestBodyFileSpecified"; + public const string HttpCommand_ResponseHeadersFileSpecified = "ResponseHeadersFileSpecified"; + public const string HttpCommand_ResponseBodyFileSpecified = "ResponseBodyFileSpecified"; + public const string HttpCommand_StreamingSpecified = "StreamingSpecified"; + public const string Preference_GetOrSet = "GetOrSet"; public const string Preference_PreferenceName = "PreferenceName"; diff --git a/test/Microsoft.HttpRepl.Tests/Commands/DeleteCommandsTests.cs b/test/Microsoft.HttpRepl.Tests/Commands/DeleteCommandsTests.cs index 1173d5c8d..49f608dc4 100644 --- a/test/Microsoft.HttpRepl.Tests/Commands/DeleteCommandsTests.cs +++ b/test/Microsoft.HttpRepl.Tests/Commands/DeleteCommandsTests.cs @@ -44,7 +44,7 @@ public async Task ExecuteAsync_WithNoBasePath_VerifyError() string expectedErrorMessage = Strings.Error_NoBasePath.SetColor(httpState.ErrorColor); - DeleteCommand deleteCommand = new DeleteCommand(fileSystem, preferences); + DeleteCommand deleteCommand = new DeleteCommand(fileSystem, preferences, new NullTelemetry()); await deleteCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); Assert.Equal(expectedErrorMessage, shellState.ErrorMessage); @@ -63,7 +63,7 @@ public async Task ExecuteAsync_WithMultipartRoute_VerifyOutput() out MockedFileSystem fileSystem, out IPreferences preferences); - DeleteCommand deleteCommand = new DeleteCommand(fileSystem, preferences); + DeleteCommand deleteCommand = new DeleteCommand(fileSystem, preferences, new NullTelemetry()); await deleteCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); string expectedResponse = "File path delete received successfully."; @@ -87,7 +87,7 @@ public async Task ExecuteAsync_WithOnlyBaseAddress_VerifyOutput() out MockedFileSystem fileSystem, out IPreferences preferences); - DeleteCommand deleteCommand = new DeleteCommand(fileSystem, preferences); + DeleteCommand deleteCommand = new DeleteCommand(fileSystem, preferences, new NullTelemetry()); await deleteCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); string expectedResponse = "Root delete received successfully."; diff --git a/test/Microsoft.HttpRepl.Tests/Commands/EchoCommandTests.cs b/test/Microsoft.HttpRepl.Tests/Commands/EchoCommandTests.cs index 47392a4d7..f2b49368d 100644 --- a/test/Microsoft.HttpRepl.Tests/Commands/EchoCommandTests.cs +++ b/test/Microsoft.HttpRepl.Tests/Commands/EchoCommandTests.cs @@ -79,7 +79,7 @@ public async Task PostCommand_WithEchoOn_OnlyPrintsRequestBodyOnce() out IPreferences preferences); httpState.EchoRequest = true; - PostCommand postCommand = new PostCommand(fileSystem, preferences); + PostCommand postCommand = new PostCommand(fileSystem, preferences, new NullTelemetry()); await postCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); List result = shellState.Output; diff --git a/test/Microsoft.HttpRepl.Tests/Commands/GetCommandTests.cs b/test/Microsoft.HttpRepl.Tests/Commands/GetCommandTests.cs index 516a9c5cf..e7c33aeee 100644 --- a/test/Microsoft.HttpRepl.Tests/Commands/GetCommandTests.cs +++ b/test/Microsoft.HttpRepl.Tests/Commands/GetCommandTests.cs @@ -9,6 +9,7 @@ using Microsoft.HttpRepl.Fakes; using Microsoft.HttpRepl.Preferences; using Microsoft.HttpRepl.Resources; +using Microsoft.HttpRepl.Telemetry; using Microsoft.Repl.ConsoleHandling; using Microsoft.Repl.Parsing; using Xunit; @@ -45,7 +46,7 @@ public async Task ExecuteAsync_WithNoBasePath_VerifyError() string expectedErrorMessage = Strings.Error_NoBasePath.SetColor(httpState.ErrorColor); - GetCommand getCommand = new GetCommand(fileSystem, preferences); + GetCommand getCommand = new GetCommand(fileSystem, preferences, new NullTelemetry()); await getCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); Assert.Equal(expectedErrorMessage, shellState.ErrorMessage); @@ -64,7 +65,7 @@ public async Task ExecuteAsync_WithMultipartRoute_VerifyOutput() out MockedFileSystem fileSystem, out IPreferences preferences); - GetCommand getCommand = new GetCommand(fileSystem, preferences); + GetCommand getCommand = new GetCommand(fileSystem, preferences, new NullTelemetry()); await getCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); string expectedResponse = "This is a test response."; @@ -88,7 +89,7 @@ public async Task ExecuteAsync_WithOnlyBaseAddress_VerifyOutput() out MockedFileSystem fileSystem, out IPreferences preferences); - GetCommand getCommand = new GetCommand(fileSystem, preferences); + GetCommand getCommand = new GetCommand(fileSystem, preferences, new NullTelemetry()); await getCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); string expectedResponse = "This is a response from the root."; @@ -127,7 +128,7 @@ public async Task ExecuteAsync_WithJsonContentTypeInHeader_FormatsResponseConten out IPreferences preferences, contentType: "application/json"); - GetCommand getCommand = new GetCommand(fileSystem, preferences); + GetCommand getCommand = new GetCommand(fileSystem, preferences, new NullTelemetry()); await getCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); int expectedHeaderLength = 2; @@ -175,7 +176,7 @@ public async Task ExecuteAsync_WithTextContentTypeInHeader_DoesNotFormatResponse out IPreferences preferences, contentType: "text/plain"); - GetCommand getCommand = new GetCommand(fileSystem, preferences); + GetCommand getCommand = new GetCommand(fileSystem, preferences, new NullTelemetry()); await getCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); List result = shellState.Output; @@ -208,7 +209,7 @@ public async Task ExecuteAsync_WithHeaderOptionAndEchoOn_VerifyOutputContainsReq httpState.EchoRequest = true; - GetCommand getCommand = new GetCommand(fileSystem, preferences); + GetCommand getCommand = new GetCommand(fileSystem, preferences, new NullTelemetry()); await getCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); List result = shellState.Output; @@ -242,7 +243,7 @@ public async Task ExecuteAsync_WithSameHeadersAndBodyPaths_VerifyError() string expectedErrorMessage = Strings.BaseHttpCommand_Error_SameBodyAndHeaderFileName.SetColor(httpState.ErrorColor); - GetCommand getCommand = new GetCommand(fileSystem, preferences); + GetCommand getCommand = new GetCommand(fileSystem, preferences, new NullTelemetry()); // Act await getCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); @@ -250,5 +251,43 @@ public async Task ExecuteAsync_WithSameHeadersAndBodyPaths_VerifyError() // Assert Assert.Equal(expectedErrorMessage, shellState.ErrorMessage); } + + [Fact] + public async Task ExecuteAsync_WithPathAndOptions_SendsTelemetry() + { + // Arrange + string expectedPath = "/path"; + string expectedMethod = "GET"; + ArrangeInputs(commandText: $"{expectedMethod} {expectedPath} --no-formatting --header Content-Length=20", + baseAddress: _baseAddress, + path: _path, + urlsWithResponse: _urlsWithResponse, + out MockedShellState shellState, + out HttpState httpState, + out ICoreParseResult parseResult, + out MockedFileSystem fileSystem, + out IPreferences preferences); + + TelemetryCollector telemetry = new TelemetryCollector(); + GetCommand getCommand = new GetCommand(fileSystem, preferences, telemetry); + + // Act + await getCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); + + // Assert + Assert.Single(telemetry.Telemetry); + TelemetryCollector.CollectedTelemetry collectedTelemetry = telemetry.Telemetry[0]; + Assert.Equal(TelemetryEventNames.HttpCommand, collectedTelemetry.EventName, ignoreCase: true); + Assert.Equal(expectedMethod, collectedTelemetry.Properties[TelemetryPropertyNames.HttpCommand_Method]); + Assert.Equal("True", collectedTelemetry.Properties[TelemetryPropertyNames.HttpCommand_PathSpecified]); + Assert.Equal("True", collectedTelemetry.Properties[TelemetryPropertyNames.HttpCommand_NoFormattingSpecified]); + Assert.Equal("True", collectedTelemetry.Properties[TelemetryPropertyNames.HttpCommand_HeaderSpecified]); + Assert.Equal("False", collectedTelemetry.Properties[TelemetryPropertyNames.HttpCommand_ResponseHeadersFileSpecified]); + Assert.Equal("False", collectedTelemetry.Properties[TelemetryPropertyNames.HttpCommand_StreamingSpecified]); + Assert.Equal("False", collectedTelemetry.Properties[TelemetryPropertyNames.HttpCommand_NoBodySpecified]); + Assert.Equal("False", collectedTelemetry.Properties[TelemetryPropertyNames.HttpCommand_RequestBodyContentSpecified]); + Assert.Equal("False", collectedTelemetry.Properties[TelemetryPropertyNames.HttpCommand_RequestBodyFileSpecified]); + Assert.Equal("False", collectedTelemetry.Properties[TelemetryPropertyNames.HttpCommand_ResponseBodyFileSpecified]); + } } } diff --git a/test/Microsoft.HttpRepl.Tests/Commands/HeadCommandTests.cs b/test/Microsoft.HttpRepl.Tests/Commands/HeadCommandTests.cs index 8bb09ce0d..90f7316ad 100644 --- a/test/Microsoft.HttpRepl.Tests/Commands/HeadCommandTests.cs +++ b/test/Microsoft.HttpRepl.Tests/Commands/HeadCommandTests.cs @@ -44,7 +44,7 @@ public async Task ExecuteAsync_WithNoBasePath_VerifyError() string expectedErrorMessage = Strings.Error_NoBasePath.SetColor(httpState.ErrorColor); - HeadCommand headCommand = new HeadCommand(fileSystem, preferences); + HeadCommand headCommand = new HeadCommand(fileSystem, preferences, new NullTelemetry()); await headCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); Assert.Equal(expectedErrorMessage, shellState.ErrorMessage); @@ -64,7 +64,7 @@ public async Task ExecuteAsync_WithMultipartRoute_VerifyHeaders() out IPreferences preferences, header: "X-HTTPREPL-TESTHEADER"); - HeadCommand headCommand = new HeadCommand(fileSystem, preferences); + HeadCommand headCommand = new HeadCommand(fileSystem, preferences, new NullTelemetry()); await headCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); string expectedHeader = "X-HTTPREPL-TESTHEADER: Header value for HEAD request with route."; @@ -89,7 +89,7 @@ public async Task ExecuteAsync_WithOnlyBaseAddress_VerifyHeaders() out IPreferences preferences, header: "X-HTTPREPL-TESTHEADER"); - HeadCommand headCommand = new HeadCommand(fileSystem, preferences); + HeadCommand headCommand = new HeadCommand(fileSystem, preferences, new NullTelemetry()); await headCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); string expectedHeader = "X-HTTPREPL-TESTHEADER: Header value for root HEAD request."; diff --git a/test/Microsoft.HttpRepl.Tests/Commands/OptionsCommandTests.cs b/test/Microsoft.HttpRepl.Tests/Commands/OptionsCommandTests.cs index 6bdb09024..a3682e977 100644 --- a/test/Microsoft.HttpRepl.Tests/Commands/OptionsCommandTests.cs +++ b/test/Microsoft.HttpRepl.Tests/Commands/OptionsCommandTests.cs @@ -44,7 +44,7 @@ public async Task ExecuteAsync_WithNoBasePath_VerifyError() string expectedErrorMessage = Strings.Error_NoBasePath.SetColor(httpState.ErrorColor); - OptionsCommand optionsCommand = new OptionsCommand(fileSystem, preferences); + OptionsCommand optionsCommand = new OptionsCommand(fileSystem, preferences, new NullTelemetry()); await optionsCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); Assert.Equal(expectedErrorMessage, shellState.ErrorMessage); @@ -64,7 +64,7 @@ public async Task ExecuteAsync_WithMultipartRoute_VerifyOutput() out IPreferences preferences, header: "X-HTTPREPL-TESTHEADER"); - OptionsCommand optionsCommand = new OptionsCommand(fileSystem, preferences); + OptionsCommand optionsCommand = new OptionsCommand(fileSystem, preferences, new NullTelemetry()); await optionsCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); string expectedHeader = "X-HTTPREPL-TESTHEADER: Header value for OPTIONS request with route."; @@ -89,7 +89,7 @@ public async Task ExecuteAsync_WithOnlyBaseAddress_VerifyOutput() out IPreferences preferences, header: "X-HTTPREPL-TESTHEADER"); - OptionsCommand optionsCommand = new OptionsCommand(fileSystem, preferences); + OptionsCommand optionsCommand = new OptionsCommand(fileSystem, preferences, new NullTelemetry()); await optionsCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); string expectedHeader = "X-HTTPREPL-TESTHEADER: Header value for root OPTIONS request."; diff --git a/test/Microsoft.HttpRepl.Tests/Commands/PatchCommandTests.cs b/test/Microsoft.HttpRepl.Tests/Commands/PatchCommandTests.cs index e1d837ea9..56557304a 100644 --- a/test/Microsoft.HttpRepl.Tests/Commands/PatchCommandTests.cs +++ b/test/Microsoft.HttpRepl.Tests/Commands/PatchCommandTests.cs @@ -47,7 +47,7 @@ public async Task ExecuteAsync_WithNoBasePath_VerifyError() string expectedErrorMessage = Strings.Error_NoBasePath.SetColor(httpState.ErrorColor); - PatchCommand patchCommand = new PatchCommand(fileSystem, preferences); + PatchCommand patchCommand = new PatchCommand(fileSystem, preferences, new NullTelemetry()); await patchCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); Assert.Equal(expectedErrorMessage, shellState.ErrorMessage); @@ -66,7 +66,7 @@ public async Task ExecuteAsync_OnlyBaseAddressWithInlineContent_VerifyResponse() out MockedFileSystem fileSystem, out IPreferences preferences); - PatchCommand patchCommand = new PatchCommand(fileSystem, preferences); + PatchCommand patchCommand = new PatchCommand(fileSystem, preferences, new NullTelemetry()); await patchCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); string expectedResponse = "This is a test response from a PATCH: \"Test Patch Body\""; @@ -90,7 +90,7 @@ public async Task ExecuteAsync_MultiPartRouteWithInlineContent_VerifyResponse() out MockedFileSystem fileSystem, out IPreferences preferences); - PatchCommand patchCommand = new PatchCommand(fileSystem, preferences); + PatchCommand patchCommand = new PatchCommand(fileSystem, preferences, new NullTelemetry()); await patchCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); string expectedResponse = "This is a test response from a PATCH: \"Test Patch Body\""; @@ -114,7 +114,7 @@ public async Task ExecuteAsync_MultiPartRouteWithNoBodyRequired_VerifyResponse() out MockedFileSystem fileSystem, out IPreferences preferences); - PatchCommand patchCommand = new PatchCommand(fileSystem, preferences); + PatchCommand patchCommand = new PatchCommand(fileSystem, preferences, new NullTelemetry()); await patchCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); string expectedResponse = "This is a test response from a PATCH: \"\""; @@ -145,7 +145,7 @@ public async Task ExecuteAsync_MultiPartRouteWithBodyFromFile_VerifyResponse() fileSystem.AddFile(filePath, "Test Patch Body From File"); - PatchCommand patchCommand = new PatchCommand(fileSystem, preferences); + PatchCommand patchCommand = new PatchCommand(fileSystem, preferences, new NullTelemetry()); await patchCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); List result = shellState.Output; diff --git a/test/Microsoft.HttpRepl.Tests/Commands/PostCommandTests.cs b/test/Microsoft.HttpRepl.Tests/Commands/PostCommandTests.cs index 3644df5fe..1aff57a43 100644 --- a/test/Microsoft.HttpRepl.Tests/Commands/PostCommandTests.cs +++ b/test/Microsoft.HttpRepl.Tests/Commands/PostCommandTests.cs @@ -51,7 +51,7 @@ public async Task ExecuteAsync_WithNoBasePath_VerifyError() string expectedErrorMessage = Strings.Error_NoBasePath.SetColor(httpState.ErrorColor); - PostCommand postCommand = new PostCommand(fileSystem, preferences); + PostCommand postCommand = new PostCommand(fileSystem, preferences, new NullTelemetry()); await postCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); Assert.Equal(expectedErrorMessage, shellState.ErrorMessage); @@ -70,7 +70,7 @@ public async Task ExecuteAsync_OnlyBaseAddressWithInlineContent_VerifyResponse() out MockedFileSystem fileSystem, out IPreferences preferences); - PostCommand postCommand = new PostCommand(fileSystem, preferences); + PostCommand postCommand = new PostCommand(fileSystem, preferences, new NullTelemetry()); await postCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); string expectedResponse = "This is a test response from a POST: \"Test Post Body\""; @@ -97,7 +97,7 @@ public async Task ExecuteAsync_WithContentTypeHeader_NotDuplicated() httpState.EchoRequest = true; - PostCommand postCommand = new PostCommand(fileSystem, preferences); + PostCommand postCommand = new PostCommand(fileSystem, preferences, new NullTelemetry()); await postCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); List result = shellState.Output; @@ -123,7 +123,7 @@ public async Task ExecuteAsync_WithOtherContentHeader_NotDuplicated() httpState.EchoRequest = true; - PostCommand postCommand = new PostCommand(fileSystem, preferences); + PostCommand postCommand = new PostCommand(fileSystem, preferences, new NullTelemetry()); await postCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); List result = shellState.Output; @@ -149,7 +149,7 @@ public async Task ExecuteAsync_WithNonContentHeader_NotDuplicated() httpState.EchoRequest = true; - PostCommand postCommand = new PostCommand(fileSystem, preferences); + PostCommand postCommand = new PostCommand(fileSystem, preferences, new NullTelemetry()); await postCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); @@ -173,7 +173,7 @@ public async Task ExecuteAsync_MultiPartRouteWithInlineContent_VerifyResponse() out MockedFileSystem fileSystem, out IPreferences preferences); - PostCommand postCommand = new PostCommand(fileSystem, preferences); + PostCommand postCommand = new PostCommand(fileSystem, preferences, new NullTelemetry()); await postCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); string expectedResponse = "This is a test response from a POST: \"Test Post Body\""; @@ -197,7 +197,7 @@ public async Task ExecuteAsync_MultiPartRouteWithNoBodyRequired_VerifyResponse() out MockedFileSystem fileSystem, out IPreferences preferences); - PostCommand postCommand = new PostCommand(fileSystem, preferences); + PostCommand postCommand = new PostCommand(fileSystem, preferences, new NullTelemetry()); await postCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); string expectedResponse = "This is a test response from a POST: \"\""; @@ -228,7 +228,7 @@ public async Task ExecuteAsync_MultiPartRouteWithBodyFromFile_VerifyResponse() fileSystem.AddFile(filePath, "Test Post Body From File"); - PostCommand postCommand = new PostCommand(fileSystem, preferences); + PostCommand postCommand = new PostCommand(fileSystem, preferences, new NullTelemetry()); await postCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); List result = shellState.Output; @@ -256,7 +256,7 @@ public async Task ExecuteAsync_NonExistentContentFile_VerifyResponse() readBodyFromFile: true, fileContents: fileContents); - PostCommand postCommand = new PostCommand(fileSystem, preferences); + PostCommand postCommand = new PostCommand(fileSystem, preferences, new NullTelemetry()); await postCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); Assert.Empty(shellState.Output); @@ -278,7 +278,7 @@ public async Task ExecuteAsync_WithEditorNotConfigured_VerifyResponse() preferences.SetValue(WellKnownPreference.DefaultEditorCommand, ""); - PostCommand postCommand = new PostCommand(fileSystem, preferences); + PostCommand postCommand = new PostCommand(fileSystem, preferences, new NullTelemetry()); await postCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); Assert.Empty(shellState.Output); @@ -299,7 +299,7 @@ public async Task ExecuteAsync_WithEditorDoesNotExist_VerifyResponse() ICoreParseResult parseResult = CoreParseResultHelper.Create(commandText); HttpClient httpClient = new HttpClient(); HttpState httpState = new HttpState(preferences, httpClient); - PostCommand postCommand = new PostCommand(fileSystem, preferences); + PostCommand postCommand = new PostCommand(fileSystem, preferences, new NullTelemetry()); preferences.SetValue(WellKnownPreference.DefaultEditorCommand, editorPath); diff --git a/test/Microsoft.HttpRepl.Tests/Commands/PutCommandTests.cs b/test/Microsoft.HttpRepl.Tests/Commands/PutCommandTests.cs index a60be38a9..6d128cc11 100644 --- a/test/Microsoft.HttpRepl.Tests/Commands/PutCommandTests.cs +++ b/test/Microsoft.HttpRepl.Tests/Commands/PutCommandTests.cs @@ -47,7 +47,7 @@ public async Task ExecuteAsync_WithNoBasePath_VerifyError() string expectedErrorMessage = Strings.Error_NoBasePath.SetColor(httpState.ErrorColor); - PutCommand putCommand = new PutCommand(fileSystem, preferences); + PutCommand putCommand = new PutCommand(fileSystem, preferences, new NullTelemetry()); await putCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); Assert.Equal(expectedErrorMessage, shellState.ErrorMessage); @@ -66,7 +66,7 @@ public async Task ExecuteAsync_OnlyBaseAddressWithInlineContent_VerifyResponse() out MockedFileSystem fileSystem, out IPreferences preferences); - PutCommand putCommand = new PutCommand(fileSystem, preferences); + PutCommand putCommand = new PutCommand(fileSystem, preferences, new NullTelemetry()); await putCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); string expectedResponse = "This is a test response from a PUT: \"Test Put Body\""; @@ -90,7 +90,7 @@ public async Task ExecuteAsync_MultiPartRouteWithInlineContent_VerifyResponse() out MockedFileSystem fileSystem, out IPreferences preferences); - PutCommand putCommand = new PutCommand(fileSystem, preferences); + PutCommand putCommand = new PutCommand(fileSystem, preferences, new NullTelemetry()); await putCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); string expectedResponse = "This is a test response from a PUT: \"Test Put Body\""; @@ -114,7 +114,7 @@ public async Task ExecuteAsync_MultiPartRouteWithNoBodyRequired_VerifyResponse() out MockedFileSystem fileSystem, out IPreferences preferences); - PutCommand putCommand = new PutCommand(fileSystem, preferences); + PutCommand putCommand = new PutCommand(fileSystem, preferences, new NullTelemetry()); await putCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); string expectedResponse = "This is a test response from a PUT: \"\""; @@ -145,7 +145,7 @@ public async Task ExecuteAsync_MultiPartRouteWithBodyFromFile_VerifyResponse() fileSystem.AddFile(filePath, "Test Put Body From File"); - PutCommand putCommand = new PutCommand(fileSystem, preferences); + PutCommand putCommand = new PutCommand(fileSystem, preferences, new NullTelemetry()); await putCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); List result = shellState.Output;