private ClientContextCore( CosmosClient client, CosmosClientOptions clientOptions, CosmosSerializerCore serializerCore, CosmosResponseFactoryInternal cosmosResponseFactory, RequestInvokerHandler requestHandler, DocumentClient documentClient, string userAgent, BatchAsyncContainerExecutorCache batchExecutorCache, ClientTelemetry telemetry) { this.client = client; this.clientOptions = clientOptions; this.serializerCore = serializerCore; this.responseFactory = cosmosResponseFactory; this.requestHandler = requestHandler; this.documentClient = documentClient; this.userAgent = userAgent; this.batchExecutorCache = batchExecutorCache; this.telemetry = telemetry; }
public ClientPipelineBuilder( CosmosClient client, ConsistencyLevel?requestedClientConsistencyLevel, IReadOnlyCollection <RequestHandler> customHandlers, ClientTelemetry telemetry) { this.client = client ?? throw new ArgumentNullException(nameof(client)); this.requestedClientConsistencyLevel = requestedClientConsistencyLevel; this.transportHandler = new TransportHandler(client); Debug.Assert(this.transportHandler.InnerHandler == null, nameof(this.transportHandler)); this.invalidPartitionExceptionRetryHandler = new NamedCacheRetryHandler(); Debug.Assert(this.invalidPartitionExceptionRetryHandler.InnerHandler == null, "The invalidPartitionExceptionRetryHandler.InnerHandler must be null to allow other handlers to be linked."); this.PartitionKeyRangeHandler = new PartitionKeyRangeHandler(client); Debug.Assert(this.PartitionKeyRangeHandler.InnerHandler == null, "The PartitionKeyRangeHandler.InnerHandler must be null to allow other handlers to be linked."); // Disable system usage for internal builds. Cosmos DB owns the VMs and already logs // the system information so no need to track it. #if !INTERNAL this.diagnosticsHandler = new DiagnosticsHandler(); Debug.Assert(this.diagnosticsHandler.InnerHandler == null, nameof(this.diagnosticsHandler)); if (telemetry != null) { this.telemetryHandler = new TelemetryHandler(telemetry); Debug.Assert(this.telemetryHandler.InnerHandler == null, nameof(this.telemetryHandler)); } #else this.diagnosticsHandler = null; this.telemetryHandler = null; #endif this.UseRetryPolicy(); this.AddCustomHandlers(customHandlers); }
internal static void SendReport(string reportType, string reportContent) { ClientTelemetry.SendPacket($"GWReportType: {reportType} | {reportContent}"); }
public TelemetryHandler(ClientTelemetry telemetry) { this.telemetry = telemetry ?? throw new ArgumentNullException(nameof(telemetry)); }
internal static CosmosClientContext Create( CosmosClient cosmosClient, DocumentClient documentClient, CosmosClientOptions clientOptions, RequestInvokerHandler requestInvokerHandler = null) { if (cosmosClient == null) { throw new ArgumentNullException(nameof(cosmosClient)); } if (documentClient == null) { throw new ArgumentNullException(nameof(documentClient)); } clientOptions = ClientContextCore.CreateOrCloneClientOptions(clientOptions); ConnectionPolicy connectionPolicy = clientOptions.GetConnectionPolicy(cosmosClient.ClientId); ClientTelemetry telemetry = null; if (connectionPolicy.EnableClientTelemetry) { try { telemetry = ClientTelemetry.CreateAndStartBackgroundTelemetry( documentClient: documentClient, userAgent: connectionPolicy.UserAgentContainer.UserAgent, connectionMode: connectionPolicy.ConnectionMode, authorizationTokenProvider: cosmosClient.AuthorizationTokenProvider, diagnosticsHelper: DiagnosticsHandlerHelper.Instance, preferredRegions: clientOptions.ApplicationPreferredRegions); } catch (Exception ex) { DefaultTrace.TraceInformation($"Error While starting Telemetry Job : {ex.Message}. Hence disabling Client Telemetry"); connectionPolicy.EnableClientTelemetry = false; } } else { DefaultTrace.TraceInformation("Client Telemetry Disabled."); } if (requestInvokerHandler == null) { //Request pipeline ClientPipelineBuilder clientPipelineBuilder = new ClientPipelineBuilder( cosmosClient, clientOptions.ConsistencyLevel, clientOptions.CustomHandlers, telemetry: telemetry); requestInvokerHandler = clientPipelineBuilder.Build(); } CosmosSerializerCore serializerCore = CosmosSerializerCore.Create( clientOptions.Serializer, clientOptions.SerializerOptions); // This sets the serializer on client options which gives users access to it if a custom one is not configured. clientOptions.SetSerializerIfNotConfigured(serializerCore.GetCustomOrDefaultSerializer()); CosmosResponseFactoryInternal responseFactory = new CosmosResponseFactoryCore(serializerCore); return(new ClientContextCore( client: cosmosClient, clientOptions: clientOptions, serializerCore: serializerCore, cosmosResponseFactory: responseFactory, requestHandler: requestInvokerHandler, documentClient: documentClient, userAgent: documentClient.ConnectionPolicy.UserAgentContainer.UserAgent, batchExecutorCache: new BatchAsyncContainerExecutorCache(), telemetry: telemetry)); }