コード例 #1
0
 public TelemetryService(ITelemetryClient telemetryClient)
 {
     _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient));
 }
コード例 #2
0
        /// <summary>
        /// Creates a new instance of <see cref="CommandLinePredictor"/>.
        /// </summary>
        /// <param name="modelPredictions">List of suggestions from the model, sorted by frequency (most to least).</param>
        /// <param name="parameterValuePredictor">Provide the prediction to the parameter values.</param>
        /// <param name="telemetryClient">The telemetry client.</param>
        /// <param name="azContext">The current PowerShell conext.</param>
        public CommandLinePredictor(IList <PredictiveCommand> modelPredictions, ParameterValuePredictor parameterValuePredictor, ITelemetryClient telemetryClient, IAzContext azContext = null)
        {
            Validation.CheckArgument(modelPredictions, $"{nameof(modelPredictions)} cannot be null.");

            _telemetryClient         = telemetryClient;
            _parameterValuePredictor = parameterValuePredictor;
            var commnadLines = new List <CommandLine>();

            if (modelPredictions != null)
            {
                for (var i = 0; i < modelPredictions.Count; ++i)
                {
                    try
                    {
                        this._commandLinePredictions.Add(new CommandLine(modelPredictions[i], azContext));
                    }
                    catch (Exception e)
                    {
                        _telemetryClient?.OnParseCommandLineFailure(new CommandLineParsingTelemetryData(modelPredictions[i].Command, e));
                    }
                }
            }
        }
コード例 #3
0
 public TelemetryEventService(ITelemetryClient telemetryClient)
 {
     _timers          = new Dictionary <string, Stopwatch>();
     _telemetryClient = telemetryClient;
 }
コード例 #4
0
 public PullRequestEventHasher(ITelemetryClient telemetryClient)
     : base(telemetryClient)
 {
 }
コード例 #5
0
 public OrganizationPayloadHasher(ITelemetryClient telemetryClient)
     : base(telemetryClient)
 {
 }
コード例 #6
0
 public TelemetryService(ITelemetryClient telemetry, ISystemInfoService infoService)
 {
     _telemetry   = telemetry;
     _infoService = infoService;
 }
コード例 #7
0
 protected AbstractMatsExecutor(ITelemetryClient mats)
 {
     _mats = mats;
 }
