/// <summary> /// Add all enabled, present Azure IMS fields to the heartbeat properties. /// </summary> /// <param name="provider">Heartbeat provider to set the properties on.</param> /// <returns>True if any property values were successfully set, false if none were set.</returns> public async Task <bool> SetDefaultPayloadAsync(IHeartbeatPropertyManager provider) { bool hasSetFields = false; try { if (!this.isAzureMetadataCheckCompleted) { this.isAzureMetadataCheckCompleted = true; var azureComputeMetadata = await this.azureInstanceMetadataRequestor.GetAzureComputeMetadataAsync() .ConfigureAwait(false); if (azureComputeMetadata != null) { var enabledImdsFields = this.ExpectedAzureImsFields.Except(provider.ExcludedHeartbeatProperties); foreach (string field in enabledImdsFields) { string verifiedValue = azureComputeMetadata.VerifyExpectedValue(field); bool addedProperty = provider.AddHeartbeatProperty( propertyName: string.Concat(AzureComputeMetadataHeartbeatPropertyProvider.HeartbeatPropertyPrefix, field), propertyValue: verifiedValue, isHealthy: true); if (!addedProperty) { WindowsServerEventSource.Log.AzureInstanceMetadataWasntAddedToHeartbeatProperties(field, verifiedValue); } hasSetFields = hasSetFields || addedProperty; } } else { WindowsServerEventSource.Log.AzureInstanceMetadataNotAdded(); } } } catch (Exception setPayloadException) { WindowsServerEventSource.Log.AzureInstanceMetadataFailureSettingDefaultPayload(setPayloadException.Message, setPayloadException.InnerException?.Message); } return(hasSetFields); }
// 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); }