1212using System . Threading . Tasks ;
1313using Microsoft . Azure . WebJobs . Host ;
1414using Microsoft . Azure . WebJobs . Script . Binding ;
15+ using Microsoft . Azure . WebJobs . Script . Diagnostics ;
1516
1617namespace Microsoft . Azure . WebJobs . Script . Description
1718{
@@ -23,6 +24,8 @@ public class ScriptFunctionInvoker : ScriptFunctionInvokerBase
2324 private static string [ ] _supportedScriptTypes = new string [ ] { "ps1" , "cmd" , "bat" , "py" , "php" , "sh" , "fsx" } ;
2425 private readonly string _scriptFilePath ;
2526 private readonly string _scriptType ;
27+ private readonly IMetricsLogger _metrics ;
28+
2629 private readonly Collection < FunctionBinding > _inputBindings ;
2730 private readonly Collection < FunctionBinding > _outputBindings ;
2831
@@ -33,6 +36,7 @@ internal ScriptFunctionInvoker(string scriptFilePath, ScriptHost host, FunctionM
3336 _scriptType = Path . GetExtension ( _scriptFilePath ) . ToLower ( CultureInfo . InvariantCulture ) . TrimStart ( '.' ) ;
3437 _inputBindings = inputBindings ;
3538 _outputBindings = outputBindings ;
39+ _metrics = host . ScriptConfig . HostConfig . GetService < IMetricsLogger > ( ) ;
3640 }
3741
3842 public static bool IsSupportedScriptType ( string extension )
@@ -87,6 +91,9 @@ internal async Task ExecuteScriptAsync(string path, string arguments, object[] i
8791 IBinder binder = ( IBinder ) invocationParameters [ 2 ] ;
8892 ExecutionContext functionExecutionContext = ( ExecutionContext ) invocationParameters [ 3 ] ;
8993
94+ FunctionStartedEvent startedEvent = new FunctionStartedEvent ( Metadata ) ;
95+ _metrics . BeginEvent ( startedEvent ) ;
96+
9097 // perform any required input conversions
9198 string stdin = null ;
9299 if ( input != null )
@@ -131,8 +138,14 @@ internal async Task ExecuteScriptAsync(string path, string arguments, object[] i
131138 }
132139 process . WaitForExit ( ) ;
133140
134- if ( process . ExitCode != 0 )
141+ bool failed = process . ExitCode != 0 ;
142+ startedEvent . Success = ! failed ;
143+ _metrics . EndEvent ( startedEvent ) ;
144+
145+ if ( failed )
135146 {
147+ startedEvent . Success = false ;
148+
136149 string error = process . StandardError . ReadToEnd ( ) ;
137150 TraceWriter . Error ( error ) ;
138151 TraceWriter . Verbose ( string . Format ( "Function completed (Failure)" ) ) ;
0 commit comments