/// <summary> /// Processes Begin request by starting subsegment. /// </summary> private void ProcessBeginRequest(IExecutionContext executionContext) { var request = executionContext.RequestContext.Request; Entity entity = null; try { entity = _recorder.GetEntity(); } catch (EntityNotAvailableException e) { _recorder.TraceContext.HandleEntityMissing(_recorder, e, "Cannot get entity while processing AWS SDK request"); } var serviceName = RemoveAmazonPrefixFromServiceName(request.ServiceName); _recorder.BeginSubsegment(AWSXRaySDKUtils.FormatServiceName(serviceName)); _recorder.SetNamespace("aws"); entity = entity == null ? null : _recorder.GetEntity(); if (TraceHeader.TryParse(entity, out TraceHeader traceHeader)) { request.Headers[TraceHeader.HeaderKey] = traceHeader.ToString(); } else { _logger.DebugFormat("Failed to inject trace header to AWS SDK request as the segment can't be converted to TraceHeader."); } }
/// <inheritdoc /> public async Task <TResult> InterceptAsync <TResult>(Func <Task <TResult> > method, DbCommand command) { _recorder.BeginSubsegment(BuildSubsegmentName(command)); try { _recorder.SetNamespace("remote"); var ret = await method(); CollectSqlInformation(command); return(ret); } catch (Exception e) { _recorder.AddException(e); throw; } finally { _recorder.EndSubsegment(); } }
/// <summary> /// Processes Begin request by starting subsegment. /// </summary> private void ProcessBeginRequest(IExecutionContext executionContext) { var request = executionContext.RequestContext.Request; if (TraceHeader.TryParse(_recorder.GetEntity(), out TraceHeader traceHeader)) { request.Headers[TraceHeader.HeaderKey] = traceHeader.ToString(); } else { _logger.DebugFormat("Failed to inject trace header to AWS SDK request as the segment can't be converted to TraceHeader."); } _recorder.BeginSubsegment(RemoveAmazonPrefixFromServiceName(request.ServiceName)); _recorder.SetNamespace("aws"); }
private void ProcessBeginCommand(CommandEventData eventData) { Entity entity = null; try { entity = _recorder.GetEntity(); } catch (EntityNotAvailableException e) { _recorder.TraceContext.HandleEntityMissing(_recorder, e, "Cannot get entity while processing start of Entity Framework command."); } _recorder.BeginSubsegment(BuildSubsegmentName(eventData.Command)); _recorder.SetNamespace("remote"); CollectSqlInformation(eventData); }
private void ProcessBeginRequest(IExecutionContext executionContext) { var request = executionContext.RequestContext.Request; Entity entity = null; try { entity = _recorder.GetEntity(); } catch (EntityNotAvailableException e) { _recorder.TraceContext.HandleEntityMissing(_recorder, e, "Cannot get entity while processing AWS SDK request"); } _recorder.BeginSubsegment(RemoveAmazonPrefixFromServiceName(request.ServiceName)); _recorder.SetNamespace("aws"); entity = entity == null ? null : _recorder.GetEntity(); if (TraceHeader.TryParse(entity, out var traceHeader)) { request.Headers[TraceHeader.HeaderKey] = traceHeader.ToString(); if (request.Parameters.Any(p => p.Value == "AWSTraceHeader")) { return; } var index = request .Parameters .Where(x => x.Key.StartsWith("MessageSystemAttribute")) .Select(x => int.TryParse(x.Value.Split('.')[1], out var idx) ? idx : 0) .Union(new[] { 0 }) .Max() + 1; request.Parameters.Add("MessageSystemAttribute" + "." + index + "." + "Name", StringUtils.FromString("AWSTraceHeader")); request.Parameters.Add("MessageSystemAttribute" + "." + index + "." + "Value.DataType", StringUtils.FromString("String")); request.Parameters.Add("MessageSystemAttribute" + "." + index + "." + "Value" + "." + "StringValue", StringUtils.FromString(traceHeader.ToString())); } }
private void BeforeRequestEventHandler(object sender, RequestEventArgs e) { var args = e as WebServiceRequestEventArgs; if (args == null) { _logger.DebugFormat("Failed to handle BeforeRequestEvent, because e can't be converted to WebServiceRequestEventArgs."); return; } if (TraceHeader.TryParse(_recorder.GetEntity(), out TraceHeader traceHeader)) { args.Headers[TraceHeader.HeaderKey] = traceHeader.ToString(); } else { _logger.DebugFormat("Failed to inject trace header to AWS SDK request as the segment can't be converted to TraceHeader."); } _recorder.BeginSubsegment(RemoveAmazonPrefixFromServiceName(args.ServiceName)); _recorder.SetNamespace("aws"); }
public void TestLogErrorModeForContextMissingStrategy() { using (var recorder = new AWSXRayRecorder()) { recorder.ContextMissingStrategy = ContextMissingStrategy.LOG_ERROR; recorder.EndSegment(); recorder.BeginSubsegment("no segment"); recorder.EndSubsegment(); recorder.SetNamespace("dummy namespace"); recorder.AddAnnotation("key", "value"); recorder.AddHttpInformation("key", "value"); recorder.MarkError(); recorder.MarkFault(); recorder.MarkThrottle(); recorder.AddException(new ArgumentNullException()); recorder.AddPrecursorId(Entity.GenerateId()); recorder.AddSqlInformation("sqlKey", "value"); recorder.AddMetadata("key", "value"); } }
/// <summary> /// Processes Begin request by starting subsegment. /// </summary> private void ProcessBeginRequest(IExecutionContext executionContext) { if (AWSXRayRecorder.Instance.IsTracingDisabled()) { _logger.DebugFormat("X-Ray tracing is disabled, do not handle AWSSDK request."); return; } var request = executionContext.RequestContext.Request; if (TraceHeader.TryParse(TraceContext.GetEntity(), out TraceHeader traceHeader)) { request.Headers[TraceHeader.HeaderKey] = traceHeader.ToString(); } else { _logger.DebugFormat("Failed to inject trace header to AWS SDK request as the segment can't be converted to TraceHeader."); } _recorder.BeginSubsegment(RemoveAmazonPrefixFromServiceName(request.ServiceName)); _recorder.SetNamespace("aws"); }
private TResult Intercept <TResult>(Func <TResult> method) { AWSXRayRecorder recorder = AWSXRayRecorder.Instance; recorder.BeginSubsegment(Connection.Database + "@" + SqlUtil.RemovePortNumberFromDataSource(Connection.DataSource)); try { recorder.SetNamespace("remote"); var ret = method(); CollectSqlInformation(); return(ret); } catch (Exception e) { recorder.AddException(e); throw; } finally { recorder.EndSubsegment(); } }
/// <summary> /// Process command to begin subsegment. /// </summary> /// <param name="command">Instance of <see cref="DbCommand"/>.</param> /// <param name="collectSqlQueriesOverride">Nullable to indicate whether to collect sql query text or not.</param> internal static void ProcessBeginCommand(DbCommand command, bool?collectSqlQueriesOverride) { _recorder.BeginSubsegment(BuildSubsegmentName(command)); _recorder.SetNamespace("remote"); CollectSqlInformation(command, collectSqlQueriesOverride); }