コード例 #8
0
        public static bool Upload(TelemetryConfiguration teleConfig, string profile, ITelemetryClient teleClient)
        {
            try
            {
                var fileEntries = Directory.GetFiles(teleConfig.LogsPath)
                                  .Where(f =>
                                         Path.GetFileName(f)
                                         .StartsWith("portingAssistant-client-cli") &&
                                         teleConfig.Suffix.ToArray().Any(x => f.EndsWith(x))
                                         ).ToList();

                var lastReadTokenFile = Path.Combine(teleConfig.LogsPath, "lastToken.json");
                var fileLineNumberMap = new Dictionary <string, int>();
                if (File.Exists(lastReadTokenFile))
                {
                    fileLineNumberMap = JsonConvert.DeserializeObject <Dictionary <string, int> >(File.ReadAllText(lastReadTokenFile));
                }
                foreach (var file in fileEntries)
                {
                    var logName       = Path.GetFileNameWithoutExtension(file);
                    var fileExtension = Path.GetExtension(file);
                    if (fileExtension == ".log")
                    {
                        logName = $"{logName}-logs";
                    }
                    else if (fileExtension == ".metrics")
                    {
                        logName = $"{logName}-metrics";
                    }

                    // Add new files to fileLineNumberMap
                    if (!fileLineNumberMap.ContainsKey(file))
                    {
                        fileLineNumberMap[file] = 0;
                    }
                    var initLineNumber = fileLineNumberMap[file];

                    FileInfo fileInfo = new FileInfo(file);
                    var      success  = false;
                    using (FileStream fs = fileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    {
                        using (StreamReader reader = new StreamReader(fs))
                        {
                            // If put-log api works keep sending logs else wait and do it next time
                            var logs = new ArrayList();

                            int currLineNumber = 0;
                            for (; currLineNumber < initLineNumber; currLineNumber++)
                            {
                                string line = reader.ReadLine();
                                if (line == null)
                                {
                                    return(true);
                                }
                            }

                            while (!reader.EndOfStream)
                            {
                                currLineNumber++;
                                logs.Add(reader.ReadLine());

                                // send 1000 lines of logs each time when there are large files
                                if (logs.Count >= 1000)
                                {
                                    // logs.TrimToSize();
                                    success = PutLogData(logName, JsonConvert.SerializeObject(logs), profile, teleConfig, teleClient).Result;
                                    if (success)
                                    {
                                        logs = new ArrayList();
                                    }
                                    else
                                    {
                                        return(false);
                                    }
                                }
                            }

                            if (logs.Count != 0)
                            {
                                success = PutLogData(logName, JsonConvert.SerializeObject(logs), profile, teleConfig, teleClient).Result;
                                if (!success)
                                {
                                    return(false);
                                }
                            }

                            if (success)
                            {
                                fileLineNumberMap[file] = currLineNumber;
                                string jsonString = JsonConvert.SerializeObject(fileLineNumberMap);
                                File.WriteAllText(lastReadTokenFile, jsonString);
                            }
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                Log.Logger.Error(ex.Message);
                return(false);
            }
        }
コード例 #9
0
 public ForkPayloadHasher(ITelemetryClient telemetryClient)
     : base(telemetryClient)
 {
 }
コード例 #10
0
 public TelemetryDiagnosticControls(ITelemetryClient telemetryClient)
 {
     _telemetryClient = telemetryClient;
 }
コード例 #11
0
 public TelemetryClientApplicationBaseExecutor(IClientApplicationBaseExecutor executor, ITelemetryClient mats)
     : base(mats)
 {
     _executor = executor;
 }
コード例 #12
0
        public EnrichmentMessageRouter(IDataSource dataSource, IDataSink dataSink, IIoTDeviceDataEnricher dataEnricher, ITelemetryClient telemetryClient, IConfiguration config, ILogger <EnrichmentMessageRouter> logger)
        {
            this.dataSource      = dataSource;
            this.dataSink        = dataSink;
            this.dataEnricher    = dataEnricher;
            this.telemetryClient = telemetryClient;
            this.logger          = logger;
            this.config          = config;

            // handle messages as they arrive
            this.MessageBatchReceived += (sender, e) =>
            {
                // process with parallelism
                Parallel.ForEach(e.Messages, async(message) =>
                {
                    // get the device id
                    var deviceId = message.GetDeviceId();

                    // get the metadata
                    var startTime = DateTime.UtcNow;
                    var timer     = System.Diagnostics.Stopwatch.StartNew();
                    try
                    {
                        var metadata = await this.dataEnricher.GetMetadataAsync(deviceId);
                        if (metadata != null)
                        {
                            // enrich the message
                            message.EnrichMessage(metadata);

                            // output the message
                            await this.dataSink.WriteMessageAsync(message);

                            // send the telemetry
                            timer.Stop();
                            telemetryClient.TrackDependency("gRPC call", "IoTClient", "GetMetadataAzync", startTime, timer.Elapsed, true);
                        }
                    }
                    catch
                    {
                        // send the telemetry
                        timer.Stop();
                        logger.LogDebug($"gRPC call took {timer.Elapsed.Milliseconds} ms");
                        telemetryClient.TrackDependency("gRPC call", "IoTClient", "GetMetadataAzync", startTime, timer.Elapsed, false);
                    }
                    finally
                    {
                        Interlocked.Decrement(ref waiting);
                    }
                });
            };
        }
コード例 #13
0
 public IssueCommentPayloadHasher(ITelemetryClient telemetryClient)
     : base(telemetryClient)
 {
 }
コード例 #14
0
 /// <summary>
 /// Adds the client.
 /// </summary>
 /// <param name="client">The client.</param>
 /// <returns></returns>
 public static ITelemetryClient AddClient(ITelemetryClient client)
 {
     LogConsumer.Trace("Adding telemetry client of type {0}", client.GetType().FullName);
     Clients.Add(client);
     return(client);
 }
コード例 #15
0
 public TelemetryDiagnosticControls()
 {
     _telemetryClient = new TelemetryClient();
 }
コード例 #16
0
 public LoggerDiagnosticsSource(ITelemetryClient telemetryClient, ILogger logger)
 {
     _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient));
     _logger          = logger ?? throw new ArgumentNullException(nameof(logger));
 }
 public IHttpWebRequest CreateWebRequest(Uri address, string dependencyName, ITelemetryFactory telemetryFactory, ITelemetryClient telemetryClient)
 {
     return(new InstrumentedHttpWebRequestWrapper(address, telemetryFactory, telemetryClient, dependencyName));
 }
コード例 #18
0
 public TelemetryService(ITelemetryClient telemetryClient, IDictionary <string, string> globalDimensions)
 {
     _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient));
     GlobalDimensions = globalDimensions ?? throw new ArgumentNullException(nameof(globalDimensions));
 }
