/// <summary> Record a custom analytics event represented by a name and a list of key-value pairs. </summary> /// /// <exception cref="ArgumentNullException"> Thrown when <paramref name="eventType"/> or /// <paramref name="attributes"/> are null. </exception> /// /// <param name="eventType"> The name of the event to record. Only the first 255 characters (256 /// including the null terminator) are retained. </param> /// <param name="attributes"> The attributes to associate with this event. </param> public void RecordCustomEvent(string eventType, IEnumerable <KeyValuePair <string, object> > attributes) { eventType = eventType ?? throw new ArgumentNullException(nameof(eventType)); attributes = attributes ?? throw new ArgumentNullException(nameof(attributes)); using (new IgnoreWork()) { var transaction = TryGetCurrentInternalTransaction(); float priority = transaction?.Priority ?? _tracePriorityManager.Create(); _customEventTransformer.Transform(eventType, attributes, priority); } }
private IInternalTransaction CreateInternalTransaction(ITransactionName initialTransactionName, Action onCreate) { RemoveOutstandingInternalTransactions(true, true); var transactionContext = GetFirstActivePrimaryContext(); if (transactionContext == null) { Log.Error("Unable to locate a valid TransactionContext."); return(null); } var priority = _tracePriorityManager.Create(); var transaction = new Transaction(_configuration, initialTransactionName, _timerFactory.StartNewTimer(), DateTime.UtcNow, _callStackManagerFactory.CreateCallStackManager(), _databaseService, priority, _databaseStatementParser, _distributedTracePayloadHandler, _errorService, _attribDefSvc.AttributeDefs); try { transactionContext.SetData(transaction); } catch (Exception exception) { Log.Error($"The chosen TransactionContext threw an exception when setting the data: {exception}"); return(null); } if (Log.IsFinestEnabled) { transaction.LogFinest($"Created transaction on {transactionContext}"); } if (onCreate != null) { onCreate(); } return(transaction); }