예제 #1
0
        private async Task SendMessage(MonitorMessage message)
        {
            if (message.MessageType == MonitorMessageTypes.HttpRequest || message.MessageType == MonitorMessageTypes.ServiceBusReceiver)
            {
                var uri = MonitorHelper.GetUri(message.RequestAddress);

                var telemetryItem = new RequestTelemetry();
                telemetryItem.Context.Operation.Id       = message.Id;
                telemetryItem.Context.Operation.ParentId = message.CorrelationId;
                telemetryItem.Name      = $"{message.RequestMethod}-{uri.Authority}";
                telemetryItem.Timestamp = message.StartTime;
                telemetryItem.Duration  = message.Duration;
                telemetryItem.Success   = !message.IsError;

                telemetryItem.ResponseCode = message.ResponseCode;
                telemetryItem.Url          = uri;
                telemetryItem.Source       = message.ProcessName;

                SetTelemetryProperties(telemetryItem.Properties, message);

                _client.TrackRequest(telemetryItem);
            }
            else if (message.MessageType == MonitorMessageTypes.HttpClient || message.MessageType == MonitorMessageTypes.ServiceBusSender || message.MessageType == MonitorMessageTypes.GenericObjectSender)
            {
                var uri = MonitorHelper.GetUri(message.RequestAddress);

                var telemetryItem = new DependencyTelemetry();
                telemetryItem.Context.Operation.Id       = message.Id;
                telemetryItem.Context.Operation.ParentId = message.CorrelationId;
                telemetryItem.Name      = $"{message.RequestMethod}-{uri.Authority}";
                telemetryItem.Timestamp = message.StartTime;
                telemetryItem.Duration  = message.Duration;
                telemetryItem.Success   = !message.IsError;

                telemetryItem.ResultCode = message.ResponseCode;
                telemetryItem.Data       = message.RequestAddress;
                telemetryItem.Type       = message.CallType;
                telemetryItem.Target     = uri.Authority;

                SetTelemetryProperties(telemetryItem.Properties, message);

                _client.TrackDependency(telemetryItem);
            }
            else
            {
                var telemetryItem = new TraceTelemetry();
                telemetryItem.Context.Operation.Id       = message.Id;
                telemetryItem.Context.Operation.ParentId = message.CorrelationId;

                telemetryItem.Message       = $"{message.MessageType}-{message.RequestMethod}-{message.ProcessName}";
                telemetryItem.Timestamp     = message.StartTime;
                telemetryItem.SeverityLevel = message.IsError ? SeverityLevel.Error : SeverityLevel.Information;

                SetTelemetryProperties(telemetryItem.Properties, message);

                _client.TrackTrace(telemetryItem);
            }
        }
        private async Task SaveMessage(MonitorMessage monitorMessage)
        {
            var serializedBody = JsonConvert.SerializeObject(monitorMessage);
            var message        = new Message(Encoding.UTF8.GetBytes(serializedBody))
            {
                ContentType = "application/json"
            };

            await _messageSender.SendAsync(message);
        }
        private async Task SaveMessage(MonitorMessage message, DateTime now)
        {
            var folderName   = $"{message.CorrelationId}";
            var fileName     = $"{message.StartTime.ToString("yyyy-MM-dd-HH.mm.ss.ffff")}-{message.MessageType}-{message.RequestMethod}-{message.ProcessName}.json";
            var fullFileName = folderName + "/" + fileName;

            var blockBlob = this.cloudBlobContainer.GetBlockBlobReference(fullFileName);

            var payload = Newtonsoft.Json.JsonConvert.SerializeObject(message, Newtonsoft.Json.Formatting.Indented);

            await blockBlob.UploadTextAsync(payload);
        }
예제 #4
0
        public async Task <string> LogPayloadAsync(string correlationId, string payload, string extension = "txt")
        {
            var monitorMessage = new MonitorMessage()
            {
                CorrelationId  = correlationId,
                RequestBody    = payload,
                RequestAddress = "payload logger",
                MessageType    = MonitorMessageTypes.GenericObjectSender,
                RequestMethod  = "PAYLOADLOGGER"
            };

            await _monitorLogger.WriteMessage(monitorMessage);

            return("");
        }
예제 #5
0
 /// <summary>
 /// Write a message into message buffer
 /// </summary>
 /// <param name="message"></param>
 /// <returns></returns>
 public virtual async Task WriteMessage(MonitorMessage message)
 {
     if (message != null)
     {
         var contextMessages = GetContextMessages();
         if (contextMessages != null)
         {
             contextMessages.Add(message);
         }
         else
         {
             lock (_offlineMessages)
             {
                 _offlineMessages.Add(message);
             }
         }
     }
 }
예제 #6
0
        private void SetTelemetryProperties(IDictionary <string, string> properties, MonitorMessage message)
        {
            const int LIMIT = 8192;

            properties["CorrelationId"]                = message.CorrelationId;
            properties["RequestHeaders"]               = MonitorHelper.LimitString(JsonConvert.SerializeObject(message.RequestHeaders, Formatting.Indented), LIMIT);
            properties["ResponseHeaders"]              = MonitorHelper.LimitString(JsonConvert.SerializeObject(message.ResponseHeaders, Formatting.Indented), LIMIT);
            properties["RequestArchitectureMetadata"]  = $"{message.RequestArchitectureMetadata}";
            properties["ResponseArchitectureMetadata"] = $"{message.ResponseArchitectureMetadata}";
            properties["ProcessName"]  = message.ProcessName;
            properties["RequestBody"]  = MonitorHelper.LimitString(message.RequestBody, LIMIT);
            properties["RequestUser"]  = MonitorHelper.LimitString(message.RequestUser, LIMIT);
            properties["ResponseBody"] = MonitorHelper.LimitString(message.ResponseBody, LIMIT);
            if (!String.IsNullOrEmpty(message.ErrorMessage))
            {
                properties["ErrorMessage"] = MonitorHelper.LimitString(message.ErrorMessage, LIMIT);
            }
        }