/// <summary> /// Send module load telemetry as a metric. /// For modules we send the module name (if allowed), and the version. /// Some modules (CIM) will continue use the string alternative method. /// </summary> /// <param name="telemetryType">The type of telemetry that we'll be sending.</param> /// <param name="moduleName">The module name to report. If it is not allowed, then it is set to 'anonymous'.</param> /// <param name="moduleVersion">The module version to report. The default value is the anonymous version '0.0.0.0'.</param> internal static void SendModuleTelemetryMetric(TelemetryType telemetryType, string moduleName, string moduleVersion = AnonymousVersion) { try { string allowedModuleName = GetModuleName(moduleName); string allowedModuleVersion = allowedModuleName == Anonymous ? AnonymousVersion : moduleVersion; s_telemetryClient.GetMetric(telemetryType.ToString(), "uuid", "SessionId", "ModuleName", "Version").TrackValue(metricValue: 1.0, s_uniqueUserIdentifier, s_sessionId, allowedModuleName, allowedModuleVersion); } catch { // Ignore errors. } }
/// <summary> /// Send telemetry as a metric. /// </summary> /// <param name="metricId">The type of telemetry that we'll be sending.</param> /// <param name="data">The specific details about the telemetry.</param> internal static void SendTelemetryMetric(TelemetryType metricId, string data) { if (!CanSendTelemetry) { return; } SendPSCoreStartupTelemetry("hosted"); string metricName = metricId.ToString(); try { switch (metricId) { case TelemetryType.ApplicationType: case TelemetryType.PowerShellCreate: case TelemetryType.RemoteSessionOpen: case TelemetryType.ExperimentalEngineFeatureActivation: s_telemetryClient.GetMetric(metricName, "uuid", "SessionId", "Detail").TrackValue(metricValue: 1.0, s_uniqueUserIdentifier, s_sessionId, data); break; case TelemetryType.ExperimentalModuleFeatureActivation: string experimentalFeatureName = GetExperimentalFeatureName(data); s_telemetryClient.GetMetric(metricName, "uuid", "SessionId", "Detail").TrackValue(metricValue: 1.0, s_uniqueUserIdentifier, s_sessionId, experimentalFeatureName); break; case TelemetryType.ModuleLoad: case TelemetryType.WinCompatModuleLoad: string moduleName = GetModuleName(data); // This will return anonymous if the modulename is not on the report list s_telemetryClient.GetMetric(metricName, "uuid", "SessionId", "Detail").TrackValue(metricValue: 1.0, s_uniqueUserIdentifier, s_sessionId, moduleName); break; } } catch { // do nothing, telemetry can't be sent // don't send the panic telemetry as if we have failed above, it will likely fail here. } }
/// <summary> /// Send telemetry as a metric. /// </summary> /// <param name="metricId">The type of telemetry that we'll be sending.</param> /// <param name="data">The specific details about the telemetry.</param> internal static void SendTelemetryMetric(TelemetryType metricId, string data) { if (!CanSendTelemetry) { return; } // These should be handled by SendModuleTelemetryMetric. Debug.Assert(metricId != TelemetryType.ModuleLoad, "ModuleLoad should be handled by SendModuleTelemetryMetric."); Debug.Assert(metricId != TelemetryType.WinCompatModuleLoad, "WinCompatModuleLoad should be handled by SendModuleTelemetryMetric."); string metricName = metricId.ToString(); try { switch (metricId) { case TelemetryType.ApplicationType: case TelemetryType.PowerShellCreate: case TelemetryType.RemoteSessionOpen: case TelemetryType.ExperimentalEngineFeatureActivation: s_telemetryClient.GetMetric(metricName, "uuid", "SessionId", "Detail").TrackValue(metricValue: 1.0, s_uniqueUserIdentifier, s_sessionId, data); break; case TelemetryType.ExperimentalModuleFeatureActivation: string experimentalFeatureName = GetExperimentalFeatureName(data); s_telemetryClient.GetMetric(metricName, "uuid", "SessionId", "Detail").TrackValue(metricValue: 1.0, s_uniqueUserIdentifier, s_sessionId, experimentalFeatureName); break; } } catch { // do nothing, telemetry can't be sent // don't send the panic telemetry as if we have failed above, it will likely fail here. } }