コード例 #19
0
        /// <summary>
        /// Requests preditions and collects telemetry event.
        /// </summary>
        /// <param name="azPredictorService">The service to send the request.</param>
        /// <param name="telemetryClient">The telemetry client to collect the data.</param>
        /// <param name="predictionClient">The client that initiate the telemetry event.</param>
        /// <param name="commands">A list of commands.</param>
        /// <param name="telemetryWaitTask">The task to wait before we collect the telemetry data.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        public static async Task RequestPredictionAndCollectTelemetryAync(IAzPredictorService azPredictorService, ITelemetryClient telemetryClient, PredictionClient predictionClient, IEnumerable <string> commands, TaskCompletionSource telemetryWaitTask, CancellationToken cancellationToken)
        {
            var       requestId          = Guid.NewGuid().ToString();
            bool?     hasSentHttpRequest = default;
            Exception exception          = null;

            try
            {
                hasSentHttpRequest = await azPredictorService.RequestPredictionsAsync(commands, requestId, cancellationToken);
            }
            catch (ServiceRequestException e)
            {
                hasSentHttpRequest = e.IsRequestSent;
                exception          = e.InnerException;
            }
            catch (Exception e) when(!(e is OperationCanceledException))
            {
                exception = e;
            }
            finally
            {
                if (telemetryWaitTask != null)
                {
                    await telemetryWaitTask.Task;
                }

                if (hasSentHttpRequest.HasValue)
                {
                    telemetryClient.RequestId = requestId;
                    telemetryClient.OnRequestPrediction(new RequestPredictionTelemetryData(predictionClient,
                                                                                           commands,
                                                                                           hasSentHttpRequest.Value,
                                                                                           exception));
                }
            }
        }
コード例 #20
0
 public AisABTestAdapter(Dictionary <string, string> applicationSettings, ITelemetryClient telemetryClient)
 {
     this.adapterSettings = applicationSettings;
     this.telemetryClient = telemetryClient;
 }
コード例 #21
0
 public TrackExceptionsFilterAttribute(ITelemetryClient telemetryClient)
 {
     _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient));
 }
コード例 #22
0
 public IssueCommentEventHasher(ITelemetryClient telemetryClient)
     : base(telemetryClient)
 {
 }
コード例 #23
0
 public TelemetryService(ITelemetryClient telemetryClient)
 {
     _telemetryClient = telemetryClient;
 }
 public TelemetryPublicClientExecutor(IPublicClientApplicationExecutor executor, ITelemetryClient mats)
     : base(mats)
 {
     _executor = executor;
 }
コード例 #25
0
 public TelemetryService(ITelemetryClient telemetryClient, IOptionsSnapshot <MonitorConfiguration> configuration)
 {
     _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient));
     _configuration   = configuration ?? throw new ArgumentNullException(nameof(configuration));
     _subscription    = _configuration.Value.Subscription;
 }
コード例 #26
0
 public LoggerDiagnosticsService(ILoggerFactory loggerFactory, ITelemetryClient telemetryClient)
 {
     _loggerFactory   = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
     _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient));
 }
