Skip to content

Commit ae4478a

Browse files
committed
Still emit metrics even if there's no dashboard conneciton string
1 parent 23ca4f1 commit ae4478a

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/WebJobs.Script.WebHost/Diagnostics/FunctionInstanceLogger.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,23 @@ public FunctionInstanceLogger(
2828
Func<string, FunctionDescriptor> funcLookup,
2929
IMetricsLogger metrics,
3030
string hostName,
31-
string accountConnectionString,
31+
string accountConnectionString, // May be null
3232
TraceWriter trace) : this(funcLookup, metrics)
3333
{
3434
if (trace == null)
3535
{
3636
throw new ArgumentNullException(nameof(trace));
3737
}
3838

39-
CloudStorageAccount account = CloudStorageAccount.Parse(accountConnectionString);
40-
var client = account.CreateCloudTableClient();
41-
var tableProvider = LogFactory.NewLogTableProvider(client);
39+
if (accountConnectionString != null)
40+
{
41+
CloudStorageAccount account = CloudStorageAccount.Parse(accountConnectionString);
42+
var client = account.CreateCloudTableClient();
43+
var tableProvider = LogFactory.NewLogTableProvider(client);
4244

43-
string containerName = Environment.MachineName;
44-
this._writer = LogFactory.NewWriter(hostName, containerName, tableProvider, (e) => OnException(e, trace));
45+
string containerName = Environment.MachineName;
46+
this._writer = LogFactory.NewWriter(hostName, containerName, tableProvider, (e) => OnException(e, trace));
47+
}
4548
}
4649

4750
internal FunctionInstanceLogger(

src/WebJobs.Script.WebHost/WebScriptHostManager.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -441,14 +441,13 @@ protected override void OnInitializeConfig(ScriptHostConfiguration config)
441441

442442
// Register the new "FastLogger" for Dashboard support
443443
var dashboardString = AmbientConnectionStringProvider.Instance.GetConnectionString(ConnectionStringNames.Dashboard);
444-
if (dashboardString != null)
445-
{
446-
// hostId may be missing in local test scenarios.
447-
var hostId = config.HostConfig.HostId ?? "default";
448-
Func<string, FunctionDescriptor> funcLookup = (name) => this.Instance.GetFunctionOrNull(name);
449-
var instanceLogger = new FunctionInstanceLogger(funcLookup, _metricsLogger, hostId, dashboardString, config.TraceWriter);
450-
hostConfig.AddService<IAsyncCollector<FunctionInstanceLogEntry>>(instanceLogger);
451-
}
444+
445+
// hostId may be missing in local test scenarios.
446+
var hostId = config.HostConfig.HostId ?? "default";
447+
Func<string, FunctionDescriptor> funcLookup = (name) => this.Instance.GetFunctionOrNull(name);
448+
var instanceLogger = new FunctionInstanceLogger(funcLookup, _metricsLogger, hostId, dashboardString, config.TraceWriter);
449+
hostConfig.AddService<IAsyncCollector<FunctionInstanceLogEntry>>(instanceLogger);
450+
452451
hostConfig.DashboardConnectionString = null; // disable slow logging
453452
}
454453

0 commit comments

Comments
 (0)