Example #1
0
        private void HandleStopCommand(object payloadData, PropertyFetcherSet propertyFetcherSet)
        {
            try
            {
                if (propertyFetcherSet.StopCorrelationId.Fetch(payloadData) is Guid operationId &&
                    propertyFetcherSet.StopCommand.Fetch(payloadData) is IDbCommand dbCommand)
                {
                    if (!_spans.TryRemove(operationId, out var span))
                    {
                        return;
                    }

                    TimeSpan?duration = null;

                    if (propertyFetcherSet.Statistics.Fetch(payloadData) is IDictionary <object, object> statistics &&
                        statistics.ContainsKey("ExecutionTime") && statistics["ExecutionTime"] is long durationInMs)
                    {
                        duration = TimeSpan.FromMilliseconds(durationInMs);
                    }

                    DbSpanCommon.EndSpan(span, dbCommand, duration);
                }
            }
            catch (Exception ex)
            {
                // ignore
                _logger.Error()?.LogException(ex, "Exception was thrown while handling 'command succeeded event'");
            }
        }
Example #2
0
        private void HandleErrorCommand(object payloadData, PropertyFetcherSet propertyFetcherSet)
        {
            try
            {
                if (propertyFetcherSet.ErrorCorrelationId.Fetch(payloadData) is Guid operationId)
                {
                    if (!_spans.TryRemove(operationId, out var span))
                    {
                        return;
                    }

                    if (propertyFetcherSet.Exception.Fetch(payloadData) is Exception exception)
                    {
                        span.CaptureException(exception);
                    }

                    if (propertyFetcherSet.ErrorCommand.Fetch(payloadData) is IDbCommand dbCommand)
                    {
                        DbSpanCommon.EndSpan(span, dbCommand);
                    }
                    else
                    {
                        _logger.Warning()?.Log("Cannot extract database command from {PayloadData}", payloadData);
                        span.End();
                    }
                }
            }
            catch (Exception ex)
            {
                // ignore
                _logger.Error()?.LogException(ex, "Exception was thrown while handling 'command failed event'");
            }
        }
            private void DoEndSpan <TResult>(IDbCommand command, DbCommandInterceptionContext <TResult> interceptCtx, string dbgOriginalCaller)
            {
                var span = (Span)interceptCtx.FindUserState(_userStateKey);

                if (span == null)
                {
                    _logger.Debug()
                    ?.Log("Span is not found in DbCommandInterceptionContext's UserState"
                          + " - skipping ending the corresponding span for DB-operation-ended event");
                    return;
                }

                LogEvent("DB operation ended - ending the corresponding span...", command, interceptCtx, dbgOriginalCaller);

                DbSpanCommon.EndSpan(span, command);
            }