diff --git a/src/SkyApm.Core/Diagnostics/AnonymousObject.cs b/src/SkyApm.Core/Diagnostics/AnonymousObjectAttribute.cs similarity index 93% rename from src/SkyApm.Core/Diagnostics/AnonymousObject.cs rename to src/SkyApm.Core/Diagnostics/AnonymousObjectAttribute.cs index f9662473..102db72b 100644 --- a/src/SkyApm.Core/Diagnostics/AnonymousObject.cs +++ b/src/SkyApm.Core/Diagnostics/AnonymousObjectAttribute.cs @@ -18,7 +18,7 @@ namespace SkyApm.Diagnostics { - public class AnonymousObject : ParameterBinder + public class AnonymousObjectAttribute : ParameterBinderAttribute { public override object Resolve(object value) { diff --git a/src/SkyApm.Core/Diagnostics/DiagnosticName.cs b/src/SkyApm.Core/Diagnostics/DiagnosticNameAttribute.cs similarity index 89% rename from src/SkyApm.Core/Diagnostics/DiagnosticName.cs rename to src/SkyApm.Core/Diagnostics/DiagnosticNameAttribute.cs index 5a0d0461..f8e996e9 100644 --- a/src/SkyApm.Core/Diagnostics/DiagnosticName.cs +++ b/src/SkyApm.Core/Diagnostics/DiagnosticNameAttribute.cs @@ -20,11 +20,11 @@ namespace SkyApm.Diagnostics { - public class DiagnosticName :Attribute + public class DiagnosticNameAttribute :Attribute { public string Name { get; } - public DiagnosticName(string name) + public DiagnosticNameAttribute(string name) { Name = name; } diff --git a/src/SkyApm.Core/Diagnostics/ObjectAttribute.cs b/src/SkyApm.Core/Diagnostics/ObjectAttribute.cs index ff4e4fd0..695d2e3d 100644 --- a/src/SkyApm.Core/Diagnostics/ObjectAttribute.cs +++ b/src/SkyApm.Core/Diagnostics/ObjectAttribute.cs @@ -20,7 +20,7 @@ namespace SkyApm.Diagnostics { - public class ObjectAttribute : ParameterBinder + public class ObjectAttribute : ParameterBinderAttribute { public Type TargetType { get; set; } diff --git a/src/SkyApm.Core/Diagnostics/ParameterBinder.cs b/src/SkyApm.Core/Diagnostics/ParameterBinderAttribute.cs similarity index 91% rename from src/SkyApm.Core/Diagnostics/ParameterBinder.cs rename to src/SkyApm.Core/Diagnostics/ParameterBinderAttribute.cs index 1319e181..e535d0ea 100644 --- a/src/SkyApm.Core/Diagnostics/ParameterBinder.cs +++ b/src/SkyApm.Core/Diagnostics/ParameterBinderAttribute.cs @@ -20,7 +20,7 @@ namespace SkyApm.Diagnostics { - public abstract class ParameterBinder : Attribute, IParameterResolver + public abstract class ParameterBinderAttribute : Attribute, IParameterResolver { public abstract object Resolve(object value); } diff --git a/src/SkyApm.Core/Diagnostics/PropertyAttribute.cs b/src/SkyApm.Core/Diagnostics/PropertyAttribute.cs index 05d9c3c6..283448fa 100644 --- a/src/SkyApm.Core/Diagnostics/PropertyAttribute.cs +++ b/src/SkyApm.Core/Diagnostics/PropertyAttribute.cs @@ -20,7 +20,7 @@ namespace SkyApm.Diagnostics { - public class PropertyAttribute : ParameterBinder + public class PropertyAttribute : ParameterBinderAttribute { public string Name { get; set; } diff --git a/src/SkyApm.Core/Diagnostics/TracingDiagnosticMethod.cs b/src/SkyApm.Core/Diagnostics/TracingDiagnosticMethod.cs index 9641635d..ae445241 100644 --- a/src/SkyApm.Core/Diagnostics/TracingDiagnosticMethod.cs +++ b/src/SkyApm.Core/Diagnostics/TracingDiagnosticMethod.cs @@ -61,7 +61,7 @@ private static IEnumerable GetParameterResolvers(MethodInfo { foreach (var parameter in methodInfo.GetParameters()) { - var binder = parameter.GetCustomAttribute(); + var binder = parameter.GetCustomAttribute(); if (binder != null) { if(binder is ObjectAttribute objectBinder) diff --git a/src/SkyApm.Core/Diagnostics/TracingDiagnosticMethodCollection.cs b/src/SkyApm.Core/Diagnostics/TracingDiagnosticMethodCollection.cs index fe465024..ac135d3e 100644 --- a/src/SkyApm.Core/Diagnostics/TracingDiagnosticMethodCollection.cs +++ b/src/SkyApm.Core/Diagnostics/TracingDiagnosticMethodCollection.cs @@ -31,7 +31,7 @@ public TracingDiagnosticMethodCollection(ITracingDiagnosticProcessor tracingDiag _methods = new List(); foreach (var method in tracingDiagnosticProcessor.GetType().GetMethods()) { - var diagnosticName = method.GetCustomAttribute(); + var diagnosticName = method.GetCustomAttribute(); if(diagnosticName==null) continue; _methods.Add(new TracingDiagnosticMethod(tracingDiagnosticProcessor, method, diagnosticName.Name)); diff --git a/src/SkyApm.Diagnostics.FreeSql/FreeSqlTracingDiagnosticProcessor.cs b/src/SkyApm.Diagnostics.FreeSql/FreeSqlTracingDiagnosticProcessor.cs index 5817be0c..bea08fa9 100644 --- a/src/SkyApm.Diagnostics.FreeSql/FreeSqlTracingDiagnosticProcessor.cs +++ b/src/SkyApm.Diagnostics.FreeSql/FreeSqlTracingDiagnosticProcessor.cs @@ -105,7 +105,7 @@ public void SyncStructureAfter([Object] SyncStructureAfterEventArgs eventData) var context = _localSegmentContextAccessor.Context; if (context != null) { - if (string.IsNullOrEmpty(eventData.Sql) == false) + if (!string.IsNullOrEmpty(eventData.Sql)) context.Span.AddTag(Common.Tags.DB_STATEMENT, eventData.Sql); if (eventData?.Exception != null) context.Span.ErrorOccurred(eventData.Exception, _tracingConfig); @@ -127,7 +127,7 @@ public void CommandAfter([Object] CommandAfterEventArgs eventData) var context = _localSegmentContextAccessor.Context; if (context != null) { - if (string.IsNullOrEmpty(eventData.Log) == false) + if (!string.IsNullOrEmpty(eventData.Log)) context.Span.AddTag(Common.Tags.DB_STATEMENT, eventData.Log); if (eventData?.Exception != null) context.Span.ErrorOccurred(eventData.Exception, _tracingConfig); @@ -149,7 +149,7 @@ public void TraceAfterUnitOfWork([Object] TraceAfterEventArgs eventData) var context = _localSegmentContextAccessor.Context; if (context != null) { - if (string.IsNullOrEmpty(eventData.Remark) == false) + if (!string.IsNullOrEmpty(eventData.Remark)) context.Span.AddTag(Common.Tags.DB_STATEMENT, eventData.Remark); if (eventData?.Exception != null) context.Span.ErrorOccurred(eventData.Exception, _tracingConfig); diff --git a/src/SkyApm.Diagnostics.Grpc/Client/ClientDiagnosticInterceptor.cs b/src/SkyApm.Diagnostics.Grpc/Client/ClientDiagnosticInterceptor.cs index 603d5873..11bbe606 100644 --- a/src/SkyApm.Diagnostics.Grpc/Client/ClientDiagnosticInterceptor.cs +++ b/src/SkyApm.Diagnostics.Grpc/Client/ClientDiagnosticInterceptor.cs @@ -54,7 +54,7 @@ public override AsyncUnaryCall AsyncUnaryCall(TR catch (Exception ex) { _processor.DiagnosticUnhandledException(ex); - throw ex; + throw; } }); return new AsyncUnaryCall(responseAsync, response.ResponseHeadersAsync, response.GetStatus, response.GetTrailers, response.Dispose); @@ -101,7 +101,7 @@ public T Call(ClientInterceptorContext UnaryServerHandler(TR { _processor.BeginRequest(context); - return await Handler(context, async () => + return await Handler(context, async () => { return await continuation(request, context); }); @@ -44,7 +44,7 @@ public override async Task UnaryServerHandler(TR public override async Task ClientStreamingServerHandler(IAsyncStreamReader requestStream, ServerCallContext context, ClientStreamingServerMethod continuation) { - return await Handler(context, async () => + return await Handler(context, async () => { return await continuation(requestStream, context); }); @@ -52,7 +52,7 @@ public override async Task ClientStreamingServerHandler(TRequest request, IServerStreamWriter responseStream, ServerCallContext context, ServerStreamingServerMethod continuation) { - await Handler(context, async () => + await Handler(context, async () => { await continuation(request, responseStream, context); }); @@ -60,14 +60,13 @@ await Handler(context, async () => public override async Task DuplexStreamingServerHandler(IAsyncStreamReader requestStream, IServerStreamWriter responseStream, ServerCallContext context, DuplexStreamingServerMethod continuation) { - await Handler(context, async () => + await Handler(context, async () => { await continuation(requestStream, responseStream, context); }); } - private async Task Handler(ServerCallContext context, Func func) - where TRequest : class + private async Task Handler(ServerCallContext context, Func func) { _processor.BeginRequest(context); try @@ -78,12 +77,11 @@ private async Task Handler(ServerCallContext context, Func func) catch (Exception ex) { _processor.DiagnosticUnhandledException(ex); - throw ex; + throw; } } - private async Task Handler(ServerCallContext context, Func> func) - where TRequest : class + private async Task Handler(ServerCallContext context, Func> func) where TResponse : class { _processor.BeginRequest(context); @@ -96,7 +94,7 @@ private async Task Handler(ServerCallContext con catch (Exception ex) { _processor.DiagnosticUnhandledException(ex); - throw ex; + throw; } } } diff --git a/src/SkyApm.Diagnostics.MongoDB/DiagnosticsActivityEventSubscriber.cs b/src/SkyApm.Diagnostics.MongoDB/DiagnosticsActivityEventSubscriber.cs index 301765f0..076ac030 100644 --- a/src/SkyApm.Diagnostics.MongoDB/DiagnosticsActivityEventSubscriber.cs +++ b/src/SkyApm.Diagnostics.MongoDB/DiagnosticsActivityEventSubscriber.cs @@ -27,7 +27,7 @@ namespace SkyApm.Diagnostics.MongoDB { public class DiagnosticsActivityEventSubscriber : IEventSubscriber { - public static DiagnosticSource diagnosticSource = new DiagnosticListener("MongoSourceListener"); + private static DiagnosticSource diagnosticSource = new DiagnosticListener("MongoSourceListener"); internal static readonly AssemblyName AssemblyName = typeof(DiagnosticsActivityEventSubscriber).Assembly.GetName(); internal static readonly string ActivitySourceName = AssemblyName.Name; internal static readonly Version Version = AssemblyName.Version; @@ -71,10 +71,7 @@ private void Handle(CommandStartedEvent @event) return; } var activity = new Activity("MongoActivity"); - if (activity == null) - { - return; - } + _activityMap.TryAdd(@event.RequestId, activity); diagnosticSource.StartActivity(activity, @event); }