/// <summary> /// Records the SQL information on the current subsegment. /// </summary> private static void CollectSqlInformationDefault(DbCommand command) { var recorder = AWSXRayRecorder.Instance; var databaseType = AgentUtil.GetDataBaseType(command); recorder.AddSqlInformation("database_type", databaseType); recorder.AddSqlInformation("database_version", command.Connection.ServerVersion); DbConnectionStringBuilder connectionStringBuilder = new DbConnectionStringBuilder { ConnectionString = command.Connection.ConnectionString }; // Remove sensitive information from connection string connectionStringBuilder.Remove("Password"); var userId = AgentUtil.GetUserId(connectionStringBuilder); // Do a pre-check for user ID since in the case of TrustedConnection, a user ID may not be available. if (userId != null) { recorder.AddSqlInformation("user", userId.ToString()); } recorder.AddSqlInformation("connection_string", connectionStringBuilder.ToString()); if (ShouldCollectSqlText()) { recorder.AddSqlInformation("sanitized_query", command.CommandText); } }
internal static void ProcessHTTPRequest(object sender, EventArgs e) { var context = ((HttpApplication)sender).Context; string ruleName = null; var request = context.Request; TraceHeader traceHeader = GetTraceHeader(context); var segmentName = GetSegmentNamingStrategy().GetSegmentName(request); // Make sample decision if (traceHeader.Sampled == SampleDecision.Unknown || traceHeader.Sampled == SampleDecision.Requested) { SamplingResponse response = MakeSamplingDecision(request, traceHeader, segmentName); ruleName = response.RuleName; } var timestamp = context.Timestamp.ToUniversalTime(); // Gets initial timestamp of current HTTP Request SamplingResponse samplingResponse = new SamplingResponse(ruleName, traceHeader.Sampled); // get final ruleName and SampleDecision _recorder.BeginSegment(segmentName, traceHeader.RootTraceId, traceHeader.ParentId, samplingResponse, timestamp); // Mark the segment as auto-instrumented AgentUtil.AddAutoInstrumentationMark(); if (!AWSXRayRecorder.Instance.IsTracingDisabled()) { var requestAttributes = ProcessRequestAttributes(request); _recorder.AddHttpInformation("request", requestAttributes); } }
private static Dictionary <string, object> ProcessResponseAttributes(HttpResponse response) { var responseAttributes = new Dictionary <string, object>(); int statusCode = (int)response.StatusCode; responseAttributes["status"] = statusCode; AgentUtil.MarkEntityFromStatus(statusCode); return(responseAttributes); }
private static Dictionary <string, object> PopulateResponseAttributes(HttpResponse response) { var responseAttributes = new Dictionary <string, object>(); int statusCode = (int)response.StatusCode; AgentUtil.MarkEntityFromStatus(statusCode); responseAttributes["status"] = statusCode; if (response.Headers.ContentLength != null) { responseAttributes["content_length"] = response.Headers.ContentLength; } return(responseAttributes); }
/// <summary> /// Process response /// </summary> private static void ProcessResponse(HttpStatusCode httpStatusCode, long?contentLength) { if (AWSXRayRecorder.Instance.IsTracingDisabled()) { _logger.DebugFormat("Tracing is disabled. Not ending a subsegment on HTTP response."); return; } var statusCode = (int)httpStatusCode; var responseInformation = new Dictionary <string, object> { ["status"] = statusCode }; AgentUtil.MarkEntityFromStatus(statusCode); responseInformation["content_length"] = contentLength; AWSXRayRecorder.Instance.AddHttpInformation("response", responseInformation); }
/// <summary> /// Process http request. /// </summary> internal static void ProcessRequest(HttpContext httpContext) { HttpRequest request = httpContext.Request; string headerString = null; if (request.Headers.TryGetValue(TraceHeader.HeaderKey, out StringValues headerValue)) { if (headerValue.Count >= 1) { headerString = headerValue[0]; } } if (!TraceHeader.TryParse(headerString, out TraceHeader traceHeader)) { _logger.DebugFormat("Trace header doesn't exist or not valid : ({0}). Injecting a new one.", headerString); traceHeader = new TraceHeader { RootTraceId = TraceId.NewId(), ParentId = null, Sampled = SampleDecision.Unknown }; } var segmentName = SegmentNamingStrategy.GetSegmentName(request); bool isSampleDecisionRequested = traceHeader.Sampled == SampleDecision.Requested; string ruleName = null; // Make sample decision if (traceHeader.Sampled == SampleDecision.Unknown || traceHeader.Sampled == SampleDecision.Requested) { string host = request.Host.Host; string url = request.Path; string method = request.Method; SamplingInput samplingInput = new SamplingInput(host, url, method, segmentName, _recorder.Origin); SamplingResponse sampleResponse = _recorder.SamplingStrategy.ShouldTrace(samplingInput); traceHeader.Sampled = sampleResponse.SampleDecision; ruleName = sampleResponse.RuleName; } if (AWSXRayRecorder.IsLambda()) { _recorder.BeginSubsegment(segmentName); } else { SamplingResponse samplingResponse = new SamplingResponse(ruleName, traceHeader.Sampled); // get final ruleName and SampleDecision _recorder.BeginSegment(SegmentNamingStrategy.GetSegmentName(request), traceHeader.RootTraceId, traceHeader.ParentId, samplingResponse); } if (!AWSXRayRecorder.Instance.IsTracingDisabled()) { var requestAttributes = PopulateRequestAttributes(request); _recorder.AddHttpInformation("request", requestAttributes); } // Mark the segment as auto-instrumented AgentUtil.AddAutoInstrumentationMark(); if (isSampleDecisionRequested) { httpContext.Response.Headers.Add(TraceHeader.HeaderKey, traceHeader.ToString()); // Its recommended not to modify response header after _next.Invoke() call } }