Skip to content

Commit 114c7a7

Browse files
committed
[V1 port] Record function pass/fail metrics. Fixes #3640
1 parent 1f88208 commit 114c7a7

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

src/WebJobs.Script/Description/FunctionInvokerBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ public void End(bool success)
259259
_logInfo.LogFunctionResult(success, _metadata.Name, _invocationId.ToString(), _invocationStopWatch.ElapsedMilliseconds);
260260

261261
startedEvent.Success = success;
262+
string eventName = success ? MetricEventNames.FunctionInvokeSucceeded : MetricEventNames.FunctionInvokeFailed;
263+
_metrics.LogEvent(eventName, startedEvent.FunctionName);
262264
_metrics.EndEvent(startedEvent);
263265

264266
if (invokeLatencyEvent != null)

src/WebJobs.Script/Diagnostics/MetricEventNames.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@ public static class MetricEventNames
2121
public const string FunctionBindingTypeDirectionFormat = "function.binding.{0}.{1}";
2222
public const string FunctionCompileLatencyByLanguageFormat = "function.compile.{0}.latency";
2323
public const string FunctionInvokeThrottled = "function.invoke.throttled";
24+
public const string FunctionInvokeSucceeded = "function.invoke.succeeded";
25+
public const string FunctionInvokeFailed = "function.invoke.failed";
2426
}
2527
}

test/WebJobs.Script.Tests/Description/FunctionInvokerBaseTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ public async Task Invoke_Success_EmitsExpectedEvents()
115115
var message = _traceWriter.GetTraces().Last().Message;
116116
Assert.True(Regex.IsMatch(message, $"Function completed \\(Success, Id={executionContext.InvocationId}, Duration=[0-9]*ms\\)"));
117117

118+
// verify invoke failed event
119+
Assert.False(string.IsNullOrEmpty(_metricsLogger.LoggedEvents.FirstOrDefault(e => e == MetricEventNames.FunctionInvokeSucceeded)));
120+
118121
// verify latency event
119122
var startLatencyEvent = _metricsLogger.EventsBegan[0];
120123
Assert.Equal($"{MetricEventNames.FunctionInvokeLatency}_testfunction", startLatencyEvent);
@@ -185,6 +188,9 @@ await Assert.ThrowsAsync<InvalidOperationException>(async () =>
185188
var message = _traceWriter.GetTraces().Last().Message;
186189
Assert.True(Regex.IsMatch(message, $"Function completed \\(Failure, Id={executionContext.InvocationId}, Duration=[0-9]*ms\\)"));
187190

191+
// verify invoke failed event
192+
Assert.False(string.IsNullOrEmpty(_metricsLogger.LoggedEvents.FirstOrDefault(e => e == MetricEventNames.FunctionInvokeFailed)));
193+
188194
// verify latency event
189195
var startLatencyEvent = _metricsLogger.EventsBegan[0];
190196
Assert.Equal($"{MetricEventNames.FunctionInvokeLatency}_testfunction", startLatencyEvent);

0 commit comments

Comments
 (0)