diff --git a/WebJobs.proj b/WebJobs.proj index 0fab8adc..0201f5da 100644 --- a/WebJobs.proj +++ b/WebJobs.proj @@ -36,6 +36,10 @@ Assembly $(PublishPath)\Binaries + + Assembly + $(PublishPath)\Binaries + Assembly $(PublishPath)\Binaries @@ -65,6 +69,10 @@ File $(PublishPath)\Packages + + File + $(PublishPath)\Packages + diff --git a/WebJobs.sln b/WebJobs.sln index 88b9f1f6..6a088016 100644 --- a/WebJobs.sln +++ b/WebJobs.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 +# Visual Studio 15 +VisualStudioVersion = 15.0.26403.7 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{639967B0-0544-4C52-94AC-9A3D25E33256}" EndProject @@ -56,6 +56,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Sample", "Sample", "{72A798 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleHost", "sample\SampleHost\SampleHost.csproj", "{93429246-CCE9-4EB0-B94D-68522862BA79}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebJobs.Logging.ApplicationInsights", "src\Microsoft.Azure.WebJobs.Logging.ApplicationInsights\WebJobs.Logging.ApplicationInsights.csproj", "{D3FF0FDE-EBDF-4751-8131-3375CF2A5C21}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -130,6 +132,10 @@ Global {93429246-CCE9-4EB0-B94D-68522862BA79}.Debug|Any CPU.Build.0 = Debug|Any CPU {93429246-CCE9-4EB0-B94D-68522862BA79}.Release|Any CPU.ActiveCfg = Release|Any CPU {93429246-CCE9-4EB0-B94D-68522862BA79}.Release|Any CPU.Build.0 = Release|Any CPU + {D3FF0FDE-EBDF-4751-8131-3375CF2A5C21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D3FF0FDE-EBDF-4751-8131-3375CF2A5C21}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D3FF0FDE-EBDF-4751-8131-3375CF2A5C21}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D3FF0FDE-EBDF-4751-8131-3375CF2A5C21}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/sample/SampleHost/App.config b/sample/SampleHost/App.config index 63491736..5e795166 100644 --- a/sample/SampleHost/App.config +++ b/sample/SampleHost/App.config @@ -21,6 +21,10 @@ + + + + diff --git a/sample/SampleHost/SampleHost.csproj b/sample/SampleHost/SampleHost.csproj index 26883425..d3d17f67 100644 --- a/sample/SampleHost/SampleHost.csproj +++ b/sample/SampleHost/SampleHost.csproj @@ -159,6 +159,10 @@ {0e095cb2-3030-49ff-966c-785f1a55f0c1} WebJobs.Host + + {d3ff0fde-ebdf-4751-8131-3375cf2a5c21} + WebJobs.Logging.ApplicationInsights + {e3f2b2c8-6b8d-4d6a-a3ae-98366c9f3b49} WebJobs diff --git a/src/Microsoft.Azure.WebJobs.Host/GlobalSuppressions.cs b/src/Microsoft.Azure.WebJobs.Host/GlobalSuppressions.cs index 3a3a478b..665a8b2c 100644 --- a/src/Microsoft.Azure.WebJobs.Host/GlobalSuppressions.cs +++ b/src/Microsoft.Azure.WebJobs.Host/GlobalSuppressions.cs @@ -69,13 +69,4 @@ [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "Microsoft.Azure.WebJobs.Host.JobHostQueuesConfiguration.#MaxPollingIntervalInt")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "Microsoft.Azure.WebJobs.Host.JobHostQueuesConfiguration.#MaxPollingIntervalInt")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "AddBindingRule", Scope = "member", Target = "Microsoft.Azure.WebJobs.Host.Config.ExtensionConfigContext.#AddBindingRule`1()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "Microsoft.Extensions.Logging.AppInsightsLoggerExtensions.#AddAppInsights(Microsoft.Extensions.Logging.ILoggerFactory,System.String,System.Func`3)")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "Microsoft.Extensions.Logging.AppInsightsLoggerExtensions.#AddAppInsights(Microsoft.Extensions.Logging.ILoggerFactory,System.String,System.Func`3)")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "Microsoft.Extensions.Logging.AppInsightsLoggerExtensions.#AddAppInsights(Microsoft.Extensions.Logging.ILoggerFactory,System.String,System.Func`3)")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "Microsoft.Azure.WebJobs.Host.Loggers.FunctionResultAggregatorFactory.#Create(System.Int32,System.TimeSpan,Microsoft.Extensions.Logging.ILoggerFactory)")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "Microsoft.Extensions.Logging.ApplicationInsightsLoggerExtensions.#AddApplicationInsights(Microsoft.Extensions.Logging.ILoggerFactory,Microsoft.Azure.WebJobs.Host.Loggers.ITelemetryClientFactory,System.Func`3)")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "Microsoft.Extensions.Logging.ApplicationInsightsLoggerExtensions.#AddApplicationInsights(Microsoft.Extensions.Logging.ILoggerFactory,System.String,System.Func`3)")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "Microsoft.Azure.WebJobs.Host.Loggers.DefaultTelemetryClientFactory.#InitializeConfiguration()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", MessageId = "_perfModule", Scope = "member", Target = "Microsoft.Azure.WebJobs.Host.Loggers.DefaultTelemetryClientFactory.#Dispose(System.Boolean)")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", MessageId = "_quickPulseModule", Scope = "member", Target = "Microsoft.Azure.WebJobs.Host.Loggers.DefaultTelemetryClientFactory.#Dispose(System.Boolean)")] - +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "Microsoft.Azure.WebJobs.Host.Loggers.FunctionResultAggregatorFactory.#Create(System.Int32,System.TimeSpan,Microsoft.Extensions.Logging.ILoggerFactory)")] \ No newline at end of file diff --git a/src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/Aggregator/FunctionResultAggregate.cs b/src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/Aggregator/FunctionResultAggregate.cs index f93b1a1e..e8f0df9f 100644 --- a/src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/Aggregator/FunctionResultAggregate.cs +++ b/src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/Aggregator/FunctionResultAggregate.cs @@ -26,7 +26,7 @@ namespace Microsoft.Azure.WebJobs.Host.Loggers [LoggingKeys.Name] = Name, [LoggingKeys.Count] = Count, [LoggingKeys.Timestamp] = Timestamp, - [LoggingKeys.AvgDuration] = AverageDuration, + [LoggingKeys.AverageDuration] = AverageDuration, [LoggingKeys.MaxDuration] = MaxDuration, [LoggingKeys.MinDuration] = MinDuration, [LoggingKeys.Successes] = Successes, diff --git a/src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/Constants/LoggingKeys.cs b/src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/Constants/LoggingKeys.cs index 65665983..f5164ca4 100644 --- a/src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/Constants/LoggingKeys.cs +++ b/src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/Constants/LoggingKeys.cs @@ -1,32 +1,101 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. +using Microsoft.Extensions.Logging; + namespace Microsoft.Azure.WebJobs.Host.Loggers { - internal static class LoggingKeys + /// + /// Keys used by the infrastructure. + /// + public static class LoggingKeys { - // These are publicly visible as property names or prefixes + /// + /// public const string FullName = "FullName"; + + /// + /// public const string Name = "Name"; + + /// + /// public const string Count = "Count"; + + /// + /// public const string Successes = "Successes"; + + /// + /// public const string Failures = "Failures"; + + /// + /// public const string SuccessRate = "SuccessRate"; - public const string AvgDuration = "AvgDurationMs"; + + /// + /// + public const string AverageDuration = "AvgDurationMs"; + + /// + /// public const string MaxDuration = "MaxDurationMs"; + + /// + /// public const string MinDuration = "MinDurationMs"; + + /// + /// public const string Timestamp = "Timestamp"; + + /// + /// public const string InvocationId = "InvocationId"; + + /// + /// public const string TriggerReason = "TriggerReason"; + + /// + /// public const string StartTime = "StartTime"; + + /// + /// public const string EndTime = "EndTime"; + + /// + /// public const string Duration = "Duration"; + + /// + /// public const string Succeeded = "Succeeded"; + + /// + /// public const string FormattedMessage = "FormattedMessage"; + + /// + /// public const string CategoryName = "Category"; + + /// + /// public const string HttpMethod = "HttpMethod"; + + /// + /// public const string CustomPropertyPrefix = "prop__"; + + /// + /// public const string ParameterPrefix = "param__"; + + /// + /// public const string OriginalFormat = "{OriginalFormat}"; } } diff --git a/src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/Constants/ScopeKeys.cs b/src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/Constants/ScopeKeys.cs index 12150dd5..d7bda425 100644 --- a/src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/Constants/ScopeKeys.cs +++ b/src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/Constants/ScopeKeys.cs @@ -3,19 +3,19 @@ namespace Microsoft.Azure.WebJobs.Host.Loggers { - internal static class ScopeKeys + /// + /// A collection of constants used for logging scope keys. + /// + public static class ScopeKeys { - // These are used internally for passing values via scopes + /// + /// A key identifying the function invocation id. + /// public const string FunctionInvocationId = "MS_FunctionInvocationId"; + + /// + /// A key identifying the function name. + /// public const string FunctionName = "MS_FunctionName"; - public const string HttpRequest = "MS_HttpRequest"; - - // HTTP context is set automatically by ASP.NET, this isn't ours. - internal const string HttpContext = "MS_HttpContext"; - - // This is set by Functions - internal const string FunctionsHttpResponse = "MS_AzureFunctionsHttpResponse"; - - internal const string ForwardedForHeaderName = "X-Forwarded-For"; } } diff --git a/src/Microsoft.Azure.WebJobs.Host/WebJobs.Host.csproj b/src/Microsoft.Azure.WebJobs.Host/WebJobs.Host.csproj index a09238ee..e3faa687 100644 --- a/src/Microsoft.Azure.WebJobs.Host/WebJobs.Host.csproj +++ b/src/Microsoft.Azure.WebJobs.Host/WebJobs.Host.csproj @@ -54,30 +54,6 @@ ..\Common\PublicKey.snk - - ..\..\packages\Microsoft.ApplicationInsights.Agent.Intercept.2.0.7\lib\net45\Microsoft.AI.Agent.Intercept.dll - True - - - ..\..\packages\Microsoft.ApplicationInsights.DependencyCollector.2.3.0\lib\net45\Microsoft.AI.DependencyCollector.dll - True - - - ..\..\packages\Microsoft.ApplicationInsights.PerfCounterCollector.2.3.0\lib\net45\Microsoft.AI.PerfCounterCollector.dll - True - - - ..\..\packages\Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.2.3.0\lib\net45\Microsoft.AI.ServerTelemetryChannel.dll - True - - - ..\..\packages\Microsoft.ApplicationInsights.WindowsServer.2.3.0\lib\net45\Microsoft.AI.WindowsServer.dll - True - - - ..\..\packages\Microsoft.ApplicationInsights.2.3.0\lib\net46\Microsoft.ApplicationInsights.dll - True - ..\..\packages\Microsoft.Azure.KeyVault.Core.1.0.0\lib\net40\Microsoft.Azure.KeyVault.Core.dll True @@ -190,7 +166,6 @@ ..\..\packages\Microsoft.Tpl.Dataflow.4.5.24\lib\portable-net45+win8+wpa81\System.Threading.Tasks.Dataflow.dll True - @@ -517,7 +492,6 @@ - @@ -528,15 +502,7 @@ - - - - - - - - diff --git a/src/Microsoft.Azure.WebJobs.Host/WebSitesKnownKeyNames.cs b/src/Microsoft.Azure.WebJobs.Host/WebSitesKnownKeyNames.cs index 373f55c7..93592952 100644 --- a/src/Microsoft.Azure.WebJobs.Host/WebSitesKnownKeyNames.cs +++ b/src/Microsoft.Azure.WebJobs.Host/WebSitesKnownKeyNames.cs @@ -6,7 +6,5 @@ namespace Microsoft.Azure.WebJobs.Host internal static class WebSitesKnownKeyNames { public const string JobDataPath = "WEBJOBS_DATA_PATH"; - - public const string WebSiteInstanceIdKey = "WEBSITE_INSTANCE_ID"; } } diff --git a/src/Microsoft.Azure.WebJobs.Host/packages.config b/src/Microsoft.Azure.WebJobs.Host/packages.config index 04e1dfb2..38c123f9 100644 --- a/src/Microsoft.Azure.WebJobs.Host/packages.config +++ b/src/Microsoft.Azure.WebJobs.Host/packages.config @@ -1,11 +1,5 @@  - - - - - - diff --git a/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights.NuGet/WebJobs.Logging.ApplicationInsights.nuproj b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights.NuGet/WebJobs.Logging.ApplicationInsights.nuproj new file mode 100644 index 00000000..3591bb78 --- /dev/null +++ b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights.NuGet/WebJobs.Logging.ApplicationInsights.nuproj @@ -0,0 +1,31 @@ + + + + + $(MSBuildProjectName).nuspec + Microsoft.Azure.WebJobs.Logging.ApplicationInsights + $(WebJobsPackageVersion) + false + + + + {D3FF0FDE-EBDF-4751-8131-3375CF2A5C21} + WebJobs.Logging.ApplicationInsights + + + + + lib\net45\Microsoft.Azure.WebJobs.Logging.ApplicationInsights.dll + + + lib\net45\Microsoft.Azure.WebJobs.Logging.ApplicationInsights.xml + + + + + + + NuGetPackageId=$(NuGetPackageId);NuGetPackageVersion=$(NuGetPackageVersion);PackageEULA=$(WebJobsPackageEULA);WebJobsPackageVersion=$(WebJobsPackageVersion) + + + \ No newline at end of file diff --git a/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights.NuGet/WebJobs.Logging.ApplicationInsights.nuspec b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights.NuGet/WebJobs.Logging.ApplicationInsights.nuspec new file mode 100644 index 00000000..78e0eb34 --- /dev/null +++ b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights.NuGet/WebJobs.Logging.ApplicationInsights.nuspec @@ -0,0 +1,21 @@ + + + + $NuGetPackageId$ + Microsoft.Azure.WebJobs.Logging.ApplicationInsights + $NuGetPackageVersion$ + Microsoft + © Microsoft Corporation. All rights reserved. + Microsoft.Azure.WebJobs.Logging.ApplicationInsights is a library for writing WebJobs logs with ILogger and Application Insights. + This package contains the runtime assemblies for Microsoft.Azure.WebJobs.Logging.ApplicationInsights. For more information, please visit http://go.microsoft.com/fwlink/?LinkID=320971 + en-US + http://go.microsoft.com/fwlink/?LinkID=320972 + $PackageEULA$ + true + Microsoft Azure WebJobs Jobs Logging Application Insights windowsazureofficial Web + + + + + + \ No newline at end of file diff --git a/src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/ApplicationInsights/ApplicationInsightsLogger.cs b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/ApplicationInsightsLogger.cs similarity index 97% rename from src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/ApplicationInsights/ApplicationInsightsLogger.cs rename to src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/ApplicationInsightsLogger.cs index fcd60ed5..a212044c 100644 --- a/src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/ApplicationInsights/ApplicationInsightsLogger.cs +++ b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/ApplicationInsightsLogger.cs @@ -201,7 +201,7 @@ namespace Microsoft.Azure.WebJobs.Host.Loggers // Functions attaches the HttpRequest, which allows us to log richer request details. object request; - if (scopeProps.TryGetValue(ScopeKeys.HttpRequest, out request)) + if (scopeProps.TryGetValue(ApplicationInsightsScopeKeys.HttpRequest, out request)) { ApplyHttpRequestProperties(requestTelemetry, request as HttpRequestMessage); } @@ -310,7 +310,7 @@ namespace Microsoft.Azure.WebJobs.Host.Loggers { // first check for X-Forwarded-For; used by load balancers IEnumerable headers; - if (httpRequest.Headers.TryGetValues(ScopeKeys.ForwardedForHeaderName, out headers)) + if (httpRequest.Headers.TryGetValues(ApplicationInsightsScopeKeys.ForwardedForHeaderName, out headers)) { string ip = headers.FirstOrDefault(); if (!string.IsNullOrWhiteSpace(ip)) @@ -319,7 +319,7 @@ namespace Microsoft.Azure.WebJobs.Host.Loggers } } - HttpContextBase context = httpRequest.Properties.GetValueOrDefault(ScopeKeys.HttpContext); + HttpContextBase context = httpRequest.Properties.GetValueOrDefault(ApplicationInsightsScopeKeys.HttpContext); return context?.Request?.UserHostAddress ?? LoggingConstants.ZeroIpAddress; } @@ -339,7 +339,7 @@ namespace Microsoft.Azure.WebJobs.Host.Loggers internal static HttpResponseMessage GetResponse(HttpRequestMessage httpRequest) { // Grab the response stored by functions - return httpRequest.Properties.GetValueOrDefault(ScopeKeys.FunctionsHttpResponse); + return httpRequest.Properties.GetValueOrDefault(ApplicationInsightsScopeKeys.FunctionsHttpResponse); } } } diff --git a/src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/ApplicationInsights/ApplicationInsightsLoggerExtensions.cs b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/ApplicationInsightsLoggerExtensions.cs similarity index 99% rename from src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/ApplicationInsights/ApplicationInsightsLoggerExtensions.cs rename to src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/ApplicationInsightsLoggerExtensions.cs index 7f364345..c1c1c7fa 100644 --- a/src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/ApplicationInsights/ApplicationInsightsLoggerExtensions.cs +++ b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/ApplicationInsightsLoggerExtensions.cs @@ -11,7 +11,6 @@ namespace Microsoft.Extensions.Logging /// /// Extensions for adding the to an . /// - [CLSCompliant(false)] public static class ApplicationInsightsLoggerExtensions { /// diff --git a/src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/ApplicationInsights/ApplicationInsightsLoggerProvider.cs b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/ApplicationInsightsLoggerProvider.cs similarity index 100% rename from src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/ApplicationInsights/ApplicationInsightsLoggerProvider.cs rename to src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/ApplicationInsightsLoggerProvider.cs diff --git a/src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/ApplicationInsights/ApplicationInsightsScope.cs b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/ApplicationInsightsScope.cs similarity index 100% rename from src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/ApplicationInsights/ApplicationInsightsScope.cs rename to src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/ApplicationInsightsScope.cs diff --git a/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/Constants/ApplicationInsightsScopeKeys.cs b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/Constants/ApplicationInsightsScopeKeys.cs new file mode 100644 index 00000000..733682f6 --- /dev/null +++ b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/Constants/ApplicationInsightsScopeKeys.cs @@ -0,0 +1,18 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +namespace Microsoft.Azure.WebJobs.Host.Loggers +{ + internal static class ApplicationInsightsScopeKeys + { + internal const string HttpRequest = "MS_HttpRequest"; + + // HTTP context is set automatically by ASP.NET, this isn't ours. + internal const string HttpContext = "MS_HttpContext"; + + // This is set by Functions + internal const string FunctionsHttpResponse = "MS_AzureFunctionsHttpResponse"; + + internal const string ForwardedForHeaderName = "X-Forwarded-For"; + } +} diff --git a/src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/Constants/LoggingConstants.cs b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/Constants/LoggingConstants.cs similarity index 100% rename from src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/Constants/LoggingConstants.cs rename to src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/Constants/LoggingConstants.cs diff --git a/src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/ApplicationInsights/DefaultTelemetryClientFactory.cs b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/DefaultTelemetryClientFactory.cs similarity index 98% rename from src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/ApplicationInsights/DefaultTelemetryClientFactory.cs rename to src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/DefaultTelemetryClientFactory.cs index 003d2eec..a54f16a8 100644 --- a/src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/ApplicationInsights/DefaultTelemetryClientFactory.cs +++ b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/DefaultTelemetryClientFactory.cs @@ -18,7 +18,6 @@ namespace Microsoft.Azure.WebJobs.Host.Loggers /// /// Creates a for use by the . /// - [CLSCompliant(false)] public class DefaultTelemetryClientFactory : ITelemetryClientFactory { private readonly string _instrumentationKey; @@ -64,8 +63,10 @@ namespace Microsoft.Azure.WebJobs.Host.Loggers internal TelemetryConfiguration InitializeConfiguration() { - TelemetryConfiguration config = new TelemetryConfiguration(); - config.InstrumentationKey = _instrumentationKey; + TelemetryConfiguration config = new TelemetryConfiguration() + { + InstrumentationKey = _instrumentationKey + }; AddInitializers(config); diff --git a/src/Microsoft.Azure.WebJobs.Host/Extensions/DictionaryExtensions.cs b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/Extensions/DictionaryExtensions.cs similarity index 100% rename from src/Microsoft.Azure.WebJobs.Host/Extensions/DictionaryExtensions.cs rename to src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/Extensions/DictionaryExtensions.cs diff --git a/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/GlobalSuppressions.cs b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/GlobalSuppressions.cs new file mode 100644 index 00000000..06793217 Binary files /dev/null and b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/GlobalSuppressions.cs differ diff --git a/src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/ApplicationInsights/ITelemetryClientFactory.cs b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/ITelemetryClientFactory.cs similarity index 96% rename from src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/ApplicationInsights/ITelemetryClientFactory.cs rename to src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/ITelemetryClientFactory.cs index f0067630..fba3ccaf 100644 --- a/src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/ApplicationInsights/ITelemetryClientFactory.cs +++ b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/ITelemetryClientFactory.cs @@ -9,7 +9,6 @@ namespace Microsoft.Azure.WebJobs.Host.Loggers /// /// Interface for creating instances. /// - [CLSCompliant(false)] public interface ITelemetryClientFactory : IDisposable { /// diff --git a/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/Properties/AssemblyInfo.cs b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..4d049eef --- /dev/null +++ b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/Properties/AssemblyInfo.cs @@ -0,0 +1,31 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] +[assembly: CLSCompliant(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("d3ff0fde-ebdf-4751-8131-3375cf2a5c21")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("2.0.0.0")] +[assembly: AssemblyFileVersion("2.0.0.0")] + +[assembly: InternalsVisibleTo("Microsoft.Azure.WebJobs.Host.UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] \ No newline at end of file diff --git a/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/WebJobs.Logging.ApplicationInsights.csproj b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/WebJobs.Logging.ApplicationInsights.csproj new file mode 100644 index 00000000..31ab648d --- /dev/null +++ b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/WebJobs.Logging.ApplicationInsights.csproj @@ -0,0 +1,171 @@ + + + + + Debug + AnyCPU + {D3FF0FDE-EBDF-4751-8131-3375CF2A5C21} + Library + Properties + Microsoft.Azure.WebJobs.Logging.ApplicationInsights + Microsoft.Azure.WebJobs.Logging.ApplicationInsights + v4.6 + 512 + + + + true + ..\src.ruleset + true + false + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + bin\Debug\Microsoft.Azure.WebJobs.Logging.ApplicationInsights.xml + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + bin\Release\Microsoft.Azure.WebJobs.Logging.ApplicationInsights.xml + + + true + + + ..\Common\PublicKey.snk + + + true + + + + ..\..\packages\Microsoft.ApplicationInsights.Agent.Intercept.2.0.7\lib\net45\Microsoft.AI.Agent.Intercept.dll + + + ..\..\packages\Microsoft.ApplicationInsights.DependencyCollector.2.3.0\lib\net45\Microsoft.AI.DependencyCollector.dll + + + ..\..\packages\Microsoft.ApplicationInsights.PerfCounterCollector.2.3.0\lib\net45\Microsoft.AI.PerfCounterCollector.dll + + + ..\..\packages\Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.2.3.0\lib\net45\Microsoft.AI.ServerTelemetryChannel.dll + + + ..\..\packages\Microsoft.ApplicationInsights.WindowsServer.2.3.0\lib\net45\Microsoft.AI.WindowsServer.dll + + + ..\..\packages\Microsoft.ApplicationInsights.2.3.0\lib\net46\Microsoft.ApplicationInsights.dll + + + ..\..\packages\Microsoft.Extensions.Logging.Abstractions.1.1.1\lib\netstandard1.1\Microsoft.Extensions.Logging.Abstractions.dll + + + ..\..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll + + + + ..\..\packages\System.AppContext.4.3.0\lib\net46\System.AppContext.dll + + + + ..\..\packages\System.Console.4.3.0\lib\net46\System.Console.dll + + + + ..\..\packages\System.Diagnostics.DiagnosticSource.4.3.0\lib\net46\System.Diagnostics.DiagnosticSource.dll + + + ..\..\packages\System.Globalization.Calendars.4.3.0\lib\net46\System.Globalization.Calendars.dll + + + ..\..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll + + + + ..\..\packages\System.IO.Compression.ZipFile.4.3.0\lib\net46\System.IO.Compression.ZipFile.dll + + + ..\..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll + + + ..\..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll + + + ..\..\packages\System.Net.Http.4.3.0\lib\net46\System.Net.Http.dll + True + + + ..\..\packages\System.Net.Sockets.4.3.0\lib\net46\System.Net.Sockets.dll + + + + ..\..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + + + ..\..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net46\System.Security.Cryptography.Algorithms.dll + + + ..\..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll + + + ..\..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll + + + ..\..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net46\System.Security.Cryptography.X509Certificates.dll + + + + + + + + + ..\..\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll + + + + + + + + + + + + + + + + + + + Properties\PublicKey.snk + + + + + + + {0e095cb2-3030-49ff-966c-785f1a55f0c1} + WebJobs.Host + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + \ No newline at end of file diff --git a/src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/ApplicationInsights/WebJobsTelemetryInitializer.cs b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/WebJobsTelemetryInitializer.cs similarity index 95% rename from src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/ApplicationInsights/WebJobsTelemetryInitializer.cs rename to src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/WebJobsTelemetryInitializer.cs index 033adcbc..1186eeea 100644 --- a/src/Microsoft.Azure.WebJobs.Host/Loggers/Logger/ApplicationInsights/WebJobsTelemetryInitializer.cs +++ b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/WebJobsTelemetryInitializer.cs @@ -12,6 +12,7 @@ namespace Microsoft.Azure.WebJobs.Host.Loggers internal class WebJobsTelemetryInitializer : ITelemetryInitializer { private const string ComputerNameKey = "COMPUTERNAME"; + private const string WebSiteInstanceIdKey = "WEBSITE_INSTANCE_ID"; private static string _roleInstanceName = GetRoleInstanceName(); @@ -44,7 +45,7 @@ namespace Microsoft.Azure.WebJobs.Host.Loggers private static string GetRoleInstanceName() { - string instanceName = Environment.GetEnvironmentVariable(WebSitesKnownKeyNames.WebSiteInstanceIdKey); + string instanceName = Environment.GetEnvironmentVariable(WebSiteInstanceIdKey); if (string.IsNullOrEmpty(instanceName)) { instanceName = Environment.GetEnvironmentVariable(ComputerNameKey); diff --git a/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/app.config b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/app.config new file mode 100644 index 00000000..fe9787e2 --- /dev/null +++ b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/app.config @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/packages.config b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/packages.config new file mode 100644 index 00000000..d377c8af --- /dev/null +++ b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/packages.config @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Microsoft.Azure.WebJobs.NuGet/WebJobs.nuspec b/src/Microsoft.Azure.WebJobs.NuGet/WebJobs.nuspec index 4117acdd..20a76307 100644 --- a/src/Microsoft.Azure.WebJobs.NuGet/WebJobs.nuspec +++ b/src/Microsoft.Azure.WebJobs.NuGet/WebJobs.nuspec @@ -18,7 +18,6 @@ - \ No newline at end of file diff --git a/src/Packages/Packages.csproj b/src/Packages/Packages.csproj index fd5b4544..22c22988 100644 --- a/src/Packages/Packages.csproj +++ b/src/Packages/Packages.csproj @@ -35,18 +35,24 @@ NuGetProj.settings.targets + + WebJobs.Logging.ApplicationInsights\WebJobs.Logging.ApplicationInsights.nuproj + + + WebJobs.Logging.ApplicationInsights\WebJobs.Logging.ApplicationInsights.nuspec + WebJobs.ServiceBus\WebJobs.ServiceBus.nuproj WebJobs.ServiceBus\WebJobs.ServiceBus.nuspec - + WebJobs.Logging\WebJobs.Logging.nuproj WebJobs.Logging\WebJobs.Logging.nuspec - + diff --git a/test/Microsoft.Azure.WebJobs.Host.UnitTests/Loggers/ApplicationInsightsLoggerTests.cs b/test/Microsoft.Azure.WebJobs.Host.UnitTests/Loggers/ApplicationInsightsLoggerTests.cs index e17a0a73..db4356bc 100644 --- a/test/Microsoft.Azure.WebJobs.Host.UnitTests/Loggers/ApplicationInsightsLoggerTests.cs +++ b/test/Microsoft.Azure.WebJobs.Host.UnitTests/Loggers/ApplicationInsightsLoggerTests.cs @@ -134,7 +134,7 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Loggers Assert.Equal(116, metricDict[$"{_functionFullName} {LoggingKeys.Successes}"]); Assert.Equal(200, metricDict[$"{_functionFullName} {LoggingKeys.MinDuration}"]); Assert.Equal(2180, metricDict[$"{_functionFullName} {LoggingKeys.MaxDuration}"]); - Assert.Equal(340, metricDict[$"{_functionFullName} {LoggingKeys.AvgDuration}"]); + Assert.Equal(340, metricDict[$"{_functionFullName} {LoggingKeys.AverageDuration}"]); Assert.Equal(96.67, metricDict[$"{_functionFullName} {LoggingKeys.SuccessRate}"]); Assert.Equal(120, metricDict[$"{_functionFullName} {LoggingKeys.Count}"]); } @@ -150,13 +150,13 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Loggers var request = new HttpRequestMessage(HttpMethod.Post, "http://someuri/api/path"); request.Headers.Add("User-Agent", "my custom user agent"); var response = new HttpResponseMessage(); - request.Properties[ScopeKeys.FunctionsHttpResponse] = response; + request.Properties[ApplicationInsightsScopeKeys.FunctionsHttpResponse] = response; MockIpAddress(request, "1.2.3.4"); ILogger logger = CreateLogger(LogCategories.Results); var scopeProps = CreateScopeDictionary(_invocationId, _functionShortName); - scopeProps[ScopeKeys.HttpRequest] = request; + scopeProps[ApplicationInsightsScopeKeys.HttpRequest] = request; using (logger.BeginScope(scopeProps)) { @@ -194,7 +194,7 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Loggers ILogger logger = CreateLogger(LogCategories.Results); var scopeProps = CreateScopeDictionary(_invocationId, _functionShortName); - scopeProps[ScopeKeys.HttpRequest] = request; + scopeProps[ApplicationInsightsScopeKeys.HttpRequest] = request; using (logger.BeginScope(scopeProps)) { @@ -308,7 +308,7 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Loggers public void GetIpAddress_ChecksHeaderFirst(string headerIp) { HttpRequestMessage request = new HttpRequestMessage(); - request.Headers.Add(ScopeKeys.ForwardedForHeaderName, headerIp); + request.Headers.Add(ApplicationInsightsScopeKeys.ForwardedForHeaderName, headerIp); MockIpAddress(request, "5.6.7.8"); string ip = ApplicationInsightsLogger.GetIpAddress(request); @@ -419,7 +419,7 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Loggers Mock mockRequest = new Mock(MockBehavior.Strict); mockRequest.Setup(r => r.UserHostAddress).Returns(ipAddress); mockContext.Setup(c => c.Request).Returns(mockRequest.Object); - request.Properties[ScopeKeys.HttpContext] = mockContext.Object; + request.Properties[ApplicationInsightsScopeKeys.HttpContext] = mockContext.Object; } private ILogger CreateLogger(string category) diff --git a/test/Microsoft.Azure.WebJobs.Host.UnitTests/Loggers/LoggerExtensionsTests.cs b/test/Microsoft.Azure.WebJobs.Host.UnitTests/Loggers/LoggerExtensionsTests.cs index d8e6b35a..077041fa 100644 --- a/test/Microsoft.Azure.WebJobs.Host.UnitTests/Loggers/LoggerExtensionsTests.cs +++ b/test/Microsoft.Azure.WebJobs.Host.UnitTests/Loggers/LoggerExtensionsTests.cs @@ -106,7 +106,7 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Loggers Assert.Equal(116, payload[LoggingKeys.Successes]); Assert.Equal(TimeSpan.FromMilliseconds(200), (TimeSpan)payload[LoggingKeys.MinDuration]); Assert.Equal(TimeSpan.FromMilliseconds(2180), (TimeSpan)payload[LoggingKeys.MaxDuration]); - Assert.Equal(TimeSpan.FromMilliseconds(340), (TimeSpan)payload[LoggingKeys.AvgDuration]); + Assert.Equal(TimeSpan.FromMilliseconds(340), (TimeSpan)payload[LoggingKeys.AverageDuration]); Assert.Equal(now, payload[LoggingKeys.Timestamp]); Assert.Equal(120, payload[LoggingKeys.Count]); Assert.Equal(96.67, payload[LoggingKeys.SuccessRate]); diff --git a/test/Microsoft.Azure.WebJobs.Host.UnitTests/PublicSurfaceTests.cs b/test/Microsoft.Azure.WebJobs.Host.UnitTests/PublicSurfaceTests.cs index 9b41d585..189afe39 100644 --- a/test/Microsoft.Azure.WebJobs.Host.UnitTests/PublicSurfaceTests.cs +++ b/test/Microsoft.Azure.WebJobs.Host.UnitTests/PublicSurfaceTests.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Reflection; +using Microsoft.Azure.WebJobs.Host.Loggers; using Microsoft.Azure.WebJobs.Logging; using Xunit; @@ -228,11 +229,25 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests "FunctionListenerException", "ExceptionFormatter", "FunctionResultAggregatorConfiguration", - "ApplicationInsightsLoggerExtensions", "LogCategoryFilter", "LogCategories", + "LoggingKeys", + "ScopeKeys" + }; + + AssertPublicTypes(expected, assembly); + } + + [Fact] + public void ApplicationInsightsPublicSurface_LimitedToSpecificTypes() + { + var assembly = typeof(ApplicationInsightsLogger).Assembly; + + var expected = new[] + { "ITelemetryClientFactory", - "DefaultTelemetryClientFactory" + "DefaultTelemetryClientFactory", + "ApplicationInsightsLoggerExtensions" }; AssertPublicTypes(expected, assembly); diff --git a/test/Microsoft.Azure.WebJobs.Host.UnitTests/WebJobs.Host.UnitTests.csproj b/test/Microsoft.Azure.WebJobs.Host.UnitTests/WebJobs.Host.UnitTests.csproj index f6f24583..39ce1d63 100644 --- a/test/Microsoft.Azure.WebJobs.Host.UnitTests/WebJobs.Host.UnitTests.csproj +++ b/test/Microsoft.Azure.WebJobs.Host.UnitTests/WebJobs.Host.UnitTests.csproj @@ -378,6 +378,10 @@ + + {d3ff0fde-ebdf-4751-8131-3375cf2a5c21} + WebJobs.Logging.ApplicationInsights + {b5a04006-ab0c-4800-ae4c-080d31867de3} WebJobs.Logging diff --git a/tools/SkipStrongNames.xml b/tools/SkipStrongNames.xml index 98236936..1c5029b9 100644 --- a/tools/SkipStrongNames.xml +++ b/tools/SkipStrongNames.xml @@ -8,6 +8,7 @@ +