Example #1
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)
                    {
                        _apmAgent.TracerInternal.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'");
            }
        }
Example #2
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 && durationInMs > 0)
                    {
                        duration = TimeSpan.FromMilliseconds(durationInMs);
                    }

                    _apmAgent.TracerInternal.DbSpanCommon.EndSpan(span, dbCommand, duration);
                }
            }
            catch (Exception ex)
            {
                // ignore
                _logger.Error()?.LogException(ex, "Exception was thrown while handling 'command succeeded event'");
            }
        }
Example #3
0
 private void HandleStartCommand(object payloadData, PropertyFetcherSet propertyFetcherSet)
 {
     try
     {
         if (propertyFetcherSet.StartCorrelationId.Fetch(payloadData) is Guid operationId &&
             propertyFetcherSet.StartCommand.Fetch(payloadData) is IDbCommand dbCommand)
         {
             var span = _apmAgent.TracerInternal.DbSpanCommon.StartSpan(_apmAgent, dbCommand);
             _spans.TryAdd(operationId, span);
         }
     }
     catch (Exception ex)
     {
         //ignore
         _logger.Error()?.LogException(ex, "Exception was thrown while handling 'command started event'");
     }
 }