Exemple #1
0
        public void MarkFailedTest()
        {
            Assert.IsFalse(OpenTelemetryCoreRecorder.IsExceptionRegistered(
                               new Exception(),
                               default));

            Assert.IsTrue(OpenTelemetryCoreRecorder.IsExceptionRegistered(
                              new CosmosNullReferenceException(
                                  new NullReferenceException(),
                                  NoOpTrace.Singleton),
                              default));

            Assert.IsTrue(OpenTelemetryCoreRecorder.IsExceptionRegistered(
                              new CosmosObjectDisposedException(
                                  new ObjectDisposedException("dummyobject"),
                                  MockCosmosUtil.CreateMockCosmosClient(),
                                  NoOpTrace.Singleton),
                              default));

            Assert.IsTrue(OpenTelemetryCoreRecorder.IsExceptionRegistered(
                              new CosmosOperationCanceledException(
                                  new OperationCanceledException(),
                                  new CosmosTraceDiagnostics(NoOpTrace.Singleton)),
                              default));

            Assert.IsTrue(OpenTelemetryCoreRecorder.IsExceptionRegistered(
                              new CosmosException(
                                  System.Net.HttpStatusCode.OK,
                                  "dummyMessage",
                                  "dummyStacktrace",
                                  null,
                                  NoOpTrace.Singleton,
Exemple #2
0
        private async Task <TResult> RunWithDiagnosticsHelperAsync <TResult>(
            ITrace trace,
            Func <ITrace, Task <TResult> > task,
            Func <TResult, OpenTelemetryAttributes> openTelemetry,
            string operationName)
        {
            using (OpenTelemetryCoreRecorder recorder =
                       OpenTelemetryRecorderFactory.CreateRecorder(
                           operationName: operationName,
                           isFeatureEnabled: this.clientOptions.EnableOpenTelemetry))
                using (new ActivityScope(Guid.NewGuid()))
                {
                    try
                    {
                        TResult result = await task(trace).ConfigureAwait(false);

                        if (openTelemetry != null && recorder.IsEnabled)
                        {
                            // Record client and other information
                            recorder.Record(operationName, this);

                            // Record request response information
                            OpenTelemetryAttributes response = openTelemetry(result);
                            recorder.Record(response);
                        }

                        return(result);
                    }
                    catch (OperationCanceledException oe) when(!(oe is CosmosOperationCanceledException))
                    {
                        CosmosOperationCanceledException operationCancelledException = new CosmosOperationCanceledException(oe, trace);

                        recorder.MarkFailed(operationCancelledException);

                        throw operationCancelledException;
                    }
                    catch (ObjectDisposedException objectDisposed) when(!(objectDisposed is CosmosObjectDisposedException))
                    {
                        CosmosObjectDisposedException objectDisposedException = new CosmosObjectDisposedException(
                            objectDisposed,
                            this.client,
                            trace);

                        recorder.MarkFailed(objectDisposedException);

                        throw objectDisposedException;
                    }
                    catch (NullReferenceException nullRefException) when(!(nullRefException is CosmosNullReferenceException))
                    {
                        CosmosNullReferenceException nullException = new CosmosNullReferenceException(
                            nullRefException,
                            trace);

                        recorder.MarkFailed(nullException);

                        throw nullException;
                    }
                    catch (Exception ex)
                    {
                        recorder.MarkFailed(ex);

                        throw;
                    }
                }
        }