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); } } }
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 OnStart(Activity activity, HttpWebRequest request) { foreach (var trackedHeader in this._config.TrackedRequestHeaders) { var headerContent = request.Headers.Get(trackedHeader); if (headerContent != null) { activity.SetTag(OpenTelemetryAttributes.GetAttributeHttpRequestHeader(trackedHeader), headerContent); } } }
/// <summary> /// Record attributes from response /// </summary> /// <param name="response"></param> public void Record(OpenTelemetryAttributes response) { this.scope.AddAttribute(OpenTelemetryAttributeKeys.DbName, response.DatabaseName); this.scope.AddAttribute(OpenTelemetryAttributeKeys.ContainerName, response.ContainerName); this.scope.AddAttribute(OpenTelemetryAttributeKeys.RequestContentLength, response.RequestContentLength); this.scope.AddAttribute(OpenTelemetryAttributeKeys.ResponseContentLength, response.ResponseContentLength); this.scope.AddAttribute(OpenTelemetryAttributeKeys.StatusCode, response.StatusCode); this.scope.AddAttribute(OpenTelemetryAttributeKeys.RequestCharge, response.RequestCharge); this.scope.AddAttribute(OpenTelemetryAttributeKeys.ItemCount, response.ItemCount); this.scope.AddAttribute(OpenTelemetryAttributeKeys.Region, ClientTelemetryHelper.GetContactedRegions(response.Diagnostics)); if (this.IsEnabled && DiagnosticsFilterHelper.IsAllowed( latency: response.Diagnostics.GetClientElapsedTime(), statuscode: response.StatusCode)) { this.scope.AddAttribute(OpenTelemetryAttributeKeys.RequestDiagnostics, response.Diagnostics); } }
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); } } }
private async Task <TResult> RunWithDiagnosticsHelperAsync <TResult>( ITrace trace, Func <ITrace, Task <TResult> > task, Func <TResult, OpenTelemetryAttributes> openTelemetry, string operationName) { using (OpenTelemetryCoreRecorder recorder = OpenTelemetryRecorderFactory.CreateRecorder( operationName: operationName, isFeatureEnabled: this.clientOptions.EnableOpenTelemetry)) using (new ActivityScope(Guid.NewGuid())) { try { TResult result = await task(trace).ConfigureAwait(false); if (openTelemetry != null && recorder.IsEnabled) { // Record client and other information recorder.Record(operationName, this); // Record request response information OpenTelemetryAttributes response = openTelemetry(result); recorder.Record(response); } return(result); } catch (OperationCanceledException oe) when(!(oe is CosmosOperationCanceledException)) { CosmosOperationCanceledException operationCancelledException = new CosmosOperationCanceledException(oe, trace); recorder.MarkFailed(operationCancelledException); throw operationCancelledException; } catch (ObjectDisposedException objectDisposed) when(!(objectDisposed is CosmosObjectDisposedException)) { CosmosObjectDisposedException objectDisposedException = new CosmosObjectDisposedException( objectDisposed, this.client, trace); recorder.MarkFailed(objectDisposedException); throw objectDisposedException; } catch (NullReferenceException nullRefException) when(!(nullRefException is CosmosNullReferenceException)) { CosmosNullReferenceException nullException = new CosmosNullReferenceException( nullRefException, trace); recorder.MarkFailed(nullException); throw nullException; } catch (Exception ex) { recorder.MarkFailed(ex); throw; } } }