diff --git a/src/WebJobs.Script.WebHost/Diagnostics/WebHostMetricsLogger.cs b/src/WebJobs.Script.WebHost/Diagnostics/WebHostMetricsLogger.cs
new file mode 100644
index 0000000000..011aae9052
--- /dev/null
+++ b/src/WebJobs.Script.WebHost/Diagnostics/WebHostMetricsLogger.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 Microsoft.Azure.WebJobs.Script.Diagnostics;
+
+namespace WebJobs.Script.WebHost.Diagnostics
+{
+ public class WebHostMetricsLogger : IMetricsLogger
+ {
+ public void BeginEvent(MetricEvent metricEvent)
+ {
+ // TODO
+ FunctionStartedEvent startedEvent = metricEvent as FunctionStartedEvent;
+ if (startedEvent != null)
+ {
+ startedEvent.StartTime = DateTime.Now;
+ }
+ }
+
+ public void EndEvent(MetricEvent metricEvent)
+ {
+ // TODO
+ FunctionStartedEvent startedEvent = metricEvent as FunctionStartedEvent;
+ if (startedEvent != null)
+ {
+ startedEvent.EndTime = DateTime.Now;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/WebJobs.Script.WebHost/WebJobs.Script.WebHost.csproj b/src/WebJobs.Script.WebHost/WebJobs.Script.WebHost.csproj
index 3a6e11805b..69204244ce 100644
--- a/src/WebJobs.Script.WebHost/WebJobs.Script.WebHost.csproj
+++ b/src/WebJobs.Script.WebHost/WebJobs.Script.WebHost.csproj
@@ -237,6 +237,7 @@
+
diff --git a/src/WebJobs.Script.WebHost/WebScriptHostManager.cs b/src/WebJobs.Script.WebHost/WebScriptHostManager.cs
index 6926ee775d..a7e2886098 100644
--- a/src/WebJobs.Script.WebHost/WebScriptHostManager.cs
+++ b/src/WebJobs.Script.WebHost/WebScriptHostManager.cs
@@ -8,8 +8,11 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
+using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Script;
using Microsoft.Azure.WebJobs.Script.Description;
+using Microsoft.Azure.WebJobs.Script.Diagnostics;
+using WebJobs.Script.WebHost.Diagnostics;
namespace WebJobs.Script.WebHost
{
@@ -74,6 +77,14 @@ public FunctionDescriptor GetHttpFunctionOrNull(Uri uri)
return function;
}
+ protected override void OnInitializeConfig(JobHostConfiguration config)
+ {
+ base.OnInitializeConfig(config);
+
+ // Add our WebHost specific services
+ config.AddService(new WebHostMetricsLogger());
+ }
+
protected override void OnHostStarted()
{
base.OnHostStarted();
diff --git a/src/WebJobs.Script/Description/CSharp/CSharpFunctionInvoker.cs b/src/WebJobs.Script/Description/CSharp/CSharpFunctionInvoker.cs
index b3982c6939..5c9056e86d 100644
--- a/src/WebJobs.Script/Description/CSharp/CSharpFunctionInvoker.cs
+++ b/src/WebJobs.Script/Description/CSharp/CSharpFunctionInvoker.cs
@@ -13,6 +13,7 @@
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Azure.WebJobs.Script.Binding;
+using Microsoft.Azure.WebJobs.Script.Diagnostics;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Scripting;
@@ -31,6 +32,7 @@ public class CSharpFunctionInvoker : ScriptFunctionInvokerBase
private readonly Collection _inputBindings;
private readonly Collection _outputBindings;
private readonly IFunctionEntryPointResolver _functionEntryPointResolver;
+ private readonly IMetricsLogger _metrics;
private MethodInfo _function;
private CSharpFunctionSignature _functionSignature;
@@ -53,6 +55,7 @@ internal CSharpFunctionInvoker(ScriptHost host, FunctionMetadata functionMetadat
_inputBindings = inputBindings;
_outputBindings = outputBindings;
_triggerInputName = GetTriggerInputName(functionMetadata);
+ _metrics = host.ScriptConfig.HostConfig.GetService();
InitializeFileWatcherIfEnabled();
_resultProcessor = CreateResultProcessor();
@@ -150,6 +153,9 @@ private void RestorePackages()
public override async Task Invoke(object[] parameters)
{
+ FunctionStartedEvent startedEvent = new FunctionStartedEvent(Metadata);
+ _metrics.BeginEvent(startedEvent);
+
try
{
TraceWriter.Verbose("Function started");
@@ -175,9 +181,17 @@ public override async Task Invoke(object[] parameters)
catch (Exception ex)
{
TraceWriter.Error(ex.Message, ex is CompilationErrorException ? null : ex);
+
+ startedEvent.Success = false;
+ TraceWriter.Error(ex.Message, ex);
+
TraceWriter.Verbose("Function completed (Failure)");
throw;
}
+ finally
+ {
+ _metrics.EndEvent(startedEvent);
+ }
}
private object[] ProcessInputParameters(object[] parameters)
diff --git a/src/WebJobs.Script/Description/NodeFunctionInvoker.cs b/src/WebJobs.Script/Description/NodeFunctionInvoker.cs
index dea43b400c..d941d94868 100644
--- a/src/WebJobs.Script/Description/NodeFunctionInvoker.cs
+++ b/src/WebJobs.Script/Description/NodeFunctionInvoker.cs
@@ -16,6 +16,7 @@
using EdgeJs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Azure.WebJobs.Script.Binding;
+using Microsoft.Azure.WebJobs.Script.Diagnostics;
using Newtonsoft.Json;
namespace Microsoft.Azure.WebJobs.Script.Description
@@ -28,6 +29,7 @@ public class NodeFunctionInvoker : ScriptFunctionInvokerBase
private readonly string _script;
private readonly DictionaryJsonConverter _dictionaryJsonConverter = new DictionaryJsonConverter();
private readonly BindingMetadata _trigger;
+ private readonly IMetricsLogger _metrics;
private Func