// this is not thread safe. ATM it is called from the same thread as the webserver so it should be fine public bool UpdateClusterId(string clusterId) { bool sent = false; // we don't want to throw here, just log. thus in case of empty cluster id in the message message we don't want to throw, but we will log it try { if (String.IsNullOrEmpty(clusterId)) { throw new ArgumentNullException("clusterId"); } if (heartbeatModule != null) { try { heartbeatModule.AddHeartbeatProperty("clusterID", clusterId, true); } catch (Exception) { // we already added it before , thus updating the value of the field heartbeatModule.SetHeartbeatProperty("clusterID", clusterId); } Diagnostics.LogInfo(FormattableString.Invariant($"sent update with cluesterid: {clusterId}")); sent = true; } else { Diagnostics.LogInfo(FormattableString.Invariant($"unable to send clusterId, no telemetry module detected")); } } catch (Exception e) { // unexpected exception occured Diagnostics.LogError(FormattableString.Invariant($"Unknown exception while pushing event . {e.ToString()}")); } return(sent); }
private bool AddAppServiceEnvironmentVariablesToHeartbeat(IHeartbeatPropertyManager hbeatManager, bool isUpdateOperation = false) { bool hasBeenUpdated = false; if (hbeatManager == null) { WindowsServerEventSource.Log.AppServiceHeartbeatSetCalledWithNullManager(); } else { foreach (var kvp in this.WebHeartbeatPropertyNameEnvVarMap) { try { string hbeatKey = kvp.Key.ToString(); string hbeatValue = string.Empty; AppServiceEnvironmentVariableMonitor.Instance.GetCurrentEnvironmentVariableValue(kvp.Value, ref hbeatValue); if (isUpdateOperation) { hbeatManager.SetHeartbeatProperty(hbeatKey, hbeatValue); } else { hbeatManager.AddHeartbeatProperty(hbeatKey, hbeatValue, true); } hasBeenUpdated = true; } catch (Exception heartbeatValueException) { WindowsServerEventSource.Log.AppServiceHeartbeatPropertyAquisitionFailed(kvp.Value, heartbeatValueException.ToInvariantString()); } } } return(hasBeenUpdated); }