/// <summary>
 /// RecordOtelAttributes
 /// </summary>
 /// <param name="exception"></param>
 /// <param name="scope"></param>
 internal static void RecordOtelAttributes(CosmosException exception, DiagnosticScope scope)
 {
     scope.AddAttribute(OpenTelemetryAttributeKeys.StatusCode, exception.StatusCode);
     scope.AddAttribute(OpenTelemetryAttributeKeys.RequestCharge, exception.RequestCharge);
     scope.AddAttribute(OpenTelemetryAttributeKeys.Region, ClientTelemetryHelper.GetContactedRegions(exception.Diagnostics));
     scope.AddAttribute(OpenTelemetryAttributeKeys.RequestDiagnostics, exception.Diagnostics);
     scope.AddAttribute(OpenTelemetryAttributeKeys.ExceptionMessage, exception.Message);
 }
        public void ContactedRegionsWithNameForClientTelemetryTest()
        {
            CosmosDiagnostics diagnostics = new CosmosTraceDiagnostics(this.CreateTestTraceTree());

            string regionsContacted = ClientTelemetryHelper.GetContactedRegions(diagnostics);

            Assert.IsNotNull(regionsContacted);
            Assert.AreEqual("Central US,Central India,East US 2,France Central", regionsContacted);
        }
        internal void CollectRegionContacted(CosmosDiagnostics cosmosDiagnostics)
        {
            if (cosmosDiagnostics == null)
            {
                throw new ArgumentNullException(nameof(cosmosDiagnostics));
            }

            ClientTelemetryHelper.GetContactedRegions(cosmosDiagnostics);
        }
        public void ContactedRegionWithNameForClientTelemetryTest()
        {
            Trace trace;

            using (trace = Trace.GetRootTrace("Root Trace", TraceComponent.Unknown, TraceLevel.Info))
            {
                using (ITrace firstLevel = trace.StartChild("First level Node", TraceComponent.Unknown, TraceLevel.Info))
                {
                    firstLevel.AddDatum("Client Side Request Stats", this.GetDatumObject(Regions.FranceCentral));
                }
            }

            CosmosDiagnostics diagnostics = new CosmosTraceDiagnostics(trace);

            string regionsContacted = ClientTelemetryHelper.GetContactedRegions(diagnostics);

            Assert.IsNotNull(regionsContacted);
            Assert.AreEqual("France Central", regionsContacted);
        }
        /// <summary>
        /// Record attributes from response
        /// </summary>
        /// <param name="response"></param>
        public void Record(OpenTelemetryAttributes response)
        {
            this.scope.AddAttribute(OpenTelemetryAttributeKeys.DbName, response.DatabaseName);

            this.scope.AddAttribute(OpenTelemetryAttributeKeys.ContainerName, response.ContainerName);
            this.scope.AddAttribute(OpenTelemetryAttributeKeys.RequestContentLength, response.RequestContentLength);
            this.scope.AddAttribute(OpenTelemetryAttributeKeys.ResponseContentLength, response.ResponseContentLength);
            this.scope.AddAttribute(OpenTelemetryAttributeKeys.StatusCode, response.StatusCode);
            this.scope.AddAttribute(OpenTelemetryAttributeKeys.RequestCharge, response.RequestCharge);
            this.scope.AddAttribute(OpenTelemetryAttributeKeys.ItemCount, response.ItemCount);
            this.scope.AddAttribute(OpenTelemetryAttributeKeys.Region, ClientTelemetryHelper.GetContactedRegions(response.Diagnostics));

            if (this.IsEnabled && DiagnosticsFilterHelper.IsAllowed(
                    latency: response.Diagnostics.GetClientElapsedTime(),
                    statuscode: response.StatusCode))
            {
                this.scope.AddAttribute(OpenTelemetryAttributeKeys.RequestDiagnostics, response.Diagnostics);
            }
        }