コード例 #1
0
 public void EnrichWithResponse(Activity activity, HttpResponseHeaders responseHeaders)
 {
     foreach (var trackedHeader in this._config.TrackedResponseHeaders)
     {
         if (responseHeaders.TryGetHeaderAsString(trackedHeader, out var headerContent))
         {
             activity.SetTag(OpenTelemetryAttributes.GetAttributeHttpResponseHeader(trackedHeader),
                             headerContent);
         }
     }
 }
コード例 #2
0
 private void EnrichWithResponseHeaders(Activity activity, WebHeaderCollection headers)
 {
     foreach (var trackedHeader in this._config.TrackedResponseHeaders)
     {
         var headerContent = headers.Get(trackedHeader);
         if (headerContent != null)
         {
             activity.SetTag(OpenTelemetryAttributes.GetAttributeHttpResponseHeader(trackedHeader),
                             headerContent);
         }
     }
 }
        public void Enrich(Activity activity, string eventName, object rawObject)
        {
            if (eventName.Equals("OnStartActivity"))
            {
                if (!(rawObject is HttpWebRequest request))
                {
                    return;
                }

                if (request.ContentLength > 0)
                {
                    activity.SetTag(OpenTelemetryAttributes.GetAttributeHttpRequestHeader("content_length"),
                                    request.ContentLength);
                }

                foreach (var enrichHook in this._enrichHooks)
                {
                    enrichHook.OnStart(activity, request);
                }
            }
            else if (eventName.Equals("OnStopActivity"))
            {
                if (!(rawObject is HttpWebResponse response))
                {
                    return;
                }

                if (response.ContentLength > 0)
                {
                    activity.SetTag(OpenTelemetryAttributes.GetAttributeHttpResponseHeader("content_length"),
                                    response.ContentLength);
                }

                if (TracingUtils.IsErrorStatusCode((int)response.StatusCode))
                {
                    activity.SetTag("error", "true");
                }

                foreach (var enrichHook in this._enrichHooks)
                {
                    enrichHook.OnSuccessEnd(activity, response);
                }
            }
            else if (eventName.Equals("OnException"))
            {
                if (!(rawObject is WebException ex))
                {
                    return;
                }

                activity.SetTag("error", "true");
                var statusCode = (ex.Response as HttpWebResponse)?.StatusCode;
                if (statusCode == null)
                {
                    activity.SetTag(OpenTelemetryAttributes.AttributeHttpStatusCode, "-");
                    activity.SetTag(OpenTelemetryAttributes.AttributeHttpClientException, ex.Status.ToString());
                }

                foreach (var enrichHook in this._enrichHooks)
                {
                    enrichHook.OnError(activity, ex);
                }
            }
        }