12
12
using System . Threading . Tasks ;
13
13
using Microsoft . Azure . WebJobs . Host ;
14
14
using Microsoft . Azure . WebJobs . Script . Binding ;
15
+ using Microsoft . Azure . WebJobs . Script . Diagnostics ;
15
16
16
17
namespace Microsoft . Azure . WebJobs . Script . Description
17
18
{
@@ -23,6 +24,8 @@ public class ScriptFunctionInvoker : ScriptFunctionInvokerBase
23
24
private static string [ ] _supportedScriptTypes = new string [ ] { "ps1" , "cmd" , "bat" , "py" , "php" , "sh" , "fsx" } ;
24
25
private readonly string _scriptFilePath ;
25
26
private readonly string _scriptType ;
27
+ private readonly IMetricsLogger _metrics ;
28
+
26
29
private readonly Collection < FunctionBinding > _inputBindings ;
27
30
private readonly Collection < FunctionBinding > _outputBindings ;
28
31
@@ -33,6 +36,7 @@ internal ScriptFunctionInvoker(string scriptFilePath, ScriptHost host, FunctionM
33
36
_scriptType = Path . GetExtension ( _scriptFilePath ) . ToLower ( CultureInfo . InvariantCulture ) . TrimStart ( '.' ) ;
34
37
_inputBindings = inputBindings ;
35
38
_outputBindings = outputBindings ;
39
+ _metrics = host . ScriptConfig . HostConfig . GetService < IMetricsLogger > ( ) ;
36
40
}
37
41
38
42
public static bool IsSupportedScriptType ( string extension )
@@ -87,6 +91,9 @@ internal async Task ExecuteScriptAsync(string path, string arguments, object[] i
87
91
IBinder binder = ( IBinder ) invocationParameters [ 2 ] ;
88
92
ExecutionContext functionExecutionContext = ( ExecutionContext ) invocationParameters [ 3 ] ;
89
93
94
+ FunctionStartedEvent startedEvent = new FunctionStartedEvent ( Metadata ) ;
95
+ _metrics . BeginEvent ( startedEvent ) ;
96
+
90
97
// perform any required input conversions
91
98
string stdin = null ;
92
99
if ( input != null )
@@ -131,8 +138,14 @@ internal async Task ExecuteScriptAsync(string path, string arguments, object[] i
131
138
}
132
139
process . WaitForExit ( ) ;
133
140
134
- if ( process . ExitCode != 0 )
141
+ bool failed = process . ExitCode != 0 ;
142
+ startedEvent . Success = ! failed ;
143
+ _metrics . EndEvent ( startedEvent ) ;
144
+
145
+ if ( failed )
135
146
{
147
+ startedEvent . Success = false ;
148
+
136
149
string error = process . StandardError . ReadToEnd ( ) ;
137
150
TraceWriter . Error ( error ) ;
138
151
TraceWriter . Verbose ( string . Format ( "Function completed (Failure)" ) ) ;
0 commit comments