/// <summary> /// Start tracking operation by posting a <see cref="T:Coding4Fun.VisualStudio.Telemetry.OperationEvent" /> with specified properties at the begining of operation work, /// and return a <see cref="T:Coding4Fun.VisualStudio.Telemetry.TelemetryScope`1" /> object. /// When the user task finishes, call method <see cref="M:Coding4Fun.VisualStudio.Telemetry.TelemetryScope`1.End(Coding4Fun.VisualStudio.Telemetry.TelemetryResult,System.String)" /> to post another <see cref="T:Coding4Fun.VisualStudio.Telemetry.OperationEvent" /> for end point. /// Because the same event name is used by both start and end events, please don't use Start or End in event name. /// </summary> /// <param name="session">Telemetry Session</param> /// <param name="eventName"> /// An event name following data model schema. /// It requires that event name is a unique, not null or empty string. /// It consists of 3 parts and must follows pattern [product]/[featureName]/[entityName]. FeatureName could be a one-level feature or feature hierarchy delimited by "/". /// For examples, /// vs/platform/opensolution; /// vs/platform/editor/lightbulb/fixerror; /// </param> /// <param name="severity"> /// A severity level of the event. /// The level is used for event consumer (e.g., ETW provider, backend reporting) to organize data easier. /// </param> /// <param name="startEventProperties"> /// Event properties for the start event of this scope. They are also copied to end event. /// </param> /// <param name="correlations">Events with which this scope can correlate.</param> /// <returns><see cref="T:Coding4Fun.VisualStudio.Telemetry.TelemetryScope`1" /> instance.</returns> public static TelemetryScope <OperationEvent> StartOperation(this TelemetrySession session, string eventName, TelemetrySeverity severity, IDictionary <string, object> startEventProperties, TelemetryEventCorrelation[] correlations) { TelemetryScopeSettings settings = new TelemetryScopeSettings { Severity = severity, StartEventProperties = startEventProperties, Correlations = correlations }; return(session.StartOperation(eventName, settings)); }
/// <summary> /// Start tracking operation by posting a <see cref="T:Coding4Fun.VisualStudio.Telemetry.OperationEvent" /> with specified properties at the begining of operation work, /// and return a <see cref="T:Coding4Fun.VisualStudio.Telemetry.TelemetryScope`1" /> object. /// When the user task finishes, call method <see cref="M:Coding4Fun.VisualStudio.Telemetry.TelemetryScope`1.End(Coding4Fun.VisualStudio.Telemetry.TelemetryResult,System.String)" /> to post another <see cref="T:Coding4Fun.VisualStudio.Telemetry.OperationEvent" /> for end point. /// Because the same event name is used by both start and end events, please don't use Start or End in event name. /// </summary> /// <param name="session">Telemetry Session</param> /// <param name="eventName"> /// An event name following data model schema. /// It requires that event name is a unique, not null or empty string. /// It consists of 3 parts and must follows pattern [product]/[featureName]/[entityName]. FeatureName could be a one-level feature or feature hierarchy delimited by "/". /// For examples, /// vs/platform/opensolution; /// vs/platform/editor/lightbulb/fixerror; /// </param> /// <param name="settings">A <see cref="T:Coding4Fun.VisualStudio.Telemetry.TelemetryScopeSettings" /> object to control the TelemetryScope behavior.</param> /// <returns><see cref="T:Coding4Fun.VisualStudio.Telemetry.TelemetryScope`1" /> instance.</returns> public static TelemetryScope <OperationEvent> StartOperation(this TelemetrySession session, string eventName, TelemetryScopeSettings settings) { CodeContract.RequiresArgumentNotNull <TelemetrySession>(session, "session"); CodeContract.RequiresArgumentNotNull <TelemetryScopeSettings>(settings, "settings"); return(new TelemetryScope <OperationEvent>(session, eventName, (OperationStageType stageType) => new OperationEvent(eventName, stageType, TelemetryResult.None), settings)); }
/// <summary> /// Create and post an event for start point, and then create a user event for end point (but not posted.) /// </summary> /// <param name="telemetrySession">Telemetry Session</param> /// <param name="eventName"> /// An event name following data model schema. /// It requires that event name is a unique, not null or empty string. /// It consists of 3 parts and must follows pattern [product]/[featureName]/[entityName]. FeatureName could be a one-level feature or feature hierarchy delimited by "/". /// For examples, /// vs/platform/opensolution; /// vs/platform/editor/lightbulb/fixerror; /// </param> /// <param name="createNewEvent">A function to create a new event.</param> /// <param name="settings">A <see cref="T:Coding4Fun.VisualStudio.Telemetry.TelemetryScopeSettings" /> object to control the TelemetryScope behavior.</param> /// <remarks> /// Because the same event name is used by both start and end events, please don't use Start or End in event name. /// </remarks> internal TelemetryScope(TelemetrySession telemetrySession, string eventName, CreateNewEvent createNewEvent, TelemetryScopeSettings settings) { isEnded = 0; TelemetrySession = telemetrySession; Guid.NewGuid(); StartTime = DateTime.UtcNow; T val = createNewEvent(OperationStageType.Start); val.Severity = settings.Severity; val.Correlate(settings.Correlations); val.IsOptOutFriendly = settings.IsOptOutFriendly; if (settings.StartEventProperties != null) { DictionaryExtensions.AddRange <string, object>(val.Properties, settings.StartEventProperties, true); } if (settings.PostStartEvent) { TelemetrySession.PostEvent(val); } EndEvent = val; EndEvent.SetPostStartEventProperty(settings.PostStartEvent); EndEvent.StageType = OperationStageType.End; }