コード例 #27
0
        private static void ConfigureForAzureStorage(ContainerBuilder builder, IGalleryConfigurationService configuration, ITelemetryClient telemetryClient)
        {
            /// The goal here is to initialize a <see cref="ICloudBlobClient"/> and <see cref="IFileStorageService"/>
            /// instance for each unique connection string. Each dependent of <see cref="IFileStorageService"/> (that
            /// is, each service that has a <see cref="IFileStorageService"/> constructor parameter) is registered in
            /// <see cref="StorageDependent.GetAll(IAppConfiguration)"/> and is grouped by the respective storage
            /// connection string. Each group is given a binding key which refers to the appropriate instance of the
            /// <see cref="IFileStorageService"/>.
            var completedBindingKeys = new HashSet <string>();

            foreach (var dependent in StorageDependent.GetAll(configuration.Current))
            {
                if (completedBindingKeys.Add(dependent.BindingKey))
                {
                    builder.RegisterInstance(new CloudBlobClientWrapper(dependent.AzureStorageConnectionString, configuration.Current.AzureStorageReadAccessGeoRedundant))
                    .AsSelf()
                    .As <ICloudBlobClient>()
                    .SingleInstance()
                    .Keyed <ICloudBlobClient>(dependent.BindingKey);

                    builder.RegisterType <CloudBlobFileStorageService>()
                    .WithParameter(new ResolvedParameter(
                                       (pi, ctx) => pi.ParameterType == typeof(ICloudBlobClient),
                                       (pi, ctx) => ctx.ResolveKeyed <ICloudBlobClient>(dependent.BindingKey)))
                    .AsSelf()
                    .As <IFileStorageService>()
                    .As <ICoreFileStorageService>()
                    .As <ICloudStorageStatusDependency>()
                    .SingleInstance()
                    .Keyed <IFileStorageService>(dependent.BindingKey);
                }

                var registration = builder.RegisterType(dependent.ImplementationType)
                                   .WithParameter(new ResolvedParameter(
                                                      (pi, ctx) => pi.ParameterType.IsAssignableFrom(typeof(IFileStorageService)),
                                                      (pi, ctx) => ctx.ResolveKeyed <IFileStorageService>(dependent.BindingKey)))
                                   .AsSelf()
                                   .As(dependent.InterfaceType);

                if (dependent.IsSingleInstance)
                {
                    registration.SingleInstance();
                }
                else
                {
                    registration.InstancePerLifetimeScope();
                }
            }

            // when running on Windows Azure, we use a back-end job to calculate stats totals and store in the blobs
            builder.RegisterInstance(new JsonAggregateStatsService(configuration.Current.AzureStorage_Statistics_ConnectionString, configuration.Current.AzureStorageReadAccessGeoRedundant))
            .AsSelf()
            .As <IAggregateStatsService>()
            .SingleInstance();

            // when running on Windows Azure, pull the statistics from the warehouse via storage
            builder.RegisterInstance(new CloudReportService(configuration.Current.AzureStorage_Statistics_ConnectionString, configuration.Current.AzureStorageReadAccessGeoRedundant))
            .AsSelf()
            .As <IReportService>()
            .As <ICloudStorageStatusDependency>()
            .SingleInstance();

            // when running on Windows Azure, download counts come from the downloads.v1.json blob
            var downloadCountService = new CloudDownloadCountService(
                telemetryClient,
                configuration.Current.AzureStorage_Statistics_ConnectionString,
                configuration.Current.AzureStorageReadAccessGeoRedundant);

            builder.RegisterInstance(downloadCountService)
            .AsSelf()
            .As <IDownloadCountService>()
            .SingleInstance();
            ObjectMaterializedInterception.AddInterceptor(new DownloadCountObjectMaterializedInterceptor(downloadCountService));

            builder.RegisterType <JsonStatisticsService>()
            .AsSelf()
            .As <IStatisticsService>()
            .SingleInstance();

            builder.RegisterInstance(new TableErrorLog(configuration.Current.AzureStorage_Errors_ConnectionString, configuration.Current.AzureStorageReadAccessGeoRedundant))
            .As <ErrorLog>()
            .SingleInstance();

            builder.RegisterType <FlatContainerContentFileMetadataService>()
            .As <IContentFileMetadataService>()
            .SingleInstance();
        }
コード例 #28
0
 public TelemetryService(ILogger logger, ITelemetryClient telemetry, ISystemInfoService infoService)
 {
     _logger      = logger;
     _telemetry   = telemetry;
     _infoService = infoService;
 }
コード例 #29
0
 public GitHubRateLimiter(string organizationId, ICache <RateLimitTableEntity> rateLimiterCache, IHttpClient httpClient, ITelemetryClient telemetryClient, double maxUsageBeforeDelayStarts, string apiDomain)
     : base(RateLimitTableEntity.GlobalOrganizationId, organizationName: organizationId.Equals(RateLimitTableEntity.GlobalOrganizationId) ? string.Empty : organizationId, rateLimiterCache, telemetryClient, expectRateLimitingHeaders: true)
 {
     this.httpClient = httpClient;
     this.maxUsageBeforeDelayStarts = maxUsageBeforeDelayStarts;
     this.usageCheckUrl             = $"https://{apiDomain}/rate_limit";
 }
コード例 #30
0
 public GitHubCollector(GitHubHttpClient httpClient, IAuthentication authentication, ITelemetryClient telemetryClient, List <IRecordWriter> recordWriters)
     : base(authentication, telemetryClient, recordWriters)
 {
     this.httpClient = httpClient;
 }
コード例 #31
0
 public TelemetryServiceWrapper(IDiagnosticsService diagnosticsService, ITelemetryClient telemetryClient)
     : base(diagnosticsService, telemetryClient)
 {
 }
コード例 #32
0
 public TelemetryDiagnosticControls(ITelemetryClient telemetryClient)
 {
     this._telemetryClient=telemetryClient;
 }