public AsimovAppInsightsClientWrapper(bool isUtcEnabled, string instrumentationKey, TelemetrySession hostTelemetrySession, StorageBase storage, IProcessLockFactory processLockFactory) : base(instrumentationKey) { this.isUtcEnabled = isUtcEnabled; this.hostTelemetrySession = hostTelemetrySession; this.storage = storage; this.processLockFactory = processLockFactory; }
/// <summary> /// Initializes a new instance of the <see cref="T:Coding4Fun.VisualStudio.ApplicationInsights.Channel.PersistenceChannel" /> class. /// </summary> /// <param name="storage"> /// A persistent storage that will store all transmissions. /// Setting this value groups channels, even from different processes. /// If 2 (or more) channels has the same <c>storage that share the same underlying folder</c> only one channel will perform the sending even if the channel is in a different process/AppDomain/Thread. /// </param> /// <param name="processLockFactory"> /// IProcessLockFactory that creates an IProcessLock to sync transmission between processes /// </param> /// <param name="sendersCount"> /// Defines the number of senders. A sender is a long-running thread that sends telemetry batches in intervals defined by <see cref="P:Coding4Fun.VisualStudio.ApplicationInsights.Channel.PersistenceChannel.SendingInterval" />. /// So the amount of senders also defined the maximum amount of http channels opened at the same time. /// By default we have 1 sending thread which should be more than enough for our purposes. /// </param> public PersistenceChannel(StorageBase storage, IProcessLockFactory processLockFactory, int sendersCount = 1) { TelemetryBuffer = new TelemetryBuffer(); this.storage = storage; Transmitter = new PersistenceTransmitter(this.storage, sendersCount, processLockFactory); flushManager = new FlushManager(this.storage, TelemetryBuffer); EndpointAddress = "https://dc.services.visualstudio.com/v2/track"; }
/// <summary> /// Initializes a new instance of the <see cref="T:Coding4Fun.VisualStudio.ApplicationInsights.Channel.PersistenceTransmitter" /> class. /// </summary> /// <param name="storage">The transmissions storage.</param> /// <param name="sendersCount">The number of senders to create.</param> /// <param name="processLockFactory">IProcessLockBuilder that will create an IProcessLock to sync transmission between processes</param> /// <param name="createSenders">A boolean value that indicates if this class should try and create senders. This is a workaround for unit tests purposes only.</param> internal PersistenceTransmitter(StorageBase storage, int sendersCount, IProcessLockFactory processLockFactory, bool createSenders = true) { this.storage = storage; sendingCancellationTokenSource = new CancellationTokenSource(); eventToKeepMutexThreadAlive = new AutoResetEvent(false); try { string text = this.storage.StorageFolder?.FullName; if (text == null) { text = string.Empty; } locker = processLockFactory.CreateLocker(text, "_675531BB6E734D2F846AB8511A8963FD_"); } catch (Exception ex) { locker = null; string message = string.Format(CultureInfo.InvariantCulture, "PersistenceTransmitter: Failed to construct the mutex: {0}", new object[1] { ex }); CoreEventSource.Log.LogVerbose(message); } if (createSenders) { Task.Factory.StartNew(delegate { AcquireMutex(delegate { CreateSenders(sendersCount); }); }, TaskCreationOptions.LongRunning).ContinueWith(delegate(Task task) { string text2 = string.Format(CultureInfo.InvariantCulture, "PersistenceTransmitter: Unhandled exception in CreateSenders: {0}", new object[1] { task.Exception }); LocalFileLoggerService.Default.Log(LocalLoggerSeverity.Error, "Telemetry", text2); CoreEventSource.Log.LogVerbose(text2); }, TaskContinuationOptions.OnlyOnFaulted); } }
/// <summary> /// Create default session channels and return IEnumerable list of them. /// In the case when checkPendingAsimovEvents == true call method on Vortex channel /// to check whether pending telemetry is exists and in case existing Start this channel /// immediately. /// </summary> /// <param name="telemetrySession"></param> /// <param name="checkPendingAsimovEvents"></param> /// <returns></returns> public IEnumerable <ISessionChannel> CreateSessionChannels(TelemetrySession telemetrySession, bool checkPendingAsimovEvents) { IStorageBuilder storageBuilder = GetStorageBuilder(); IProcessLockFactory processLockFactory = GetProcessLock(); if (AppInsightsInstrumentationKey != null) { yield return(new DefaultAppInsightsSessionChannel(AppInsightsInstrumentationKey, telemetrySession.UserId.ToString(), storageBuilder, processLockFactory)); } if (AsimovInstrumentationKey != null) { AsimovAppInsightsSessionChannel asimovAppInsightsSessionChannel = new AsimovAppInsightsSessionChannel("aivortex", false, AsimovInstrumentationKey, telemetrySession.UserId.ToString(), ChannelProperties.Default | ChannelProperties.NotForUnitTest, telemetrySession, storageBuilder, processLockFactory); if (checkPendingAsimovEvents) { asimovAppInsightsSessionChannel.CheckPendingEventsAndStartChannel(telemetrySession.SessionId); } yield return(asimovAppInsightsSessionChannel); yield return(new AsimovAppInsightsSessionChannel("aiasimov", Platform.IsWindows, AsimovInstrumentationKey, telemetrySession.UserId.ToString(), ChannelProperties.NotForUnitTest, telemetrySession, storageBuilder, processLockFactory)); } yield return(new TelemetryLogToFileChannel()); }
public DefaultAppInsightsClientWrapper(string instrumentationKey, StorageBase storage, IProcessLockFactory processLockFactory) : base(instrumentationKey) { this.storage = storage; this.processLockFactory = processLockFactory; }
public DefaultAppInsightsSessionChannel(string instrumentationKey, string userId, IStorageBuilder storageBuilder, IProcessLockFactory processLockFactory) : base(instrumentationKey, userId) { this.storageBuilder = storageBuilder; this.processLockFactory = processLockFactory; }