コード例 #1
0
        public async Task Invoke(HttpContext context)
        {
            using (var spanBuilder = Trace.BeginSpan())
            {
                var url = GetUrl(context.Request);
                spanBuilder.SetAnnotation(TracingAnnotationNames.Operation, GetOperationName(context.Request.Method, url));
                spanBuilder.SetAnnotation(TracingAnnotationNames.Kind, "http-server");
                spanBuilder.SetAnnotation(TracingAnnotationNames.Service, serviceName);
                spanBuilder.SetAnnotation(TracingAnnotationNames.Host, HostnameProvider.Get());
                spanBuilder.SetAnnotation(TracingAnnotationNames.HttpUrl, url.ToStringWithoutQuery());
                if (context.Request.ContentLength.HasValue)
                {
                    spanBuilder.SetAnnotation(TracingAnnotationNames.HttpRequestContentLength, context.Request.ContentLength);
                }

                try
                {
                    await next.Invoke(context).ConfigureAwait(false);

                    if (context.Response.ContentLength.HasValue)
                    {
                        spanBuilder.SetAnnotation(TracingAnnotationNames.HttpResponseContentLength, context.Response.ContentLength);
                    }
                    spanBuilder.SetAnnotation(TracingAnnotationNames.HttpCode, context.Response.StatusCode);
                }
                catch
                {
                    spanBuilder.SetAnnotation(TracingAnnotationNames.HttpCode, (int)HttpStatusCode.InternalServerError);
                    context.Response.StatusCode = 500;
                }
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public void Emit(SerilogEvent logEvent)
        {
            var airlockClient = getAirlockClient();
            var routingKey    = getRoutingKey();

            if (airlockClient == null || string.IsNullOrEmpty(routingKey))
            {
                return;
            }
            var logEventData = new LogEventData
            {
                Timestamp  = logEvent.Timestamp,
                Level      = TranslateLevel(logEvent.Level),
                Message    = logEvent.MessageTemplate.Render(logEvent.Properties).Truncate(maxMessageLength),
                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);
        }
コード例 #4
0
 private void EnrichWithHostname()
 {
     SetTag(MetricsTagNames.Host, HostnameProvider.Get());
 }