public void StopDependencyTrackingThrowsExceptionWithNullTelemetryClient() { var operationItem = new CallContextBasedOperationHolder <DependencyTelemetry>(this.telemetryClient, new DependencyTelemetry()); TelemetryClient tc = null; tc.StopOperation(operationItem); }
/// <summary> /// Creates an operation object with a given telemetry item. /// </summary> /// <typeparam name="T">Type of the telemetry item.</typeparam> /// <param name="telemetryClient">Telemetry client object.</param> /// <param name="operationTelemetry">Operation to start.</param> /// <returns>Operation item object with a new telemetry item having current start time and timestamp.</returns> public static IOperationHolder <T> StartOperation <T>(this TelemetryClient telemetryClient, T operationTelemetry) where T : OperationTelemetry { if (telemetryClient == null) { throw new ArgumentNullException("Telemetry client cannot be null."); } if (operationTelemetry == null) { throw new ArgumentNullException("operationTelemetry cannot be null."); } var operationHolder = new CallContextBasedOperationHolder <T>(telemetryClient, operationTelemetry) { // Parent context store is assigned to operation that is used to restore call context. ParentContext = CallContextHelpers.GetCurrentOperationContext() }; telemetryClient.Initialize(operationTelemetry); // Initialize operation id if it wasn't initialized by telemetry initializers if (string.IsNullOrEmpty(operationTelemetry.Id)) { operationTelemetry.GenerateOperationId(); } // If the operation is not executing in the context of any other operation // set its name and id as a context (root) operation name and id if (string.IsNullOrEmpty(operationTelemetry.Context.Operation.Id)) { operationTelemetry.Context.Operation.Id = operationTelemetry.Id; } if (string.IsNullOrEmpty(operationTelemetry.Context.Operation.Name)) { operationTelemetry.Context.Operation.Name = operationTelemetry.Name; } operationTelemetry.Start(); // Update the call context to store certain fields that can be used for subsequent operations. var operationContext = new OperationContextForCallContext(); operationContext.ParentOperationId = operationTelemetry.Id; operationContext.RootOperationId = operationTelemetry.Context.Operation.Id; operationContext.RootOperationName = operationTelemetry.Context.Operation.Name; CallContextHelpers.SaveOperationContext(operationContext); return(operationHolder); }
public void CreatingOperationItemDoesNotThrowOnPassingValidArguments() { var operationItem = new CallContextBasedOperationHolder<DependencyTelemetry>(new TelemetryClient(), new DependencyTelemetry()); }
public void CreatingOperationItemWithNullTelemetryThrowsArgumentNullException() { var operationItem = new CallContextBasedOperationHolder<DependencyTelemetry>(new TelemetryClient(), null); }
public void StopDependencyTrackingThrowsExceptionWithNullTelemetryClient() { var operationItem = new CallContextBasedOperationHolder<DependencyTelemetry>(this.telemetryClient, new DependencyTelemetry()); TelemetryClient tc = null; tc.StopOperation(operationItem); }