コード例 #1
0
        public void TransformSpans(LambdaRootSpan rootSpan)
        {
            lock (_spanReservoirLock)
            {
                // Record errors after root span has finished. By now, txn name has been set
                foreach (LambdaSpan lambdaSpan in _spanReservoir)
                {
                    _errors.RecordErrors(lambdaSpan);
                }

                var arnTag = rootSpan.GetTag("aws.arn");
                var arn    = (arnTag as string) ?? "";

                LinkedList <Event> spans;
                // Do not collect Spans if sampled=false, clear reservoir and set spans to empty list
                if (rootSpan.PrioritySamplingState.Sampled)
                {
                    spans = _spanReservoir;
                }
                else
                {
                    spans = new LinkedList <Event>();
                }

                _spanReservoir = new LinkedList <Event>();
                TransactionEvent txnEvent = new TransactionEvent(rootSpan);
                var errorEvents           = _errors.GetAndClearEvents();
                var errorTraces           = _errors.GetAndClearTraces();
                WriteData(arn, _executionEnv, spans.ToList(), txnEvent, errorEvents, errorTraces);
            }
        }
コード例 #2
0
 internal TransactionEventTimelineMessage(DbConnection connection, Guid connectionId, Guid transactionId, TransactionEvent transactionEvent)
 {
     TransactionId    = transactionId;
     ConnectionId     = connectionId;
     Database         = connection.Database;
     TransactionEvent = transactionEvent;
 }
コード例 #3
0
        public async Task <Response> Handle(PublishTransaction request, CancellationToken cancellationToken)
        {
            var @event = new TransactionEvent(request.AccountId, request.Date, request.Value, request.Type);
            await _publisher.PublishAsync(@event);

            return(new Response());
        }
コード例 #4
0
 internal TransactionEventTimeline(IInspectorContext context, DbConnection connection, Guid connectionId, Guid transactionId, TransactionEvent transactionEvent)
     : base(context)
 {
     _connection       = connection;
     _connectionId     = connectionId;
     _transactionId    = transactionId;
     _transactionEvent = transactionEvent;
 }
コード例 #5
0
        private bool ConsumeEvent(TransactionEvent message)
        {
            var result = _mediator.Send(new CreateTransaction(message)).Result;

            _logger.LogInformation($"Processado..");

            return(result.Valid);
        }
コード例 #6
0
 private void FillBaseEventPropertiesFromRecord(TransactionEvent te, NpgsqlDataReader reader)
 {
     te.LoggedAt      = reader.GetDateTime(1);
     te.OccuredAt     = reader.GetDateTime(2);
     te.TransactionId = reader.GetInt32(4);
     te.UserId        = (reader.IsDBNull(5)) ? null : reader.GetString(5);
     te.Service       = reader.GetString(6);
     te.Server        = reader.GetString(7);
 }
コード例 #7
0
        public async Task Append(int expectedVersion, TransactionEvent transactionEvent)
        {
            var evts    = (await ReadAll(transactionEvent.AccountId)).ToArray();
            var version = evts.Length;

            /*
             * Using the length of the evts array as the version number.
             * In event sourcing you need to know what the version is to make
             * sure someone else hasn't updated the store before you.
             * Remember we are in an eventually consistent environment so
             * things are going to change. Historically, database philosophy
             * was all pessimistic, you can even do Google search and read
             * about adlock pessimistic and what it means. Essentially,
             * consistency was king, you made certain as far as possible that
             * updates were serialised one after the other in order. We are now
             * in the 2020's that likes of Amazon have turned that paradigm
             * pretty much completely up-side-down. Consistency is important
             * but instantaneous is no longer required (most of the time).
             */
            if (version != expectedVersion)
            {
                throw new Exception("Versions don't match");
            }


            // In the real world of course, we would require customers to perform
            // all manner of checks to create an account. Here we just create one
            // as it is not part of the current demonstration.
            if (!events.ContainsKey(transactionEvent.AccountId))
            {
                events.TryAdd(transactionEvent.AccountId, new List <TransactionEvent>());
            }

            /*
             * Here we can perform a check to make sure we don't add the same
             * event to the store twice for a particular account. Use the
             * correlation id here, but add by the account id.
             */
            throw new NotImplementedException("You must implement persisting of an event...");
            if (false)
            {
                // append the event here:



                // Now you can trigger other actions, if necessary (there aren't any required in our program):
            }
        }
コード例 #8
0
        // Write all the payload data to the console using standard out. This is the only method that should call the Logger#out method.
        private void WriteData(string arn, string executionEnv, IList <Event> spans, TransactionEvent txnEvent, IList <ErrorEvent> errorEvents, IList <ErrorTrace> errorTraces)
        {
            var metadata = ProtocolUtil.GetMetadata(arn, executionEnv);
            var data     = ProtocolUtil.GetData(spans, txnEvent, errorEvents, errorTraces);

            var payload = new List <object> {
                2, "NR_LAMBDA_MONITORING", metadata, ProtocolUtil.CompressAndEncode(JsonConvert.SerializeObject(data))
            };

            _logger.Log(JsonConvert.SerializeObject(payload));
            var debug = Environment.GetEnvironmentVariable("NEW_RELIC_DEBUG_MODE");

            if (_debugMode)
            {
                _logger.Log(JsonConvert.SerializeObject(data));
            }
        }
コード例 #9
0
            public static TransactionEvent CreateFromXml( System.Xml.XmlElement n)
            {
                TransactionEvent e = new TransactionEvent();

                e.ikey = n.GetAttribute("ikey");
                e.val = n.GetAttribute("value");

                return e;
            }
コード例 #10
0
 internal static TransactionEventTimeline CreateEventTimeline(DbConnection connection, Guid connectionId, Guid transactionId, TransactionEvent transactionEvent)
 {
     return new TransactionEventTimeline(_context, connection, connectionId, transactionId, transactionEvent);
 }