public override bool TryPopulate(Envelope envelope, ref AnalyticsItem analyticsItem) { if (!(envelope.EventData is MessageData messageData)) { return(false); } analyticsItem.MessageItem = new MessageItem(); analyticsItem.MessageItem.Message = messageData.Message; analyticsItem.MessageItem.Severity = messageData.SeverityLevel; if (messageData.Properties.TryGetValue("DeveloperMode", out string developerModeValue) && bool.TryParse(developerModeValue, out bool isDeveloperMode)) { analyticsItem.MessageItem.IsDeveloperMode = isDeveloperMode; } if (messageData.Properties.TryGetValue("AspNetCoreEnvironment", out string environmentName)) { analyticsItem.MessageItem.Environment = environmentName; } if (messageData.Properties.TryGetValue("CategoryName", out string categoryName)) { analyticsItem.MessageItem.Category = categoryName; } return(!string.IsNullOrWhiteSpace(analyticsItem.MessageItem.Message)); }
public void Register(object analyticsInstance) { AnalyticsItem analyticsItem = null; if (analyticsInstance is IIndicatorCore) { analyticsItem = new AnalyticsItem(AnalyticsTypeOption.Indicator, analyticsInstance); analyticsItem.Initialize(); registeredAnalytics.Add(analyticsItem); } if (analyticsInstance is ISignal) { analyticsItem = new AnalyticsItem(AnalyticsTypeOption.Signal, analyticsInstance); analyticsItem.Initialize(); registeredAnalytics.Add(analyticsItem); } if (analyticsInstance is IStrategy) { analyticsItem = new AnalyticsItem(AnalyticsTypeOption.Strategy, analyticsInstance); analyticsItem.Initialize(); registeredAnalytics.Add(analyticsItem); } }
public override bool TryPopulate(Envelope envelope, ref AnalyticsItem analyticsItem) { if (!(envelope.EventData is RequestData requestData)) { return(false); } analyticsItem.RequestItem = new RequestItem(); analyticsItem.RequestItem.Name = requestData.Name; if (requestData.Properties.TryGetValue("DeveloperMode", out string developerModeValue) && bool.TryParse(developerModeValue, out bool isDeveloperMode)) { analyticsItem.RequestItem.IsDeveloperMode = isDeveloperMode; } if (requestData.Properties.TryGetValue("AspNetCoreEnvironment", out string environment)) { analyticsItem.RequestItem.Environment = environment; } analyticsItem.RequestItem.IsSuccess = requestData.IsSuccess; analyticsItem.RequestItem.Name = requestData.Name; analyticsItem.RequestItem.Duration = requestData.DurationInMilliseconds; if (int.TryParse(requestData.ResponseCode, out int responseCode)) { analyticsItem.RequestItem.ResponseCode = responseCode; } analyticsItem.RequestItem.Url = requestData.Url; return(true); }
internal static bool TryPopulateItem(Envelope envelope, out AnalyticsItem analyticsItem) { analyticsItem = null; if (null == envelope) { return(false); } analyticsItem = new AnalyticsItem(); analyticsItem.InstrumentationKey = envelope.InstrumentationKey; analyticsItem.Timestamp = envelope.EventDate; if (envelope.Tags.TryGetValue("ai.location.ip", out string ip)) { analyticsItem.Ip = ip; } if (envelope.Tags.TryGetValue("ai.operation.id", out string operationId)) { analyticsItem.OperationId = operationId; } if (envelope.Tags.TryGetValue("ai.operation.parentId", out string parentOperationId)) { analyticsItem.ParentOperationId = parentOperationId; } if (envelope.Tags.TryGetValue("ai.cloud.roleInstance", out string roleInstance)) { analyticsItem.RoleInstance = roleInstance; } if (envelope.Tags.TryGetValue("ai.internal.sdkVersion", out string sdkVersion)) { analyticsItem.SdkVersion = sdkVersion; } if (envelope.Tags.TryGetValue("ai.application.ver", out string appVersion)) { analyticsItem.ApplicationVersion = appVersion; } if (envelope.Tags.TryGetValue("ai.user.id", out string userId)) { analyticsItem.UserId = userId; } if (envelope.Tags.TryGetValue("ai.user.accountId", out string userAccountId)) { analyticsItem.UserAccountId = userAccountId; } if (envelope.Tags.TryGetValue("ai.user.authUserId", out string authenticatedUserId)) { analyticsItem.AuthenticatedUserId = authenticatedUserId; } analyticsItem.Type = envelope.Name.Substring(1 + envelope.Name.LastIndexOf('.')); return(true); }
public override bool TryPopulate(Envelope envelope, ref AnalyticsItem analyticsItem) { if (!(envelope.EventData is ExceptionData exceptionData)) { return(false); } if (null == exceptionData.Exceptions || 0 == exceptionData.Exceptions.Count) { return(false); } foreach (var exceptionDetails in exceptionData.Exceptions) { ExceptionItem exceptionItem = new ExceptionItem(); if (exceptionData.Properties.TryGetValue("RequestId", out string requestId)) { exceptionItem.RequestId = requestId; } if (exceptionData.Properties.TryGetValue("CategoryName", out string categoryName)) { exceptionItem.Category = categoryName; } if (exceptionData.Properties.TryGetValue("RequestPath", out string path)) { exceptionItem.Path = path; } if (exceptionData.Properties.TryGetValue("ConnectionId", out string connectionId)) { exceptionItem.ConnectionId = connectionId; } if (exceptionData.Properties.TryGetValue("FormattedMessage", out string message)) { exceptionItem.Message = message; } if (exceptionData.Properties.TryGetValue("EventName", out string eventName)) { exceptionItem.Name = eventName; } exceptionItem.ExceptionId = exceptionDetails.Id; exceptionItem.ExceptionMessage = exceptionDetails.Message; exceptionItem.ExceptionType = exceptionDetails.TypeName; if (null != exceptionDetails.ParsedStack && 0 < exceptionDetails.ParsedStack.Count) { exceptionItem.StackTrace = string.Join(Environment.NewLine, exceptionDetails.ParsedStack.Select(s => s.ToString())); } analyticsItem.Exceptions.Add(exceptionItem); } return(true); }
/// <summary> /// Send through an analytics item over to segment /// </summary> /// <param name="analyticsItem">An analytics object that determines what type of data you're sending</param> /// <returns>HttpResponseMessage based on how the transaction went</returns> public override async Task <HttpResponseMessage> SendData(AnalyticsItem analyticsItem) { var json = ConvertAnalyticsItemToJson(analyticsItem); var content = new StringContent(json, Encoding.UTF8, "application/json"); using var client = new HttpClient(); var encoded = CreateEncodedWriteKey(); client.DefaultRequestHeaders.Add("Authorization", $"Basic {encoded}"); return(await client.PostAsync($"{_endpoint.GetURL()}{analyticsItem.type}", content)); }
/// <summary> /// Converts the analytics item into a json string. Checks the size of the content being passed. /// </summary> /// <param name="analyticsItem">The item being sent to segment</param> /// <returns>A string conversion of the analytics item</returns> /// <exception cref="SegmentHelperException">Thrown if the size of the content is larger than 32kb (based on segment requirements)</exception> private string ConvertAnalyticsItemToJson(AnalyticsItem analyticsItem) { var json = JsonConvert.SerializeObject(analyticsItem, Formatting.None, _jsonSerializerSettings); var contentSize = json.Length * sizeof(Char); if (contentSize >= SegmentConstants.MAX_SEND_SIZE_IN_BYTES) { throw new SegmentHelperException( $"Analytics item {analyticsItem} was too large to send (Content: {contentSize}, Max: {SegmentConstants.MAX_SEND_SIZE_IN_BYTES}.)" + $"Consider splitting the data into multiple objects and sending them through a batch call."); } return(json); }
public void RefreshStats() { //vedo - async Application.Current.Dispatcher.BeginInvoke((Action)(() => { SecurityScoreDataCount(); var scLog = inAppAnalyitics.Get <Events.AnalyticsLog, AnalyticsItem>(); var item = new AnalyticsItem(Convert.ToInt32(_securityScoreDecimal), DuplicatePasswordCounter, WeakPasswordCounter, OldPasswordCounter, SecurityScoreDataHelper.GetSecurityScoreData(SecurityScoreItemType.all).Count()); scLog.Log(item); })); }
public void Enqueue(AnalyticsItem analyticsItem) { if (null == analyticsItem) { return; } if (this.Items.IsCompleted) { return; } if (!this.Items.TryAdd(analyticsItem, 50)) { this.Logger.LogWarning("Failed to queue analytics item."); } }
public override bool TryPopulate(Envelope envelope, ref AnalyticsItem analyticsItem) { if (!(envelope.EventData is AvailabilityData availabilityData)) { return(false); } AvailabilityItem availabilityItem = new AvailabilityItem(); availabilityItem.Duration = availabilityData.Duration; availabilityItem.Message = availabilityData.Message; availabilityItem.Name = availabilityData.Name; availabilityItem.Success = availabilityData.Success; if (availabilityData.Properties.TryGetValue("AspNetCoreEnvironment", out string environment)) { availabilityItem.Environment = environment; } analyticsItem.AvailabilityItem = availabilityItem; return(true); }
public override bool TryPopulate(Envelope envelope, ref AnalyticsItem analyticsItem) { if (!(envelope.EventData is MetricData metricData)) { return(false); } if (null == metricData.Metrics || 0 == metricData.Metrics.Count) { return(false); } foreach (var metric in metricData.Metrics) { MetricItem metricItem = new MetricItem() { Kind = metric.Kind, Maximum = metric.Maximum ?? 0, Minimum = metric.Minimum ?? 0, SampleRate = envelope.SampleRate, StandardDeviation = metric.StandardDeviation ?? 0, Value = metric.Value, Name = metric.Name, Count = metric.Count ?? 0 }; if (!string.IsNullOrWhiteSpace(metricItem.Name) && -1 < metricItem.Name.IndexOf('\\')) { metricItem.NormalizedName = metricItem.Name.Substring(1 + metricItem.Name.LastIndexOf('\\')); } else { metricItem.NormalizedName = metricItem.Name; } analyticsItem.Metrics.Add(metricItem); } return(true); }
public override bool TryPopulate(Envelope envelope, ref AnalyticsItem analyticsItem) { if (!(envelope.EventData is EventData eventData)) { return(false); } EventItem eventItem = new EventItem(); eventItem.Name = eventData.Name; if (eventData.Properties.TryGetValue("DeveloperMode", out string developerModeValue) && bool.TryParse(developerModeValue, out bool isDeveloperMode)) { eventItem.IsDeveloperMode = isDeveloperMode; } if (eventData.Properties.TryGetValue("AspNetCoreEnvironment", out string environment)) { eventItem.Environment = environment; } analyticsItem.Events.Add(eventItem); return(true); }
private void UpdateIndicatorCache(DateTime timeKey, AnalyticsItem analyticsItem) { object[] values = new object[analyticsItem.PlottingMethods.Count]; int index = 0; int nanCount = 0; foreach (MethodInfo method in analyticsItem.PlottingMethods.Values) { double result = (double)method.Invoke(analyticsItem.Instance, zeroParamObject); values[index] = result; if (double.IsNaN(result)) { nanCount++; } index++; } if (nanCount != index) { analyticsItem.CachedIndicatorAppender.Append(timeKey, values); } }
public override bool TryPopulate(Envelope envelope, ref AnalyticsItem analyticsItem) { if (!(envelope.EventData is RemoteDependencyData dependencyData)) { return(false); } DependencyItem dependencyItem = new DependencyItem(); dependencyItem.Name = dependencyData.Name; dependencyItem.Duration = dependencyData.DurationInMilliseconds; dependencyItem.IsSuccess = dependencyData.IsSuccess; dependencyItem.Type = dependencyData.Type; dependencyItem.Target = dependencyData.Target; if (dependencyData.Properties.TryGetValue("DeveloperMode", out string developerModeValue) && bool.TryParse(developerModeValue, out bool isDeveloperMode)) { dependencyItem.IsDeveloperMode = isDeveloperMode; } if (dependencyData.Properties.TryGetValue("AspNetCoreEnvironment", out string environment)) { dependencyItem.Environment = environment; } if (dependencyData.Properties.TryGetValue("Input", out string input)) { dependencyItem.Input = input; } if (dependencyData.Properties.TryGetValue("Output", out string output)) { dependencyItem.Output = output; } analyticsItem.Dependencies.Add(dependencyItem); return(true); }
public abstract bool TryPopulate(Envelope envelope, ref AnalyticsItem analyticsItem);
public bool TryGetNext(int millisecondsTimeout, out AnalyticsItem analyticsItem) { return(this.Items.TryTake(out analyticsItem, millisecondsTimeout)); }
public abstract Task <HttpResponseMessage> SendData(AnalyticsItem analyticsItem);