Example #1
0
        internal Microsoft.Azure.Cosmos.CosmosClient CreateCosmosClient(string accountKey)
        {
            Microsoft.Azure.Cosmos.CosmosClientOptions clientOptions = new Microsoft.Azure.Cosmos.CosmosClientOptions()
            {
                ApplicationName = BenchmarkConfig.UserAgentSuffix,
                MaxRetryAttemptsOnRateLimitedRequests = 0,
                MaxRequestsPerTcpConnection           = this.MaxRequestsPerTcpConnection,
                MaxTcpConnectionsPerEndpoint          = this.MaxTcpConnectionsPerEndpoint,
                EnableClientTelemetry = this.EnableTelemetry
            };

            if (this.EnableTelemetry)
            {
                Environment.SetEnvironmentVariable(Microsoft.Azure.Cosmos.Telemetry.ClientTelemetryOptions.EnvPropsClientTelemetrySchedulingInSeconds, "1");
            }

            if (!string.IsNullOrWhiteSpace(this.ConsistencyLevel))
            {
                clientOptions.ConsistencyLevel = (Microsoft.Azure.Cosmos.ConsistencyLevel)Enum.Parse(typeof(Microsoft.Azure.Cosmos.ConsistencyLevel), this.ConsistencyLevel, ignoreCase: true);
            }

            return(new Microsoft.Azure.Cosmos.CosmosClient(
                       this.EndPoint,
                       accountKey,
                       clientOptions));
        }
Example #2
0
        internal Microsoft.Azure.Cosmos.CosmosClient CreateCosmosClient(string accountKey)
        {
            Microsoft.Azure.Cosmos.CosmosClientOptions clientOptions = new Microsoft.Azure.Cosmos.CosmosClientOptions()
            {
                ApplicationName = this.GetUserAgentPrefix(),
                MaxRetryAttemptsOnRateLimitedRequests = 0,
                MaxRequestsPerTcpConnection           = this.MaxRequestsPerTcpConnection,
                MaxTcpConnectionsPerEndpoint          = this.MaxTcpConnectionsPerEndpoint
            };

            if (this.EnableOpenTelemetry)
            {
                clientOptions.EnableOpenTelemetry = true;
            }

            if (this.EnableTelemetry)
            {
                Environment.SetEnvironmentVariable(
                    Microsoft.Azure.Cosmos.Telemetry.ClientTelemetryOptions.EnvPropsClientTelemetryEnabled,
                    "true");

                if (this.TelemetryScheduleInSec > 0)
                {
                    Environment.SetEnvironmentVariable(
                        Microsoft.Azure.Cosmos.Telemetry.ClientTelemetryOptions.EnvPropsClientTelemetrySchedulingInSeconds,
                        Convert.ToString(this.TelemetryScheduleInSec));
                }

                if (!string.IsNullOrEmpty(this.TelemetryEndpoint))
                {
                    Environment.SetEnvironmentVariable(
                        Microsoft.Azure.Cosmos.Telemetry.ClientTelemetryOptions.EnvPropsClientTelemetryEndpoint,
                        this.TelemetryEndpoint);
                }
            }

            if (!string.IsNullOrWhiteSpace(this.ConsistencyLevel))
            {
                clientOptions.ConsistencyLevel = (Microsoft.Azure.Cosmos.ConsistencyLevel)Enum.Parse(typeof(Microsoft.Azure.Cosmos.ConsistencyLevel), this.ConsistencyLevel, ignoreCase: true);
            }

            return(new Microsoft.Azure.Cosmos.CosmosClient(
                       this.EndPoint,
                       accountKey,
                       clientOptions));
        }