diff --git a/examples/grpc.core/Examples.GrpcCore.AspNetCore/Startup.cs b/examples/grpc.core/Examples.GrpcCore.AspNetCore/Startup.cs index 374ec30c48..86657cced5 100644 --- a/examples/grpc.core/Examples.GrpcCore.AspNetCore/Startup.cs +++ b/examples/grpc.core/Examples.GrpcCore.AspNetCore/Startup.cs @@ -110,7 +110,7 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken) tcs.SetResult(true); }); - return tcs.Task.ContinueWith(antecedent => tokenRegistration.Dispose()); + return tcs.Task.ContinueWith(antecedent => tokenRegistration.Dispose(), stoppingToken); } } } diff --git a/src/OpenTelemetry.Exporter.Stackdriver/.publicApi/net462/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.Stackdriver/.publicApi/net462/PublicAPI.Unshipped.txt index fa997838e5..1fd1f60339 100644 --- a/src/OpenTelemetry.Exporter.Stackdriver/.publicApi/net462/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Stackdriver/.publicApi/net462/PublicAPI.Unshipped.txt @@ -15,7 +15,7 @@ OpenTelemetry.Exporter.Stackdriver.StackdriverTraceExporter OpenTelemetry.Exporter.Stackdriver.StackdriverTraceExporter.StackdriverTraceExporter(string projectId) -> void OpenTelemetry.Exporter.Stackdriver.Utils.CommonUtils OpenTelemetry.Trace.TracerProviderBuilderExtensions -override OpenTelemetry.Exporter.Stackdriver.StackdriverTraceExporter.Export(in OpenTelemetry.Batch batchActivity) -> OpenTelemetry.ExportResult +override OpenTelemetry.Exporter.Stackdriver.StackdriverTraceExporter.Export(in OpenTelemetry.Batch batch) -> OpenTelemetry.ExportResult static OpenTelemetry.Exporter.Stackdriver.Implementation.GoogleCloudResourceUtils.GetDefaultResource(string projectId) -> Google.Api.MonitoredResource static OpenTelemetry.Exporter.Stackdriver.Implementation.GoogleCloudResourceUtils.GetProjectId() -> string static OpenTelemetry.Exporter.Stackdriver.Implementation.StackdriverStatsConfiguration.Default.get -> OpenTelemetry.Exporter.Stackdriver.Implementation.StackdriverStatsConfiguration diff --git a/src/OpenTelemetry.Exporter.Stackdriver/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.Stackdriver/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index fa997838e5..1fd1f60339 100644 --- a/src/OpenTelemetry.Exporter.Stackdriver/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Stackdriver/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -15,7 +15,7 @@ OpenTelemetry.Exporter.Stackdriver.StackdriverTraceExporter OpenTelemetry.Exporter.Stackdriver.StackdriverTraceExporter.StackdriverTraceExporter(string projectId) -> void OpenTelemetry.Exporter.Stackdriver.Utils.CommonUtils OpenTelemetry.Trace.TracerProviderBuilderExtensions -override OpenTelemetry.Exporter.Stackdriver.StackdriverTraceExporter.Export(in OpenTelemetry.Batch batchActivity) -> OpenTelemetry.ExportResult +override OpenTelemetry.Exporter.Stackdriver.StackdriverTraceExporter.Export(in OpenTelemetry.Batch batch) -> OpenTelemetry.ExportResult static OpenTelemetry.Exporter.Stackdriver.Implementation.GoogleCloudResourceUtils.GetDefaultResource(string projectId) -> Google.Api.MonitoredResource static OpenTelemetry.Exporter.Stackdriver.Implementation.GoogleCloudResourceUtils.GetProjectId() -> string static OpenTelemetry.Exporter.Stackdriver.Implementation.StackdriverStatsConfiguration.Default.get -> OpenTelemetry.Exporter.Stackdriver.Implementation.StackdriverStatsConfiguration diff --git a/src/OpenTelemetry.Exporter.Stackdriver/Implementation/ActivityExtensions.cs b/src/OpenTelemetry.Exporter.Stackdriver/Implementation/ActivityExtensions.cs index 18a530fda9..240c2af077 100644 --- a/src/OpenTelemetry.Exporter.Stackdriver/Implementation/ActivityExtensions.cs +++ b/src/OpenTelemetry.Exporter.Stackdriver/Implementation/ActivityExtensions.cs @@ -18,6 +18,7 @@ using System.Collections.Generic; using System.Diagnostics; +using System.Globalization; using System.Linq; using Google.Cloud.Trace.V2; using Google.Protobuf.WellKnownTypes; @@ -27,7 +28,7 @@ namespace OpenTelemetry.Exporter.Stackdriver.Implementation; internal static class ActivityExtensions { - private static Dictionary labelsToReplace = new Dictionary + private static readonly Dictionary LabelsToReplace = new Dictionary { { "component", "/component" }, { "http.method", "/http/method" }, @@ -94,7 +95,7 @@ public static Span ToSpan(this Activity activity, string projectId) // StackDriver uses different labels that are used to categorize spans // replace attribute keys with StackDriver version - foreach (var entry in labelsToReplace) + foreach (var entry in LabelsToReplace) { if (span.Attributes.AttributeMap.TryGetValue(entry.Key, out var attrValue)) { @@ -146,7 +147,7 @@ public static AttributeValue ToAttributeValue(this object? av) case double d: return new AttributeValue() { - StringValue = new TruncatableString() { Value = d.ToString() }, + StringValue = new TruncatableString() { Value = d.ToString(CultureInfo.InvariantCulture) }, }; case null: return new AttributeValue(); diff --git a/src/OpenTelemetry.Exporter.Stackdriver/Implementation/Constants.cs b/src/OpenTelemetry.Exporter.Stackdriver/Implementation/Constants.cs index 9f20621d53..800a31aa74 100644 --- a/src/OpenTelemetry.Exporter.Stackdriver/Implementation/Constants.cs +++ b/src/OpenTelemetry.Exporter.Stackdriver/Implementation/Constants.cs @@ -20,30 +20,31 @@ namespace OpenTelemetry.Exporter.Stackdriver.Implementation; internal class Constants { - public static readonly string PackagVersionUndefined = "undefined"; + public const string PackagVersionUndefined = "undefined"; - public static readonly string LabelDescription = "OpenTelemetry string"; - public static readonly string OpenTelemetryTask = "OpenTelemetry_task"; - public static readonly string OpenTelemetryTaskDescription = "OpenTelemetry task identifier"; + public const string LabelDescription = "OpenTelemetry string"; + public const string OpenTelemetryTask = "OpenTelemetry_task"; + public const string OpenTelemetryTaskDescription = "OpenTelemetry task identifier"; - public static readonly string GcpGkeContainer = "k8s_container"; - public static readonly string GcpGceInstance = "gce_instance"; - public static readonly string AwsEc2Instance = "aws_ec2_instance"; - public static readonly string Global = "global"; + public const string GcpGkeContainer = "k8s_container"; + public const string GcpGceInstance = "gce_instance"; + public const string AwsEc2Instance = "aws_ec2_instance"; + public const string Global = "global"; - public static readonly string ProjectIdLabelKey = "project_id"; - public static readonly string OpenTelemetryTaskValueDefault = GenerateDefaultTaskValue(); + public const string ProjectIdLabelKey = "project_id"; + + public const string GceGcpInstanceType = "cloud.google.com/gce/instance"; + public const string GcpInstanceIdKey = "cloud.google.com/gce/instance_id"; + public const string GcpAccountIdKey = "cloud.google.com/gce/project_id"; + public const string GcpZoneKey = "cloud.google.com/gce/zone"; - public static readonly string GceGcpInstanceType = "cloud.google.com/gce/instance"; - public static readonly string GcpInstanceIdKey = "cloud.google.com/gce/instance_id"; - public static readonly string GcpAccountIdKey = "cloud.google.com/gce/project_id"; - public static readonly string GcpZoneKey = "cloud.google.com/gce/zone"; + public const string K8sContainerType = "k8s.io/container"; + public const string K8sClusterNameKey = "k8s.io/cluster/name"; + public const string K8sContainerNameKey = "k8s.io/container/name"; + public const string K8sNamespaceNameKey = "k8s.io/namespace/name"; + public const string K8sPodNameKey = "k8s.io/pod/name"; - public static readonly string K8sContainerType = "k8s.io/container"; - public static readonly string K8sClusterNameKey = "k8s.io/cluster/name"; - public static readonly string K8sContainerNameKey = "k8s.io/container/name"; - public static readonly string K8sNamespaceNameKey = "k8s.io/namespace/name"; - public static readonly string K8sPodNameKey = "k8s.io/pod/name"; + public static readonly string OpenTelemetryTaskValueDefault = GenerateDefaultTaskValue(); private static string GenerateDefaultTaskValue() { diff --git a/src/OpenTelemetry.Exporter.Stackdriver/StackdriverTraceExporter.cs b/src/OpenTelemetry.Exporter.Stackdriver/StackdriverTraceExporter.cs index 222c5c12f0..e109388329 100644 --- a/src/OpenTelemetry.Exporter.Stackdriver/StackdriverTraceExporter.cs +++ b/src/OpenTelemetry.Exporter.Stackdriver/StackdriverTraceExporter.cs @@ -37,7 +37,9 @@ public class StackdriverTraceExporter : BaseExporter private readonly TraceServiceSettings traceServiceSettings; private readonly TraceServiceClient traceServiceClient; +#pragma warning disable CA1810 // Initialize reference type static fields inline static StackdriverTraceExporter() +#pragma warning restore CA1810 // Initialize reference type static fields inline { try { @@ -87,7 +89,7 @@ internal StackdriverTraceExporter(string projectId, TraceServiceClient traceServ } /// - public override ExportResult Export(in Batch batchActivity) + public override ExportResult Export(in Batch batch) { TraceServiceClient traceWriter = this.traceServiceClient; if (this.traceServiceClient == null) @@ -103,7 +105,7 @@ public override ExportResult Export(in Batch batchActivity) ProjectName = this.googleCloudProjectId, }; - foreach (var activity in batchActivity) + foreach (var activity in batch) { // It should never happen that the time has no correct kind, only if OpenTelemetry is used incorrectly. if (activity.StartTimeUtc.Kind == DateTimeKind.Utc) diff --git a/src/OpenTelemetry.Exporter.Stackdriver/TracerProviderBuilderExtensions.cs b/src/OpenTelemetry.Exporter.Stackdriver/TracerProviderBuilderExtensions.cs index 6d08567660..e96e34b8cb 100644 --- a/src/OpenTelemetry.Exporter.Stackdriver/TracerProviderBuilderExtensions.cs +++ b/src/OpenTelemetry.Exporter.Stackdriver/TracerProviderBuilderExtensions.cs @@ -36,8 +36,10 @@ public static TracerProviderBuilder UseStackdriverExporter( { Guard.ThrowIfNull(builder); +#pragma warning disable CA2000 // Dispose objects before losing scope var activityExporter = new StackdriverTraceExporter(projectId); return builder.AddProcessor(new BatchActivityExportProcessor(activityExporter)); +#pragma warning restore CA2000 // Dispose objects before losing scope } } diff --git a/src/OpenTelemetry.Exporter.Stackdriver/Utils/CommonUtils.cs b/src/OpenTelemetry.Exporter.Stackdriver/Utils/CommonUtils.cs index 3aac886d42..ef9067fc54 100644 --- a/src/OpenTelemetry.Exporter.Stackdriver/Utils/CommonUtils.cs +++ b/src/OpenTelemetry.Exporter.Stackdriver/Utils/CommonUtils.cs @@ -32,6 +32,11 @@ public static class CommonUtils /// . public static IEnumerable> Partition(this IEnumerable source, int size) { + if (source == null) + { + throw new System.ArgumentNullException(nameof(source)); + } + using var enumerator = source.GetEnumerator(); while (enumerator.MoveNext()) { diff --git a/src/OpenTelemetry.Instrumentation.GrpcCore/ClientTracingInterceptor.cs b/src/OpenTelemetry.Instrumentation.GrpcCore/ClientTracingInterceptor.cs index 146b30dce9..b1ea6d2a72 100644 --- a/src/OpenTelemetry.Instrumentation.GrpcCore/ClientTracingInterceptor.cs +++ b/src/OpenTelemetry.Instrumentation.GrpcCore/ClientTracingInterceptor.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Threading.Tasks; using Grpc.Core; using Grpc.Core.Interceptors; using OpenTelemetry.Context.Propagation; @@ -52,6 +53,9 @@ public override TResponse BlockingUnaryCall( ClientInterceptorContext context, BlockingUnaryCallContinuation continuation) { + Guard.ThrowIfNull(context); + Guard.ThrowIfNull(continuation); + ClientRpcScope rpcScope = null; try @@ -81,11 +85,16 @@ public override AsyncUnaryCall AsyncUnaryCall( ClientInterceptorContext context, AsyncUnaryCallContinuation continuation) { + Guard.ThrowIfNull(context); + Guard.ThrowIfNull(continuation); + ClientRpcScope rpcScope = null; try { +#pragma warning disable CA2000 rpcScope = new ClientRpcScope(context, this.options); +#pragma warning restore CA2000 rpcScope.RecordRequest(request); var responseContinuation = continuation(request, rpcScope.Context); var responseAsync = responseContinuation.ResponseAsync.ContinueWith( @@ -103,7 +112,8 @@ public override AsyncUnaryCall AsyncUnaryCall( rpcScope.CompleteWithException(ex.InnerException); throw ex.InnerException; } - }); + }, + TaskScheduler.Current); return new AsyncUnaryCall( responseAsync, @@ -128,11 +138,16 @@ public override AsyncClientStreamingCall AsyncClientStreami ClientInterceptorContext context, AsyncClientStreamingCallContinuation continuation) { + Guard.ThrowIfNull(context); + Guard.ThrowIfNull(continuation); + ClientRpcScope rpcScope = null; try { +#pragma warning disable CA2000 rpcScope = new ClientRpcScope(context, this.options); +#pragma warning restore CA2000 var responseContinuation = continuation(rpcScope.Context); var clientRequestStreamProxy = new ClientStreamWriterProxy( responseContinuation.RequestStream, @@ -154,7 +169,8 @@ public override AsyncClientStreamingCall AsyncClientStreami rpcScope.CompleteWithException(ex.InnerException); throw ex.InnerException; } - }); + }, + TaskScheduler.Current); return new AsyncClientStreamingCall( clientRequestStreamProxy, @@ -181,11 +197,16 @@ public override AsyncServerStreamingCall AsyncServerStreamingCall context, AsyncServerStreamingCallContinuation continuation) { + Guard.ThrowIfNull(context); + Guard.ThrowIfNull(continuation); + ClientRpcScope rpcScope = null; try { +#pragma warning disable CA2000 rpcScope = new ClientRpcScope(context, this.options); +#pragma warning restore CA2000 rpcScope.RecordRequest(request); var responseContinuation = continuation(request, rpcScope.Context); @@ -218,11 +239,16 @@ public override AsyncDuplexStreamingCall AsyncDuplexStreami ClientInterceptorContext context, AsyncDuplexStreamingCallContinuation continuation) { + Guard.ThrowIfNull(context); + Guard.ThrowIfNull(continuation); + ClientRpcScope rpcScope = null; try { +#pragma warning disable CA2000 rpcScope = new ClientRpcScope(context, this.options); +#pragma warning restore CA2000 var responseContinuation = continuation(rpcScope.Context); var requestStreamProxy = new ClientStreamWriterProxy( diff --git a/src/OpenTelemetry.Instrumentation.GrpcCore/ClientTracingInterceptorOptions.cs b/src/OpenTelemetry.Instrumentation.GrpcCore/ClientTracingInterceptorOptions.cs index 5e7898b58d..79b23e9320 100644 --- a/src/OpenTelemetry.Instrumentation.GrpcCore/ClientTracingInterceptorOptions.cs +++ b/src/OpenTelemetry.Instrumentation.GrpcCore/ClientTracingInterceptorOptions.cs @@ -27,7 +27,7 @@ public class ClientTracingInterceptorOptions /// /// Gets or sets a value indicating whether or not to record individual message events. /// - public bool RecordMessageEvents { get; set; } = false; + public bool RecordMessageEvents { get; set; } /// /// Gets the propagator. diff --git a/src/OpenTelemetry.Instrumentation.GrpcCore/RpcScope.cs b/src/OpenTelemetry.Instrumentation.GrpcCore/RpcScope.cs index a1a7c50cdf..d5c8c6d882 100644 --- a/src/OpenTelemetry.Instrumentation.GrpcCore/RpcScope.cs +++ b/src/OpenTelemetry.Instrumentation.GrpcCore/RpcScope.cs @@ -46,7 +46,7 @@ internal abstract class RpcScope : IDisposable /// /// The complete flag. /// - private long complete = 0; + private long complete; /// /// The request message counter. diff --git a/src/OpenTelemetry.Instrumentation.GrpcCore/ServerTracingInterceptor.cs b/src/OpenTelemetry.Instrumentation.GrpcCore/ServerTracingInterceptor.cs index aaab133b95..919dd8a0da 100644 --- a/src/OpenTelemetry.Instrumentation.GrpcCore/ServerTracingInterceptor.cs +++ b/src/OpenTelemetry.Instrumentation.GrpcCore/ServerTracingInterceptor.cs @@ -54,6 +54,9 @@ public override async Task UnaryServerHandler( ServerCallContext context, UnaryServerMethod continuation) { + Guard.ThrowIfNull(context); + Guard.ThrowIfNull(continuation); + using var rpcScope = new ServerRpcScope(context, this.options); try @@ -77,6 +80,9 @@ public override async Task ClientStreamingServerHandler continuation) { + Guard.ThrowIfNull(context); + Guard.ThrowIfNull(continuation); + using var rpcScope = new ServerRpcScope(context, this.options); try @@ -104,6 +110,9 @@ public override async Task ServerStreamingServerHandler( ServerCallContext context, ServerStreamingServerMethod continuation) { + Guard.ThrowIfNull(context); + Guard.ThrowIfNull(continuation); + using var rpcScope = new ServerRpcScope(context, this.options); try @@ -127,6 +136,9 @@ public override async Task ServerStreamingServerHandler( /// public override async Task DuplexStreamingServerHandler(IAsyncStreamReader requestStream, IServerStreamWriter responseStream, ServerCallContext context, DuplexStreamingServerMethod continuation) { + Guard.ThrowIfNull(context); + Guard.ThrowIfNull(continuation); + using var rpcScope = new ServerRpcScope(context, this.options); try diff --git a/src/OpenTelemetry.Instrumentation.GrpcCore/ServerTracingInterceptorOptions.cs b/src/OpenTelemetry.Instrumentation.GrpcCore/ServerTracingInterceptorOptions.cs index 94fbea9967..3b982d0c08 100644 --- a/src/OpenTelemetry.Instrumentation.GrpcCore/ServerTracingInterceptorOptions.cs +++ b/src/OpenTelemetry.Instrumentation.GrpcCore/ServerTracingInterceptorOptions.cs @@ -27,7 +27,7 @@ public class ServerTracingInterceptorOptions /// /// Gets or sets a value indicating whether or not to record individual message events. /// - public bool RecordMessageEvents { get; set; } = false; + public bool RecordMessageEvents { get; set; } /// /// Gets the propagator. diff --git a/src/OpenTelemetry.Instrumentation.Hangfire/Implementation/HangfireInstrumentationJobFilterAttribute.cs b/src/OpenTelemetry.Instrumentation.Hangfire/Implementation/HangfireInstrumentationJobFilterAttribute.cs index 88279bedf7..dbddf6abf2 100644 --- a/src/OpenTelemetry.Instrumentation.Hangfire/Implementation/HangfireInstrumentationJobFilterAttribute.cs +++ b/src/OpenTelemetry.Instrumentation.Hangfire/Implementation/HangfireInstrumentationJobFilterAttribute.cs @@ -28,7 +28,7 @@ namespace OpenTelemetry.Instrumentation.Hangfire.Implementation; using OpenTelemetry.Context.Propagation; using OpenTelemetry.Trace; -internal class HangfireInstrumentationJobFilterAttribute : JobFilterAttribute, IServerFilter, IClientFilter +internal sealed class HangfireInstrumentationJobFilterAttribute : JobFilterAttribute, IServerFilter, IClientFilter { private readonly HangfireInstrumentationOptions options; @@ -37,6 +37,8 @@ public HangfireInstrumentationJobFilterAttribute(HangfireInstrumentationOptions this.options = options; } + public HangfireInstrumentationOptions Options { get; } + public void OnPerforming(PerformingContext performingContext) { // Short-circuit if nobody is listening @@ -123,7 +125,7 @@ private static void InjectActivityProperties(IDictionary jobPara private static IEnumerable ExtractActivityProperties(Dictionary telemetryData, string key) { - return telemetryData.ContainsKey(key) ? new[] { telemetryData[key] } : Enumerable.Empty(); + return telemetryData.TryGetValue(key, out var value) ? new[] { value } : Enumerable.Empty(); } private void SetStatusAndRecordException(Activity activity, Exception exception) diff --git a/src/OpenTelemetry.Instrumentation.MySqlData/MySqlDataInstrumentation.cs b/src/OpenTelemetry.Instrumentation.MySqlData/MySqlDataInstrumentation.cs index 1cc31f9012..31f10c9968 100644 --- a/src/OpenTelemetry.Instrumentation.MySqlData/MySqlDataInstrumentation.cs +++ b/src/OpenTelemetry.Instrumentation.MySqlData/MySqlDataInstrumentation.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Concurrent; using System.Diagnostics; +using System.Globalization; using System.Linq.Expressions; using System.Reflection; using MySql.Data.MySqlClient; @@ -113,7 +114,7 @@ public override void TraceEvent( break; case MySqlTraceEventType.QueryClosed: // args: [driverId] - this.AfterExecuteCommand(); + AfterExecuteCommand(); break; case MySqlTraceEventType.StatementPrepared: break; @@ -129,7 +130,7 @@ public override void TraceEvent( break; case MySqlTraceEventType.Error: // args: [driverId, exNumber, exMessage] - this.ErrorExecuteCommand(this.GetMySqlErrorException(args[2])); + this.ErrorExecuteCommand(GetMySqlErrorException(args[2])); break; case MySqlTraceEventType.QueryNormalized: // Should use QueryNormalized event when it exists. Because cmdText in QueryOpened event is incomplete when cmdText.length>300 @@ -137,13 +138,46 @@ public override void TraceEvent( this.OverwriteDbStatement(this.GetCommand(args[0], args[2])); break; default: - MySqlDataInstrumentationEventSource.Log.UnknownMySqlTraceEventType(id, string.Format(format, args)); + MySqlDataInstrumentationEventSource.Log.UnknownMySqlTraceEventType(id, string.Format(CultureInfo.InvariantCulture, format, args)); break; } } catch (Exception e) { - MySqlDataInstrumentationEventSource.Log.ErrorTraceEvent(id, string.Format(format, args), e.ToString()); + MySqlDataInstrumentationEventSource.Log.ErrorTraceEvent(id, string.Format(CultureInfo.InvariantCulture, format, args), e.ToString()); + } + } + + private static Exception GetMySqlErrorException(object errorMsg) + { +#pragma warning disable CA2201 // Do not raise reserved exception types + return new Exception(errorMsg?.ToString()); +#pragma warning restore CA2201 // Do not raise reserved exception types + } + + private static void AfterExecuteCommand() + { + var activity = Activity.Current; + if (activity == null) + { + return; + } + + if (activity.Source != MySqlActivitySourceHelper.ActivitySource) + { + return; + } + + try + { + if (activity.IsAllDataRequested) + { + activity.SetStatus(Status.Unset); + } + } + finally + { + activity.Stop(); } } @@ -198,32 +232,6 @@ private void OverwriteDbStatement(MySqlDataTraceCommand command) } } - private void AfterExecuteCommand() - { - var activity = Activity.Current; - if (activity == null) - { - return; - } - - if (activity.Source != MySqlActivitySourceHelper.ActivitySource) - { - return; - } - - try - { - if (activity.IsAllDataRequested) - { - activity.SetStatus(Status.Unset); - } - } - finally - { - activity.Stop(); - } - } - private void ErrorExecuteCommand(Exception exception) { var activity = Activity.Current; @@ -266,11 +274,6 @@ private MySqlDataTraceCommand GetCommand(object driverIdObj, object cmd) return command; } - private Exception GetMySqlErrorException(object errorMsg) - { - return new Exception($"{errorMsg}"); - } - private void AddConnectionLevelDetailsToActivity(MySqlConnectionStringBuilder dataSource, Activity sqlActivity) { if (!this.options.EnableConnectionLevelAttributes) diff --git a/test/OpenTelemetry.Exporter.Stackdriver.Tests/TestActivityProcessor.cs b/test/OpenTelemetry.Exporter.Stackdriver.Tests/TestActivityProcessor.cs index 816c34a496..c4a55c3755 100644 --- a/test/OpenTelemetry.Exporter.Stackdriver.Tests/TestActivityProcessor.cs +++ b/test/OpenTelemetry.Exporter.Stackdriver.Tests/TestActivityProcessor.cs @@ -34,20 +34,20 @@ public TestActivityProcessor(Action onStart, Action onEnd) this.EndAction = onEnd; } - public bool ShutdownCalled { get; private set; } = false; + public bool ShutdownCalled { get; private set; } - public bool ForceFlushCalled { get; private set; } = false; + public bool ForceFlushCalled { get; private set; } - public bool DisposedCalled { get; private set; } = false; + public bool DisposedCalled { get; private set; } - public override void OnStart(Activity activity) + public override void OnStart(Activity data) { - this.StartAction?.Invoke(activity); + this.StartAction?.Invoke(data); } - public override void OnEnd(Activity activity) + public override void OnEnd(Activity data) { - this.EndAction?.Invoke(activity); + this.EndAction?.Invoke(data); } protected override bool OnShutdown(int timeoutMilliseconds) diff --git a/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/FoobarService.cs b/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/FoobarService.cs index 09a4c2dfd2..7bb3af2851 100644 --- a/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/FoobarService.cs +++ b/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/FoobarService.cs @@ -33,7 +33,17 @@ internal class FoobarService : Foobar.FoobarBase /// /// Default traceparent header value with the sampling bit on. /// - internal static readonly string DefaultTraceparentWithSampling = "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"; + internal const string DefaultTraceparentWithSampling = "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"; + + /// + /// The request header fail with status code. + /// + internal const string RequestHeaderFailWithStatusCode = "failurestatuscode"; + + /// + /// The request header error description. + /// + internal const string RequestHeaderErrorDescription = "failuredescription"; /// /// The default parent from a traceparent header. @@ -60,16 +70,6 @@ internal class FoobarService : Foobar.FoobarBase /// internal static readonly int DefaultResponseMessageSize = ((IMessage)DefaultResponseMessage).CalculateSize(); - /// - /// The request header fail with status code. - /// - internal static readonly string RequestHeaderFailWithStatusCode = "failurestatuscode"; - - /// - /// The request header error description. - /// - internal static readonly string RequestHeaderErrorDescription = "failuredescription"; - /// /// Starts the specified service. /// diff --git a/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/GrpcCoreClientInterceptorTests.cs b/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/GrpcCoreClientInterceptorTests.cs index 458075c61e..53e8b810f0 100644 --- a/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/GrpcCoreClientInterceptorTests.cs +++ b/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/GrpcCoreClientInterceptorTests.cs @@ -35,7 +35,7 @@ public class GrpcCoreClientInterceptorTests /// /// A bogus server uri. /// - private static readonly string BogusServerUri = "dns:i.dont.exist:77923"; + private const string BogusServerUri = "dns:i.dont.exist:77923"; /// /// The default metadata func. @@ -49,7 +49,7 @@ public class GrpcCoreClientInterceptorTests [Fact] public async Task AsyncUnarySuccess() { - await this.TestHandlerSuccess(FoobarService.MakeUnaryAsyncRequest, DefaultMetadataFunc()).ConfigureAwait(false); + await TestHandlerSuccess(FoobarService.MakeUnaryAsyncRequest, DefaultMetadataFunc()).ConfigureAwait(false); } /// @@ -59,7 +59,7 @@ public async Task AsyncUnarySuccess() [Fact] public async Task AsyncUnaryUnavailable() { - await this.TestHandlerFailure( + await TestHandlerFailure( FoobarService.MakeUnaryAsyncRequest, StatusCode.Unavailable, validateErrorDescription: false, @@ -73,7 +73,7 @@ await this.TestHandlerFailure( [Fact] public async Task AsyncUnaryFail() { - await this.TestHandlerFailure(FoobarService.MakeUnaryAsyncRequest).ConfigureAwait(false); + await TestHandlerFailure(FoobarService.MakeUnaryAsyncRequest).ConfigureAwait(false); } /// @@ -97,7 +97,7 @@ static void MakeRequest(Foobar.FoobarClient client) [Fact] public async Task ClientStreamingSuccess() { - await this.TestHandlerSuccess(FoobarService.MakeClientStreamingRequest, DefaultMetadataFunc()).ConfigureAwait(false); + await TestHandlerSuccess(FoobarService.MakeClientStreamingRequest, DefaultMetadataFunc()).ConfigureAwait(false); } /// @@ -107,7 +107,7 @@ public async Task ClientStreamingSuccess() [Fact] public async Task ClientStreamingUnavailable() { - await this.TestHandlerFailure( + await TestHandlerFailure( FoobarService.MakeClientStreamingRequest, StatusCode.Unavailable, validateErrorDescription: false, @@ -121,7 +121,7 @@ await this.TestHandlerFailure( [Fact] public async Task ClientStreamingFail() { - await this.TestHandlerFailure(FoobarService.MakeClientStreamingRequest).ConfigureAwait(false); + await TestHandlerFailure(FoobarService.MakeClientStreamingRequest).ConfigureAwait(false); } /// @@ -145,7 +145,7 @@ static void MakeRequest(Foobar.FoobarClient client) [Fact] public async Task ServerStreamingSuccess() { - await this.TestHandlerSuccess(FoobarService.MakeServerStreamingRequest, DefaultMetadataFunc()).ConfigureAwait(false); + await TestHandlerSuccess(FoobarService.MakeServerStreamingRequest, DefaultMetadataFunc()).ConfigureAwait(false); } /// @@ -155,7 +155,7 @@ public async Task ServerStreamingSuccess() [Fact] public async Task ServerStreamingFail() { - await this.TestHandlerFailure(FoobarService.MakeServerStreamingRequest).ConfigureAwait(false); + await TestHandlerFailure(FoobarService.MakeServerStreamingRequest).ConfigureAwait(false); } /// @@ -179,7 +179,7 @@ static void MakeRequest(Foobar.FoobarClient client) [Fact] public async Task DuplexStreamingSuccess() { - await this.TestHandlerSuccess(FoobarService.MakeDuplexStreamingRequest, DefaultMetadataFunc()).ConfigureAwait(false); + await TestHandlerSuccess(FoobarService.MakeDuplexStreamingRequest, DefaultMetadataFunc()).ConfigureAwait(false); } /// @@ -189,7 +189,7 @@ public async Task DuplexStreamingSuccess() [Fact] public async Task DuplexStreamingUnavailable() { - await this.TestHandlerFailure( + await TestHandlerFailure( FoobarService.MakeDuplexStreamingRequest, StatusCode.Unavailable, validateErrorDescription: false, @@ -203,7 +203,7 @@ await this.TestHandlerFailure( [Fact] public async Task DuplexStreamingFail() { - await this.TestHandlerFailure(FoobarService.MakeDuplexStreamingRequest).ConfigureAwait(false); + await TestHandlerFailure(FoobarService.MakeDuplexStreamingRequest).ConfigureAwait(false); } /// @@ -376,7 +376,7 @@ static void ValidateCommonEventAttributes(ActivityEvent activityEvent) /// The client request function. /// The additional metadata, if any. /// A Task. - private async Task TestHandlerSuccess(Func clientRequestFunc, Metadata additionalMetadata) + private static async Task TestHandlerSuccess(Func clientRequestFunc, Metadata additionalMetadata) { var mockPropagator = new Mock(); PropagationContext capturedPropagationContext = default; @@ -482,7 +482,7 @@ private async Task TestHandlerSuccess(Func /// /// A Task. /// - private async Task TestHandlerFailure( + private static async Task TestHandlerFailure( Func clientRequestFunc, StatusCode statusCode = StatusCode.ResourceExhausted, bool validateErrorDescription = true, diff --git a/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/GrpcCoreServerInterceptorTests.cs b/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/GrpcCoreServerInterceptorTests.cs index 947f6cc88b..916f5779dd 100644 --- a/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/GrpcCoreServerInterceptorTests.cs +++ b/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/GrpcCoreServerInterceptorTests.cs @@ -35,7 +35,7 @@ public class GrpcCoreServerInterceptorTests [Fact] public async Task UnaryServerHandlerSuccess() { - await this.TestHandlerSuccess(FoobarService.MakeUnaryAsyncRequest).ConfigureAwait(false); + await TestHandlerSuccess(FoobarService.MakeUnaryAsyncRequest).ConfigureAwait(false); } /// @@ -45,7 +45,7 @@ public async Task UnaryServerHandlerSuccess() [Fact] public async Task UnaryServerHandlerFail() { - await this.TestHandlerFailure(FoobarService.MakeUnaryAsyncRequest).ConfigureAwait(false); + await TestHandlerFailure(FoobarService.MakeUnaryAsyncRequest).ConfigureAwait(false); } /// @@ -55,7 +55,7 @@ public async Task UnaryServerHandlerFail() [Fact] public async Task ClientStreamingServerHandlerSuccess() { - await this.TestHandlerSuccess(FoobarService.MakeClientStreamingRequest).ConfigureAwait(false); + await TestHandlerSuccess(FoobarService.MakeClientStreamingRequest).ConfigureAwait(false); } /// @@ -65,7 +65,7 @@ public async Task ClientStreamingServerHandlerSuccess() [Fact] public async Task ClientStreamingServerHandlerFail() { - await this.TestHandlerFailure(FoobarService.MakeClientStreamingRequest).ConfigureAwait(false); + await TestHandlerFailure(FoobarService.MakeClientStreamingRequest).ConfigureAwait(false); } /// @@ -75,7 +75,7 @@ public async Task ClientStreamingServerHandlerFail() [Fact] public async Task ServerStreamingServerHandlerSuccess() { - await this.TestHandlerSuccess(FoobarService.MakeServerStreamingRequest).ConfigureAwait(false); + await TestHandlerSuccess(FoobarService.MakeServerStreamingRequest).ConfigureAwait(false); } /// @@ -85,7 +85,7 @@ public async Task ServerStreamingServerHandlerSuccess() [Fact] public async Task ServerStreamingServerHandlerFail() { - await this.TestHandlerFailure(FoobarService.MakeServerStreamingRequest).ConfigureAwait(false); + await TestHandlerFailure(FoobarService.MakeServerStreamingRequest).ConfigureAwait(false); } /// @@ -95,7 +95,7 @@ public async Task ServerStreamingServerHandlerFail() [Fact] public async Task DuplexStreamingServerHandlerSuccess() { - await this.TestHandlerSuccess(FoobarService.MakeDuplexStreamingRequest).ConfigureAwait(false); + await TestHandlerSuccess(FoobarService.MakeDuplexStreamingRequest).ConfigureAwait(false); } /// @@ -105,7 +105,7 @@ public async Task DuplexStreamingServerHandlerSuccess() [Fact] public async Task DuplexStreamingServerHandlerFail() { - await this.TestHandlerFailure(FoobarService.MakeDuplexStreamingRequest).ConfigureAwait(false); + await TestHandlerFailure(FoobarService.MakeDuplexStreamingRequest).ConfigureAwait(false); } /// @@ -114,7 +114,7 @@ public async Task DuplexStreamingServerHandlerFail() /// The specific client request function. /// The additional metadata, if any. /// A Task. - private async Task TestHandlerSuccess(Func clientRequestFunc, Metadata additionalMetadata = null) + private static async Task TestHandlerSuccess(Func clientRequestFunc, Metadata additionalMetadata = null) { // starts the server with the server interceptor var interceptorOptions = new ServerTracingInterceptorOptions { Propagator = new TraceContextPropagator(), RecordMessageEvents = true, ActivityIdentifierValue = Guid.NewGuid() }; @@ -155,7 +155,7 @@ private async Task TestHandlerSuccess(Func /// The specific client request function. /// The additional metadata, if any. /// A Task. - private async Task TestHandlerFailure(Func clientRequestFunc, Metadata additionalMetadata = null) + private static async Task TestHandlerFailure(Func clientRequestFunc, Metadata additionalMetadata = null) { // starts the server with the server interceptor var interceptorOptions = new ServerTracingInterceptorOptions { Propagator = new TraceContextPropagator(), ActivityIdentifierValue = Guid.NewGuid() }; diff --git a/test/OpenTelemetry.Instrumentation.MySqlData.Tests/MySqlDataTests.cs b/test/OpenTelemetry.Instrumentation.MySqlData.Tests/MySqlDataTests.cs index 3f4c105897..0f29d966f6 100644 --- a/test/OpenTelemetry.Instrumentation.MySqlData.Tests/MySqlDataTests.cs +++ b/test/OpenTelemetry.Instrumentation.MySqlData.Tests/MySqlDataTests.cs @@ -55,7 +55,7 @@ public void SuccessTraceEventTest( var traceListener = (TraceListener)Assert.Single(MySqlTrace.Listeners); - this.ExecuteSuccessQuery(traceListener, commandText, isFailure); + ExecuteSuccessQuery(traceListener, commandText, isFailure); Assert.Equal(3, activityProcessor.Invocations.Count); @@ -170,7 +170,7 @@ private static void VerifyActivityData( } } - private void ExecuteSuccessQuery(TraceListener listener, string query, bool isFailure) + private static void ExecuteSuccessQuery(TraceListener listener, string query, bool isFailure) { // Connection opened listener.TraceEvent(