public Metadata BeginRequest <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> grpcContext) where TRequest : class where TResponse : class { // 调用grpc方法时如果没有通过WithHost()方法指定grpc服务地址,则grpcContext.Host会为null, // 但context.Span.Peer为null的时候无法形成一条完整的链路,故设置了默认值[::1] var host = grpcContext.Host ?? "[::1]"; var carrierHeader = new GrpcCarrierHeaderCollection(grpcContext.Options.Headers); var context = _tracingContext.CreateExitSegmentContext($"{host}{grpcContext.Method.FullName}", host, carrierHeader); context.Span.SpanLayer = SpanLayer.RPC_FRAMEWORK; context.Span.Component = Components.GRPC; context.Span.Peer = new StringOrIntValue(host); context.Span.AddTag(Tags.GRPC_METHOD_NAME, grpcContext.Method.FullName); context.Span.AddLog( LogEvent.Event("Grpc Client BeginRequest"), LogEvent.Message($"Request starting {grpcContext.Method.Type} {grpcContext.Method.FullName}")); var metadata = new Metadata(); foreach (var item in carrierHeader) { metadata.Add(item.Key, item.Value); } return(metadata); }
public void InitializeCall([Property(Name = "Request")] HttpRequestMessage request) { var requestUri = request.RequestUri.ToString(); if (IsSkyWalkingRequest(requestUri)) { return; } var context = _tracingContext.CreateExitSegmentContext(requestUri, $"{request.RequestUri.Host}:{request.RequestUri.Port}", new GrpcNetClientICarrierHeaderCollection(request)); context.Span.SpanLayer = SpanLayer.RPC_FRAMEWORK; context.Span.Component = Common.Components.GRPC; context.Span.AddTag(Tags.URL, requestUri); var activity = Activity.Current; if (activity.OperationName == GrpcDiagnostics.ActivityName) { var method = activity.Tags.FirstOrDefault(x => x.Key == GrpcDiagnostics.GrpcMethodTagName).Value ?? request.Method.ToString(); context.Span.AddTag(Tags.GRPC_METHOD_NAME, method); } }
private SegmentContext CreateExitSegment(string operationName, DbCommand dbCommand, IEntityFrameworkCoreSpanMetadataProvider metadataProvider) { var context = _tracingContext.CreateExitSegmentContext(operationName, metadataProvider.GetPeer(dbCommand.Connection)); context.Span.Component = new StringOrIntValue(metadataProvider.Component); return(context); }
public void BeforeExecuteCommand(MySqlDataTraceCommand sqlCommand) { var context = _tracingContext.CreateExitSegmentContext(ResolveOperationName(sqlCommand), sqlCommand.DbServer); context.Span.SpanLayer = Tracing.Segments.SpanLayer.DB; context.Span.Component = Common.Components.SQLCLIENT; context.Span.AddTag(Common.Tags.DB_TYPE, "MySql"); context.Span.AddTag(Common.Tags.DB_INSTANCE, sqlCommand.Database); context.Span.AddTag(Common.Tags.DB_STATEMENT, sqlCommand.SqlText); }
public void BeforeExecuteCommand([Property(Name = "Command")] SqlCommand sqlCommand) { var context = _tracingContext.CreateExitSegmentContext(ResolveOperationName(sqlCommand), sqlCommand.Connection.DataSource); context.Span.SpanLayer = Tracing.Segments.SpanLayer.DB; context.Span.Component = Common.Components.SQLCLIENT; context.Span.AddTag(Common.Tags.DB_TYPE, "sql"); context.Span.AddTag(Common.Tags.DB_INSTANCE, sqlCommand.Connection.Database); context.Span.AddTag(Common.Tags.DB_STATEMENT, sqlCommand.CommandText); }
/// <summary> /// 创建SegmentContext /// </summary> /// <param name="sql">sql语句</param> /// <param name="dataSource">数据源</param> /// <returns></returns> private SegmentContext CreateExitSegmentContext(string sql, string dataSource) { var operationName = sql?.Split(' ').FirstOrDefault(); var context = _tracingContext.CreateExitSegmentContext(operationName, dataSource); context.Span.SpanLayer = SpanLayer.DB; context.Span.Component = _component.Value; context.Span.AddTag(Tags.DB_TYPE, "Sql"); return(context); }
public void Handle(ITracingContext tracingContext, HttpRequestMessage request) { var context = tracingContext.CreateExitSegmentContext(request.RequestUri.ToString(), $"{request.RequestUri.Host}:{request.RequestUri.Port}", new HttpClientICarrierHeaderCollection(request)); context.Span.SpanLayer = SpanLayer.HTTP; context.Span.Component = Common.Components.HTTPCLIENT; context.Span.AddTag(Tags.URL, request.RequestUri.ToString()); context.Span.AddTag(Tags.HTTP_METHOD, request.Method.ToString()); }
public void HttpRequest([Property(Name = "Request")] HttpRequestMessage request) { var context = _tracingContext.CreateExitSegmentContext(request.RequestUri.ToString(), $"{request.RequestUri.Host}:{request.RequestUri.Port}", new HttpClientICarrierHeaderCollection(request)); context.Span.SpanLayer = SpanLayer.HTTP; context.Span.Component = new StringOrIntValue("HttpClient"); context.Span.AddTag(Tags.URL, request.RequestUri.ToString()); context.Span.AddTag(Tags.HTTP_METHOD, request.Method.ToString()); }
public void BeforeExecuteCommand([Property(Name = "Commands")] IReadOnlyList <MySqlDiagnosticsCommand> sqlCommands) { var firstSqlCommand = sqlCommands.First(); var context = _tracingContext.CreateExitSegmentContext(ResolveOperationName(firstSqlCommand), firstSqlCommand.Connection.DataSource); context.Span.SpanLayer = Tracing.Segments.SpanLayer.DB; context.Span.Component = Common.Components.SQLCLIENT; context.Span.AddTag(Common.Tags.DB_TYPE, "MySql"); context.Span.AddTag(Common.Tags.DB_INSTANCE, firstSqlCommand.Connection.Database); context.Span.AddTag(Common.Tags.DB_STATEMENT, string.Join(Environment.NewLine, sqlCommands.Select(c => c.CommandText))); }
public void BeforeRPCExecute([Object] RPCExecuteBeforeEventData eventData) { if (eventData.Data.Payload == null) { eventData.Data.Payload = new JimuPayload(); } var operation = $"client-rpc: {eventData.Data.Service.ServiceDescriptor.RoutePath}"; var context = _tracingContext.CreateExitSegmentContext(operation, eventData.Data.ServiceAddress.ToString(), new JimuClientCarrierHeaderCollection(eventData.Data.Payload)); if (eventData.Data.Service != null) { context.Span.AddTag("service", eventData.Data.Service.ServiceDescriptor.Id); context.Span.AddTag("allowAnonymous", eventData.Data.Service.ServiceDescriptor.AllowAnonymous); } StringBuilder sbLog = new StringBuilder(); if (eventData.Data?.Paras != null) { sbLog.AppendLine($"parameters =>"); foreach (var para in eventData.Data.Paras) { if (para.Value is List <JimuFile> ) { foreach (var file in para.Value as List <JimuFile> ) { sbLog.AppendLine($"{para.Key}: {file.FileName}"); } } else { sbLog.AppendLine($"{para.Key}: {para.Value}"); } } } sbLog.AppendLine($"token =>"); sbLog.AppendLine($"{eventData.Data?.Token}"); if (eventData.Data.Payload?.Items != null) { sbLog.AppendLine($"payload =>"); foreach (var item in eventData.Data.Payload.Items) { sbLog.AppendLine($"{item.Key}: {item.Value}"); } } else { sbLog.AppendLine($"payload is null"); } context.Span.AddLog(LogEvent.Event("start"), LogEvent.Message(sbLog.ToString())); }
public void BeforeExecuteCommand([Object] CommandStartedEvent @event) { var operationName = DiagnosticsActivityEventSubscriber.GetCollectionName(@event); var context = _tracingContext.CreateExitSegmentContext(operationName, @event.ConnectionId.ServerId.EndPoint.ToString()); context.Span.SpanLayer = Tracing.Segments.SpanLayer.DB; context.Span.Component = Common.Components.MongoDBCLIENT; context.Span.AddTag("db.system", "mongodb"); context.Span.AddTag("db.name", @event.DatabaseNamespace?.DatabaseName); context.Span.AddTag("db.mongodb.collection", operationName); context.Span.AddTag("db.operation", operationName + @event.CommandName); context.Span.AddTag(Common.Tags.DB_TYPE, "sql"); context.Span.AddTag(Common.Tags.DB_INSTANCE, @event.DatabaseNamespace.DatabaseName); context.Span.AddTag(Common.Tags.DB_STATEMENT, @event.Command.ToString()); }
public void HttpRequest([Property(Name = "Request")] HttpRequestMessage request) { var context = _tracingContext.CreateExitSegmentContext(request.RequestUri.AbsolutePath.ToString(), $"{request.RequestUri.Host}:{request.RequestUri.Port}", new HttpClientICarrierHeaderCollection(request)); context.Span.SpanLayer = SpanLayer.HTTP; context.Span.Component = Common.Components.HTTPCLIENT; context.Span.AddTag(Tags.URL, request.RequestUri.ToString()); context.Span.AddTag(Tags.HTTP_METHOD, request.Method.ToString()); if (request.Content != null && request.Method.ToString().ToUpper() == "POST") { context.Span.AddTag(Tags.HTTP_REQUEST, request.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult()); } }
public void BeforeSqlExecute(MySqlMetaInfo metaInfo, string sql) { if (metaInfo == null || string.IsNullOrEmpty(sql)) { return; } var opration = sql.Split(' ').First(); var context = _tracingContext.CreateExitSegmentContext(opration, metaInfo.DbServer); context.Span.SpanLayer = Tracing.Segments.SpanLayer.DB; context.Span.Component = Common.Components.MYSQL; context.Span.AddTag(Common.Tags.DB_TYPE, "MySql"); context.Span.AddTag(Common.Tags.DB_INSTANCE, metaInfo.DbName); context.Span.AddTag(Common.Tags.DB_STATEMENT, sql); }
public void BeforePublish([Object] CapEventDataPubSend eventData) { _localSegmentContextAccessor.Context = _contexts[eventData.TransportMessage.GetId()]; var context = _tracingContext.CreateExitSegmentContext(OperateNamePrefix + eventData.Operation + ProducerOperateNameSuffix, eventData.BrokerAddress.Endpoint.Replace("-1", "5672"), new CapCarrierHeaderCollection(eventData.TransportMessage)); context.Span.SpanLayer = SpanLayer.MQ; context.Span.Component = GetComponent(eventData.BrokerAddress, true); context.Span.AddTag(Tags.MQ_TOPIC, eventData.Operation); context.Span.AddTag(Tags.MQ_BROKER, eventData.BrokerAddress.Endpoint); context.Span.AddLog(LogEvent.Event("Event Publishing")); context.Span.AddLog(LogEvent.Message("Message publishing start...")); }
public void Handle(ITracingContext tracingContext, HttpRequestMessage request) { var operationName = request.RequestUri.GetLeftPart(UriPartial.Path); var shouldStopPropagation = _httpClientDiagnosticConfig.StopHeaderPropagationPaths != null && _httpClientDiagnosticConfig.StopHeaderPropagationPaths .Any(pattern => FastPathMatcher.Match(pattern, operationName)); var context = tracingContext.CreateExitSegmentContext(operationName, $"{request.RequestUri.Host}:{request.RequestUri.Port}", shouldStopPropagation ? null : new HttpClientICarrierHeaderCollection(request)); context.Span.SpanLayer = SpanLayer.HTTP; context.Span.Component = Common.Components.HTTPCLIENT; context.Span.AddTag(Tags.URL, request.RequestUri.ToString()); context.Span.AddTag(Tags.HTTP_METHOD, request.Method.ToString()); }
public void Handle(ITracingContext tracingContext, HttpRequestMessage request) { var operationName = request.RequestUri.GetLeftPart(UriPartial.Path); var ignored = _httpClientDiagnosticConfig.IgnorePaths != null && _httpClientDiagnosticConfig.IgnorePaths .Any(pattern => FastPathMatcher.Match(pattern, operationName)); if (ignored) { return; } var shouldStopPropagation = _httpClientDiagnosticConfig.StopHeaderPropagationPaths != null && _httpClientDiagnosticConfig.StopHeaderPropagationPaths .Any(pattern => FastPathMatcher.Match(pattern, operationName)); var context = tracingContext.CreateExitSegmentContext(operationName, $"{request.RequestUri.Host}:{request.RequestUri.Port}", shouldStopPropagation ? null : new HttpClientICarrierHeaderCollection(request)); context.Span.SpanLayer = SpanLayer.HTTP; context.Span.Component = Common.Components.HTTPCLIENT; context.Span.AddTag(Tags.URL, request.RequestUri.ToString()); context.Span.AddTag(Tags.HTTP_METHOD, request.Method.ToString()); if (_httpClientDiagnosticConfig.CollectRequestHeaders?.Count > 0) { var headers = CollectHeaders(request, _httpClientDiagnosticConfig.CollectRequestHeaders); if (!string.IsNullOrEmpty(headers)) { context.Span.AddTag(Tags.HTTP_HEADERS, headers); } } if (request.Content != null && _httpClientDiagnosticConfig.CollectRequestBodyContentTypes?.Count > 0) { var requestBody = request.Content.TryCollectAsString( _httpClientDiagnosticConfig.CollectRequestBodyContentTypes, _httpClientDiagnosticConfig.CollectBodyLengthThreshold); if (!string.IsNullOrEmpty(requestBody)) { context.Span.AddTag(Tags.HTTP_REQUEST_BODY, requestBody); } } }
public void HttpRequest([Property(Name = "Request")] HttpRequestMessage request) { _segmentContext = _tracingContext.CreateExitSegmentContext(request.RequestUri.ToString(), $"{request.RequestUri.Host}:{request.RequestUri.Port}", new HttpClientICarrierHeaderCollection(request)); var context = _segmentContext; if (request.Content != null) { var requestStr = request.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult(); context.Span.AddTag(TagsExtension.REQUEST, requestStr); } context.Span.SpanLayer = SpanLayer.HTTP; context.Span.Component = Components.HTTPCLIENT; context.Span.AddTag(Tags.URL, request.RequestUri.ToString()); context.Span.AddTag(Tags.HTTP_METHOD, request.Method.ToString()); context.Span.AddTag(TagsExtension.HEADERS, JsonConvert.SerializeObject(request.Headers)); }