private void AddExecutionContextDetails( IOrganizationService service, IExecutionContext executionContext, int?pluginStage, int?workflowCategory) { this.EventProperties.ImpersonatingUserId = executionContext.UserId.ToString(); this.EventProperties.CorrelationId = executionContext.CorrelationId.ToString(); this.EventProperties.Message = executionContext.MessageName; this.EventProperties.Mode = AiProperties.GetModeName(executionContext.Mode); this.EventProperties.Depth = executionContext.Depth; this.EventProperties.InputParameters = this.TraceParameters(true, service, executionContext); this.EventProperties.OutputParameters = this.TraceParameters(false, service, executionContext); this.EventProperties.OperationId = executionContext.OperationId.ToString(); this.EventProperties.OperationCreatedOn = executionContext.OperationCreatedOn.ToUniversalTime() .ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'"); this.EventProperties.OrganizationId = executionContext.OrganizationId.ToString(); if (pluginStage != null) { var stage = pluginStage.Value; this.AddPluginExecutionContextDetails(stage, executionContext as IPluginExecutionContext); } if (workflowCategory != null) { var category = workflowCategory.Value; this.AddWorkflowExecutionContextDetails(category); } }
private void SetupAiLogger( AiConfig aiConfig, IOrganizationService service, ITracingService tracingService, IExecutionContext executionContext, int?pluginStage, int?workflowCategory) { this._instrumentationKey = aiConfig.InstrumentationKey; this._loggingEndpoint = aiConfig.AiEndpoint; this._disableTraceTracking = aiConfig.DisableTraceTracking; this._disableExceptionTracking = aiConfig.DisableExceptionTracking; this._disableDependencyTracking = aiConfig.DisableDependencyTracking; this._disableEventTracking = aiConfig.DisableEventTracking; this._disableMetricTracking = aiConfig.DisableMetricTracking; this._enableDebug = aiConfig.EnableDebug; this._percentLoggedTrace = aiConfig.PercentLoggedTrace; this._percentLoggedMetric = aiConfig.PercentLoggedMetric; this._percentLoggedEvent = aiConfig.PercentLoggedEvent; this._percentLoggedException = aiConfig.PercentLoggedException; this._percentLoggedDependency = aiConfig.PercentLoggedDependency; var disableContextParameterTracking = aiConfig.DisableContextParameterTracking; this._authenticatedUserId = executionContext.InitiatingUserId.ToString(); this._tracingService = tracingService; _httpClient = HttpHelper.GetHttpClient(); this.EventProperties = new AiProperties(); this.AddPrimaryPropertyValues(executionContext, service); if (!disableContextParameterTracking) { this.AddExecutionContextDetails(service, executionContext, pluginStage, workflowCategory); } }
/// <summary> /// Initializes a new instance of the <see cref="AiDependency"/> class. /// </summary> /// <param name="properties">The D365 specific AI properties.</param> /// <param name="name">The dependency name or absolute URL.</param> /// <param name="method">The HTTP method (only logged with URL).</param> /// <param name="type">The type of dependency (Ajax, HTTP, SQL, etc.).</param> /// <param name="duration">he duration in ms of the dependent event.</param> /// <param name="resultCode">The result code, HTTP or otherwise.</param> /// <param name="success">Set to <c>true</c> if the dependent event was successful, <c>false</c> otherwise.</param> /// <param name="data">Any other data associated with the dependent event (ignored with URL).</param> public AiDependency(AiProperties properties, string name, string method, string type, int duration, int?resultCode, bool success, string data) { Uri uri = CreateUri(name); if (uri != null) { method = method.ToUpper(); Name = !string.IsNullOrEmpty(method) ? $"{method} {uri.AbsolutePath}" : uri.AbsolutePath; Data = name; Target = uri.Host; } else { Name = name; Data = data; Target = null; } if (Name.Length > 512) { Name = Name.Substring(0, 511); } Id = LogHelper.GenerateNewId(); ResultCode = resultCode; Duration = duration; Success = success; Type = type; Properties = properties; }
/// <summary> /// Initializes a new instance of the <see cref="AiEvent"/> class. /// </summary> /// <param name="properties">The D365 specific AI properties.</param> /// <param name="name">The event name.</param> public AiEvent(AiProperties properties, string name) { Name = name.Length > 512 ? name.Substring(0, 511) : name; Properties = properties; }
/// <summary> /// Initializes a new instance of the <see cref="AiTrace"/> class. /// </summary> /// <param name="properties">The D365 specific AI properties.</param> /// <param name="message">The trace message.</param> /// <param name="aiTraceSeverity">The severity level <see cref="AiTraceSeverity"/>.</param> public AiTrace(AiProperties properties, string message, AiTraceSeverity aiTraceSeverity) { Message = message.Length > 32768 ? message.Substring(0, 32767) : message; SeverityLevel = aiTraceSeverity; Properties = properties; }
private void AddPluginExecutionContextDetails(int stage, IPluginExecutionContext executionContext) { this.EventProperties.Source = "Plug-in"; this.EventProperties.Stage = AiProperties.GetStageName(stage); if (executionContext == null) { return; } this.EventProperties.ParentCorrelationId = (executionContext?.ParentContext?.CorrelationId ?? executionContext?.CorrelationId).ToString(); // this.AddPluginExecutionHistory(executionContext); }
private void AddPluginExecutionHistory(IPluginExecutionContext executionContext) { // This doesn't work... need to figure out something that can work here. DateTime?end = null; if (!executionContext.SharedVariables.ContainsKey("StartedOn")) { executionContext.SharedVariables.Add("StartedOn", DateTime.UtcNow); } else { end = (DateTime?)executionContext.SharedVariables["StartedOn"]; } var past = new Stack <AiPluginProperties>(); if (this.EventProperties.Depth > 1) { var currentContext = executionContext; var last = currentContext; while (currentContext != null) { past.Push( new AiPluginProperties { OperationId = currentContext.OperationId.ToString(), ImpersonatingUserId = currentContext.UserId.ToString(), CorrelationId = currentContext.CorrelationId.ToString(), Message = currentContext.MessageName, Mode = AiProperties.GetModeName(currentContext.Mode), Depth = currentContext.Depth, EntityId = currentContext.PrimaryEntityId.ToString(), EntityName = currentContext.PrimaryEntityName, Stage = AiProperties.GetStageName(currentContext.Stage), ParentCorrelationId = currentContext.ParentContext?.CorrelationId.ToString(), OperationCreatedOn = currentContext.OperationCreatedOn.ToUniversalTime() .ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'") }); last = currentContext; currentContext = currentContext.ParentContext; } var span = DateTime.UtcNow - (end ?? last.OperationCreatedOn.ToUniversalTime()); this.WriteMetric("BackendDuration", span.TotalMilliseconds); this.EventProperties.History = past.ToArray(); this.EventProperties.Duration = span.TotalMilliseconds.ToString(); } }
private void AddExecutionContextDetails(IExecutionContext executionContext, int?pluginStage, int?workflowCategory) { _eventProperties.ImpersonatingUserId = executionContext.UserId.ToString(); _eventProperties.CorrelationId = executionContext.CorrelationId.ToString(); _eventProperties.Message = executionContext.MessageName; _eventProperties.Mode = AiProperties.GetModeName(executionContext.Mode); _eventProperties.Depth = executionContext.Depth; _eventProperties.InputParameters = TraceParameters(true, executionContext); _eventProperties.OutputParameters = TraceParameters(false, executionContext); if (pluginStage != null) { int stage = pluginStage.Value; AddPluginExecutionContextDetails(stage); } if (workflowCategory != null) { int category = workflowCategory.Value; AddWorkflowExecutionContextDetails(category); } }
private void AddPluginExecutionContextDetails(int stage) { _eventProperties.Source = "Plug-in"; _eventProperties.Stage = AiProperties.GetStageName(stage); }