public void SendEvent(MetricEvent metricEvent) { var routingKey = RoutingKey.TryAddSuffix(routingKeyPrefix, RoutingKey.AppEventsSuffix); if (airlockClient == null || string.IsNullOrEmpty(routingKey)) { return; } airlockClient.Push(routingKey, metricEvent, metricEvent.Timestamp); }
public async Task Invoke(HttpContext context) { try { totalCounter.Add(); log.Debug($"Request {context.Request.Method} {context.Request.Path}"); if (HttpMethods.IsGet(context.Request.Method)) { await context.Response.WriteAsync("Frontier is running"); } else if (HttpMethods.IsPost(context.Request.Method)) { var requestPath = context.Request.Path.Value; if (string.IsNullOrEmpty(requestPath)) { context.Response.StatusCode = (int)HttpStatusCode.NotFound; return; } var streamReader = new StreamReader(context.Request.Body); var body = await streamReader.ReadToEndAsync(); try { var reportHandler = reportHandlers.FirstOrDefault(x => x.CanHandle(requestPath)); if (reportHandler == null) { context.Response.StatusCode = (int)HttpStatusCode.NotFound; return; } var report = await reportHandler.Handle(context, body); var logEventData = report.ToLogEventData(); var routingKey = RoutingKey.Create(report.GetProject(), environment, "frontier_" + reportHandler.Name, RoutingKey.LogsSuffix); log.Debug("Send data via airlock to " + routingKey); airlockClient.Push(routingKey, logEventData, logEventData.Timestamp); context.Response.StatusCode = (int)HttpStatusCode.NoContent; } finally { if (resendTo != null) { await ResendRequest(context, body); } } } else if (HttpMethods.IsOptions(context.Request.Method)) { context.Response.StatusCode = (int)HttpStatusCode.NoContent; } } catch (Exception e) { errorCounter.Add(); log.Error(e); } }
private void PushToAirlock(IEnumerable <MetricEvent> metrics) { foreach (var metricEvent in metrics) { airlockClient.Push(metricsRoutingKey, metricEvent); } }
public void Log(LogEvent logEvent) { if (airlockClient == null || string.IsNullOrEmpty(routingKey)) { return; } var logEventData = new LogEventData { Timestamp = DateTimeOffset.UtcNow, // todo (spaceorc, 15.02.2018) возможно, надо сделать поле Timestamp в logEvent? Level = logEvent.Level, Message = LogEventFormatter.FormatMessage(logEvent.MessageTemplate, logEvent.MessageParameters), Exceptions = logEvent.Exception.Parse(), // todo (andrew, 17.01.2018): maybe truncate if serialized Exceptions list has size > 32 kb Properties = logEvent.Properties.ToDictionary(x => x.Key, x => x.Value.ToString()) }; // todo (spaceorc, 13.10.2017) make "host" constant somewhere in Vostok.Core/LogPropertyNames.cs logEventData.Properties["host"] = HostnameProvider.Get(); airlockClient.Push(routingKey, logEventData, logEventData.Timestamp); }