/// <summary> /// Initializes a new instance of the <see cref="MsiCredentials"/> class. /// </summary> /// <param name="httpClientWrapper">The HTTP client wrapper</param> /// <param name="resource">The resource name - the URL for which these credentials will be used</param> /// <param name="tracer">The tracer</param> public MsiCredentials(IHttpClientWrapper httpClientWrapper, string resource, IExtendedTracer tracer) { this.resource = resource; this.httpClientWrapper = httpClientWrapper; this.tracer = tracer; this.retryPolicy = PolicyExtensions.CreateTransientHttpErrorPolicy(this.tracer, DependencyName); }
/// <summary> /// Initializes a new instance of the <see cref="ActivityLogClient"/> class. /// </summary> /// <param name="credentialsFactory">The credentials factory</param> /// <param name="httpClientWrapper">The HTTP client wrapper</param> /// <param name="tracer">The tracer</param> public ActivityLogClient(ICredentialsFactory credentialsFactory, IHttpClientWrapper httpClientWrapper, IExtendedTracer tracer) { this.httpClientWrapper = Diagnostics.EnsureArgumentNotNull(() => httpClientWrapper); this.tracer = Diagnostics.EnsureArgumentNotNull(() => tracer); this.baseUri = new Uri(ConfigurationManager.AppSettings["ResourceManagerBaseUri"] ?? "https://management.azure.com/"); Diagnostics.EnsureArgumentNotNull(() => credentialsFactory); this.credentials = credentialsFactory.Create(ConfigurationManager.AppSettings["ResourceManagerCredentialsResource"] ?? "https://management.azure.com/"); this.httpRetryPolicy = PolicyExtensions.CreateTransientHttpErrorPolicy(this.tracer, DependencyName); }
/// <summary> /// Initializes a new instance of the <see cref="LogAnalyticsClient"/> class. /// </summary> /// <param name="tracer">The tracer</param> /// <param name="httpClientWrapper">The HTTP client wrapper</param> /// <param name="credentialsFactory">The credentials factory</param> /// <param name="queryUri">The URI to use for querying telemetry - this should already include the resource to query</param> /// <param name="queryTimeout">The query timeout</param> public LogAnalyticsClient( ITracer tracer, IHttpClientWrapper httpClientWrapper, ICredentialsFactory credentialsFactory, Uri queryUri, TimeSpan queryTimeout) { this.tracer = Diagnostics.EnsureArgumentNotNull(() => tracer); this.httpClientWrapper = Diagnostics.EnsureArgumentNotNull(() => httpClientWrapper); this.credentialsFactory = Diagnostics.EnsureArgumentNotNull(() => credentialsFactory); this.QueryUri = Diagnostics.EnsureArgumentNotNull(() => queryUri); this.Timeout = Diagnostics.EnsureArgumentInRange(() => queryTimeout, TimeSpan.FromMinutes(0), TimeSpan.FromHours(2)); this.retryPolicy = PolicyExtensions.CreateTransientHttpErrorPolicy(this.tracer, "LogAnalytics"); }
/// <summary> /// Initializes a new instance of the <see cref="ExtendedAzureResourceManagerClient"/> class /// </summary> /// <param name="httpClientWrapper">The HTTP client wrapper</param> /// <param name="credentialsFactory">The credentials factory</param> /// <param name="tracer">The tracer</param> public ExtendedAzureResourceManagerClient(IHttpClientWrapper httpClientWrapper, ICredentialsFactory credentialsFactory, ITracer tracer) { this.httpClientWrapper = Diagnostics.EnsureArgumentNotNull(() => httpClientWrapper); Diagnostics.EnsureArgumentNotNull(() => credentialsFactory); this.baseUri = new Uri(ConfigurationManager.AppSettings["ResourceManagerBaseUri"] ?? "https://management.azure.com/"); this.credentials = credentialsFactory.CreateAzureCredentials(ConfigurationManager.AppSettings["ResourceManagerCredentialsResource"] ?? "https://management.azure.com/"); this.tracer = Diagnostics.EnsureArgumentNotNull(() => tracer); this.tracer = tracer; this.retryPolicy = Policy .Handle <CloudException>(ex => ex.Request != null && (ex.Response.StatusCode >= HttpStatusCode.InternalServerError || ex.Response.StatusCode == HttpStatusCode.RequestTimeout)) .WaitAndRetryAsync( 3, (i) => TimeSpan.FromSeconds(Math.Pow(2, i)), (exception, span, context) => tracer.TraceError($"Failed accessing DependencyName on {exception.Message}, retry {Math.Log(span.Seconds, 2)} out of 3")); this.httpRetryPolicy = PolicyExtensions.CreateTransientHttpErrorPolicy(this.tracer, DependencyName); }
protected TelemetryDataClientBase( ITracer tracer, IHttpClientWrapper httpClientWrapper, ICredentialsFactory credentialsFactory, IExtendedAzureResourceManagerClient azureResourceManagerClient, string queryUriFormat, TimeSpan queryTimeout, string telemetryDbType, IEnumerable <string> telemetryResourceIds) { this.tracer = Diagnostics.EnsureArgumentNotNull(() => tracer); this.httpClientWrapper = Diagnostics.EnsureArgumentNotNull(() => httpClientWrapper); this.credentialsFactory = Diagnostics.EnsureArgumentNotNull(() => credentialsFactory); this.AzureResourceManagerClient = Diagnostics.EnsureArgumentNotNull(() => azureResourceManagerClient); this.queryUriFormat = Diagnostics.EnsureStringNotNullOrWhiteSpace(() => queryUriFormat); this.Timeout = Diagnostics.EnsureArgumentInRange(() => queryTimeout, TimeSpan.FromMinutes(0), TimeSpan.FromHours(2)); this.telemetryDbType = telemetryDbType; int maximumNumberOfTelemetryResources = int.Parse(ConfigurationManager.AppSettings["MaximumNumberOfTelemetryResources"] ?? "300", CultureInfo.InvariantCulture); this.TelemetryResourceIds = telemetryResourceIds?.Take(maximumNumberOfTelemetryResources).ToList() ?? new List <string>(); this.retryPolicy = PolicyExtensions.CreateTransientHttpErrorPolicy(this.tracer, this.telemetryDbType); }