|
2 | 2 | // Licensed under the MIT License. See License.txt in the project root for license information.
|
3 | 3 |
|
4 | 4 | using System;
|
| 5 | +using System.Collections.Generic; |
| 6 | +using System.Linq; |
5 | 7 | using System.Threading;
|
6 | 8 | using System.Threading.Tasks;
|
7 |
| - |
| 9 | +using Microsoft.Azure.WebJobs.Script; |
| 10 | +using Microsoft.Azure.WebJobs.Script.Description; |
8 | 11 | using Microsoft.Diagnostics.Tracing;
|
9 | 12 |
|
10 | 13 | namespace WebJobs.Script.WebHost.Diagnostics
|
11 | 14 | {
|
12 | 15 | public static class MetricsEventManager
|
13 | 16 | {
|
14 | 17 | private static FunctionActivityTracker instance = null;
|
15 |
| - |
16 | 18 | private static object functionActivityTrackerLockObject = new object();
|
17 | 19 |
|
18 | 20 | public static void FunctionStarted()
|
@@ -43,6 +45,52 @@ public static void FunctionCompleted()
|
43 | 45 | }
|
44 | 46 | }
|
45 | 47 |
|
| 48 | + public static void HostStarted(ScriptHost scriptHost) |
| 49 | + { |
| 50 | + if (scriptHost == null || scriptHost.Functions == null) |
| 51 | + { |
| 52 | + return; |
| 53 | + } |
| 54 | + |
| 55 | + var siteName = GetNormalizedString(Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME")); |
| 56 | + foreach (var function in scriptHost.Functions) |
| 57 | + { |
| 58 | + if (function == null || function.Metadata == null) |
| 59 | + { |
| 60 | + continue; |
| 61 | + } |
| 62 | + |
| 63 | + MetricEventSource.Log.RaiseFunctionsInfoEvent( |
| 64 | + siteName, |
| 65 | + GetNormalizedString(function.Name), |
| 66 | + function.Metadata != null |
| 67 | + ? SerializeBindings(function.Metadata.InputBindings) |
| 68 | + : GetNormalizedString(null), |
| 69 | + function.Metadata != null |
| 70 | + ? SerializeBindings(function.Metadata.OutputBindings) |
| 71 | + : GetNormalizedString(null), |
| 72 | + function.Metadata.ScriptType.ToString(), |
| 73 | + function.Metadata != null ? function.Metadata.IsDisabled : false); |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + private static string SerializeBindings(IEnumerable<BindingMetadata> bindings) |
| 78 | + { |
| 79 | + if (bindings != null) |
| 80 | + { |
| 81 | + return string.Join(",", bindings.ToList().Select(b => b.Type.ToString())); |
| 82 | + } |
| 83 | + else |
| 84 | + { |
| 85 | + return GetNormalizedString(null); |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + private static string GetNormalizedString(string input) |
| 90 | + { |
| 91 | + return input ?? string.Empty; |
| 92 | + } |
| 93 | + |
46 | 94 | private class FunctionActivityTracker : IDisposable
|
47 | 95 | {
|
48 | 96 | private readonly string executionId = Guid.NewGuid().ToString();
|
@@ -132,19 +180,28 @@ private static void WriteFunctionsMetricEvent(string executionId, ulong executio
|
132 | 180 | {
|
133 | 181 | MetricEventSource.Log.RaiseFunctionsMetricEvent(executionId, executionTimeSpan, executionCount, executionStage);
|
134 | 182 | }
|
| 183 | + } |
135 | 184 |
|
136 |
| - [EventSource(Guid = "08D0D743-5C24-43F9-9723-98277CEA5F9B")] |
137 |
| - private sealed class MetricEventSource : EventSource |
| 185 | + [EventSource(Guid = "08D0D743-5C24-43F9-9723-98277CEA5F9B")] |
| 186 | + private sealed class MetricEventSource : EventSource |
| 187 | + { |
| 188 | + internal static readonly MetricEventSource Log = new MetricEventSource(); |
| 189 | + |
| 190 | + [Event(57906, Level = EventLevel.Informational, Channel = EventChannel.Operational)] |
| 191 | + public void RaiseFunctionsMetricEvent(string executionId, ulong executionTimeSpan, ulong executionCount, string executionStage) |
138 | 192 | {
|
139 |
| - internal static readonly MetricEventSource Log = new MetricEventSource(); |
| 193 | + if (IsEnabled()) |
| 194 | + { |
| 195 | + WriteEvent(57906, executionId, executionTimeSpan, executionCount, executionStage); |
| 196 | + } |
| 197 | + } |
140 | 198 |
|
141 |
| - [Event(57906, Level = EventLevel.Informational, Channel = EventChannel.Operational)] |
142 |
| - public void RaiseFunctionsMetricEvent(string executionId, ulong executionTimeSpan, ulong executionCount, string executionStage) |
| 199 | + [Event(57908, Level = EventLevel.Informational, Channel = EventChannel.Operational)] |
| 200 | + public void RaiseFunctionsInfoEvent(string siteName, string functionName, string inputBindings, string outputBindings, string scriptType, bool isDisabled) |
| 201 | + { |
| 202 | + if (IsEnabled()) |
143 | 203 | {
|
144 |
| - if (IsEnabled()) |
145 |
| - { |
146 |
| - WriteEvent(57906, executionId, executionTimeSpan, executionCount, executionStage); |
147 |
| - } |
| 204 | + WriteEvent(57908, siteName, functionName, inputBindings, outputBindings, scriptType, isDisabled); |
148 | 205 | }
|
149 | 206 | }
|
150 | 207 | }
|
|
0 commit comments