From 32d6db527ba3e4681d4ba0bf838428e04ce8585e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Thu, 31 Oct 2024 20:00:26 +0100 Subject: [PATCH] [repo/AwsInstrumentations] Prepare to .NET9 (#2272) --- .../Implementation/AWSServiceHelper.cs | 42 +++--- .../AWSTracingPipelineHandler.cs | 8 +- .../Implementation/Metrics/AWSHistogram.cs | 5 +- .../Metrics/AWSMeterProvider.cs | 4 +- .../Metrics/AWSMonotonicCounter.cs | 5 +- .../Metrics/AWSUpDownCounter.cs | 5 +- .../Implementation/SnsRequestContextHelper.cs | 4 +- .../Implementation/SqsRequestContextHelper.cs | 4 +- .../Implementation/Tracing/AWSTraceSpan.cs | 1 + .../Implementation/Tracing/AWSTracer.cs | 3 +- .../Tracing/AWSTracerProvider.cs | 4 +- .../Implementation/Utils.cs | 33 ++--- .../Implementation/AWSLambdaHttpUtils.cs | 14 +- .../Implementation/AWSLambdaUtils.cs | 18 +-- .../Implementation/AWSMessagingUtils.cs | 35 ++--- .../RequestContextHelperTests.cs | 2 +- .../Implementation/TestsHelper.cs | 21 ++- .../TestAWSClientInstrumentation.cs | 121 +++++++++--------- .../TestAWSClientMetricsInstrumentation.cs | 10 +- .../TestRequest.cs | 6 +- .../Tools/CustomResponses.cs | 26 ++-- .../Tools/CustomWebResponse.cs | 29 ++--- .../Tools/MockHttpRequest.cs | 27 +--- .../Tools/MockWebResponse.cs | 22 ++-- .../Tools/Utils.cs | 17 +-- .../AWSLambdaWrapperTests.cs | 4 +- .../Implementation/AWSLambdaHttpUtilsTests.cs | 8 +- .../Implementation/AWSMessagingUtilsTests.cs | 24 ++-- .../SampleHandlers.cs | 13 +- .../SampleLambdaContext.cs | 2 +- 30 files changed, 223 insertions(+), 294 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSServiceHelper.cs b/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSServiceHelper.cs index bbe8e318a3..7e87865b3c 100644 --- a/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSServiceHelper.cs +++ b/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSServiceHelper.cs @@ -9,17 +9,17 @@ internal class AWSServiceHelper { internal static IReadOnlyDictionary> ServiceRequestParameterMap = new Dictionary>() { - { AWSServiceType.DynamoDbService, new List { "TableName" } }, - { AWSServiceType.SQSService, new List { "QueueUrl" } }, - { AWSServiceType.BedrockAgentService, new List { "AgentId", "KnowledgeBaseId", "DataSourceId" } }, - { AWSServiceType.BedrockAgentRuntimeService, new List { "AgentId", "KnowledgeBaseId" } }, - { AWSServiceType.BedrockRuntimeService, new List { "ModelId" } }, + { AWSServiceType.DynamoDbService, ["TableName"] }, + { AWSServiceType.SQSService, ["QueueUrl"] }, + { AWSServiceType.BedrockAgentService, ["AgentId", "KnowledgeBaseId", "DataSourceId"] }, + { AWSServiceType.BedrockAgentRuntimeService, ["AgentId", "KnowledgeBaseId"] }, + { AWSServiceType.BedrockRuntimeService, ["ModelId"] }, }; internal static IReadOnlyDictionary> ServiceResponseParameterMap = new Dictionary>() { - { AWSServiceType.BedrockService, new List { "GuardrailId" } }, - { AWSServiceType.BedrockAgentService, new List { "AgentId", "DataSourceId" } }, + { AWSServiceType.BedrockService, ["GuardrailId"] }, + { AWSServiceType.BedrockAgentService, ["AgentId", "DataSourceId"] }, }; internal static IReadOnlyDictionary ParameterAttributeMap = new Dictionary() @@ -34,8 +34,8 @@ internal class AWSServiceHelper }; // for Bedrock Agent operations, we map each supported operation to one resource: Agent, DataSource, or KnowledgeBase - internal static List BedrockAgentAgentOps = new List - { + internal static List BedrockAgentAgentOps = + [ "CreateAgentActionGroup", "CreateAgentAlias", "DeleteAgentActionGroup", @@ -53,11 +53,11 @@ internal class AWSServiceHelper "PrepareAgent", "UpdateAgentActionGroup", "UpdateAgentAlias", - "UpdateAgent", - }; + "UpdateAgent" + ]; - internal static List BedrockAgentKnowledgeBaseOps = new List - { + internal static List BedrockAgentKnowledgeBaseOps = + [ "AssociateAgentKnowledgeBase", "CreateDataSource", "DeleteKnowledgeBase", @@ -65,15 +65,15 @@ internal class AWSServiceHelper "GetAgentKnowledgeBase", "GetKnowledgeBase", "ListDataSources", - "UpdateAgentKnowledgeBase", - }; + "UpdateAgentKnowledgeBase" + ]; - internal static List BedrockAgentDataSourceOps = new List - { + internal static List BedrockAgentDataSourceOps = + [ "DeleteDataSource", "GetDataSource", - "UpdateDataSource", - }; + "UpdateDataSource" + ]; internal static IReadOnlyDictionary OperationNameToResourceMap() { @@ -102,8 +102,8 @@ internal static string GetAWSServiceName(IRequestContext requestContext) internal static string GetAWSOperationName(IRequestContext requestContext) { - string completeRequestName = requestContext.OriginalRequest.GetType().Name; - string suffix = "Request"; + var completeRequestName = requestContext.OriginalRequest.GetType().Name; + var suffix = "Request"; var operationName = Utils.RemoveSuffix(completeRequestName, suffix); return operationName; } diff --git a/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs b/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs index 3ff390ef54..2a13fed2ba 100644 --- a/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs +++ b/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs @@ -34,10 +34,8 @@ public override void InvokeSync(IExecutionContext executionContext) public override async Task InvokeAsync(IExecutionContext executionContext) { - T? ret = null; - var activity = this.ProcessBeginRequest(executionContext); - ret = await base.InvokeAsync(executionContext).ConfigureAwait(false); + var ret = await base.InvokeAsync(executionContext).ConfigureAwait(false); ProcessEndRequest(activity, executionContext); @@ -57,7 +55,7 @@ private static void AddResponseSpecificInformation(Activity activity, IExecution if (AWSServiceHelper.ServiceResponseParameterMap.TryGetValue(service, out var parameters)) { - AmazonWebServiceResponse response = responseContext.Response; + var response = responseContext.Response; foreach (var parameter in parameters) { @@ -129,7 +127,7 @@ private static void AddRequestSpecificInformation(Activity activity, IRequestCon if (AWSServiceHelper.ServiceRequestParameterMap.TryGetValue(service, out var parameters)) { - AmazonWebServiceRequest request = requestContext.OriginalRequest; + var request = requestContext.OriginalRequest; foreach (var parameter in parameters) { diff --git a/src/OpenTelemetry.Instrumentation.AWS/Implementation/Metrics/AWSHistogram.cs b/src/OpenTelemetry.Instrumentation.AWS/Implementation/Metrics/AWSHistogram.cs index dbab867b3f..d8dc7febec 100644 --- a/src/OpenTelemetry.Instrumentation.AWS/Implementation/Metrics/AWSHistogram.cs +++ b/src/OpenTelemetry.Instrumentation.AWS/Implementation/Metrics/AWSHistogram.cs @@ -10,8 +10,7 @@ namespace OpenTelemetry.Instrumentation.AWS.Implementation.Metrics; internal sealed class AWSHistogram : Histogram where T : struct { - private static readonly ConcurrentDictionary> HistogramsDictionary - = new ConcurrentDictionary>(); + private static readonly ConcurrentDictionary> HistogramsDictionary = new(); private readonly System.Diagnostics.Metrics.Histogram histogram; @@ -21,7 +20,7 @@ public AWSHistogram( string? units = null, string? description = null) { - if (HistogramsDictionary.TryGetValue(name, out System.Diagnostics.Metrics.Histogram? histogram)) + if (HistogramsDictionary.TryGetValue(name, out var histogram)) { this.histogram = histogram; } diff --git a/src/OpenTelemetry.Instrumentation.AWS/Implementation/Metrics/AWSMeterProvider.cs b/src/OpenTelemetry.Instrumentation.AWS/Implementation/Metrics/AWSMeterProvider.cs index 240dc565f3..ee5dad188d 100644 --- a/src/OpenTelemetry.Instrumentation.AWS/Implementation/Metrics/AWSMeterProvider.cs +++ b/src/OpenTelemetry.Instrumentation.AWS/Implementation/Metrics/AWSMeterProvider.cs @@ -9,7 +9,7 @@ namespace OpenTelemetry.Instrumentation.AWS.Implementation.Metrics; internal sealed class AWSMeterProvider : MeterProvider { - private static readonly ConcurrentDictionary MetersDictionary = new ConcurrentDictionary(); + private static readonly ConcurrentDictionary MetersDictionary = new(); public override Meter GetMeter(string scope, Attributes? attributes = null) { @@ -20,7 +20,7 @@ public override Meter GetMeter(string scope, Attributes? attributes = null) // update OpenTelemetry core component version(s) to `1.9.0` and allow passing tags to // the meter constructor. - if (MetersDictionary.TryGetValue(scope, out AWSMeter? meter)) + if (MetersDictionary.TryGetValue(scope, out var meter)) { return meter; } diff --git a/src/OpenTelemetry.Instrumentation.AWS/Implementation/Metrics/AWSMonotonicCounter.cs b/src/OpenTelemetry.Instrumentation.AWS/Implementation/Metrics/AWSMonotonicCounter.cs index 7de5568996..aaab9e7b68 100644 --- a/src/OpenTelemetry.Instrumentation.AWS/Implementation/Metrics/AWSMonotonicCounter.cs +++ b/src/OpenTelemetry.Instrumentation.AWS/Implementation/Metrics/AWSMonotonicCounter.cs @@ -10,8 +10,7 @@ namespace OpenTelemetry.Instrumentation.AWS.Implementation.Metrics; internal sealed class AWSMonotonicCounter : MonotonicCounter where T : struct { - private static readonly ConcurrentDictionary> MonotonicCountersDictionary - = new ConcurrentDictionary>(); + private static readonly ConcurrentDictionary> MonotonicCountersDictionary = new(); private readonly System.Diagnostics.Metrics.Counter monotonicCounter; @@ -21,7 +20,7 @@ public AWSMonotonicCounter( string? units = null, string? description = null) { - if (MonotonicCountersDictionary.TryGetValue(name, out System.Diagnostics.Metrics.Counter? monotonicCounter)) + if (MonotonicCountersDictionary.TryGetValue(name, out var monotonicCounter)) { this.monotonicCounter = monotonicCounter; } diff --git a/src/OpenTelemetry.Instrumentation.AWS/Implementation/Metrics/AWSUpDownCounter.cs b/src/OpenTelemetry.Instrumentation.AWS/Implementation/Metrics/AWSUpDownCounter.cs index 2800ebacee..7757814b14 100644 --- a/src/OpenTelemetry.Instrumentation.AWS/Implementation/Metrics/AWSUpDownCounter.cs +++ b/src/OpenTelemetry.Instrumentation.AWS/Implementation/Metrics/AWSUpDownCounter.cs @@ -10,8 +10,7 @@ namespace OpenTelemetry.Instrumentation.AWS.Implementation.Metrics; internal sealed class AWSUpDownCounter : UpDownCounter where T : struct { - private static readonly ConcurrentDictionary> UpDownCountersDictionary - = new ConcurrentDictionary>(); + private static readonly ConcurrentDictionary> UpDownCountersDictionary = new(); private readonly System.Diagnostics.Metrics.UpDownCounter upDownCounter; @@ -21,7 +20,7 @@ public AWSUpDownCounter( string? units = null, string? description = null) { - if (UpDownCountersDictionary.TryGetValue(name, out System.Diagnostics.Metrics.UpDownCounter? upDownCounter)) + if (UpDownCountersDictionary.TryGetValue(name, out var upDownCounter)) { this.upDownCounter = upDownCounter; } diff --git a/src/OpenTelemetry.Instrumentation.AWS/Implementation/SnsRequestContextHelper.cs b/src/OpenTelemetry.Instrumentation.AWS/Implementation/SnsRequestContextHelper.cs index b7988f4e20..eee5ecc7f8 100644 --- a/src/OpenTelemetry.Instrumentation.AWS/Implementation/SnsRequestContextHelper.cs +++ b/src/OpenTelemetry.Instrumentation.AWS/Implementation/SnsRequestContextHelper.cs @@ -21,13 +21,13 @@ internal static void AddAttributes(IRequestContext context, IReadOnlyDictionary< return; } - if (attributes.Keys.Any(k => originalRequest.MessageAttributes.ContainsKey(k))) + if (attributes.Keys.Any(originalRequest.MessageAttributes.ContainsKey)) { // If at least one attribute is already present in the request then we skip the injection. return; } - int attributesCount = originalRequest.MessageAttributes.Count; + var attributesCount = originalRequest.MessageAttributes.Count; if (attributes.Count + attributesCount > MaxMessageAttributes) { // TODO: add logging (event source). diff --git a/src/OpenTelemetry.Instrumentation.AWS/Implementation/SqsRequestContextHelper.cs b/src/OpenTelemetry.Instrumentation.AWS/Implementation/SqsRequestContextHelper.cs index 06d873adfd..fdeb26ac64 100644 --- a/src/OpenTelemetry.Instrumentation.AWS/Implementation/SqsRequestContextHelper.cs +++ b/src/OpenTelemetry.Instrumentation.AWS/Implementation/SqsRequestContextHelper.cs @@ -21,13 +21,13 @@ internal static void AddAttributes(IRequestContext context, IReadOnlyDictionary< return; } - if (attributes.Keys.Any(k => originalRequest.MessageAttributes.ContainsKey(k))) + if (attributes.Keys.Any(originalRequest.MessageAttributes.ContainsKey)) { // If at least one attribute is already present in the request then we skip the injection. return; } - int attributesCount = originalRequest.MessageAttributes.Count; + var attributesCount = originalRequest.MessageAttributes.Count; if (attributes.Count + attributesCount > MaxMessageAttributes) { // TODO: add logging (event source). diff --git a/src/OpenTelemetry.Instrumentation.AWS/Implementation/Tracing/AWSTraceSpan.cs b/src/OpenTelemetry.Instrumentation.AWS/Implementation/Tracing/AWSTraceSpan.cs index 98de524b14..4e1e494b35 100644 --- a/src/OpenTelemetry.Instrumentation.AWS/Implementation/Tracing/AWSTraceSpan.cs +++ b/src/OpenTelemetry.Instrumentation.AWS/Implementation/Tracing/AWSTraceSpan.cs @@ -85,6 +85,7 @@ private static ActivityStatusCode ConvertToActivityStatusCode(SpanStatus status) { SpanStatus.OK => ActivityStatusCode.Ok, SpanStatus.ERROR => ActivityStatusCode.Error, + SpanStatus.UNSET => ActivityStatusCode.Unset, _ => ActivityStatusCode.Unset, }; } diff --git a/src/OpenTelemetry.Instrumentation.AWS/Implementation/Tracing/AWSTracer.cs b/src/OpenTelemetry.Instrumentation.AWS/Implementation/Tracing/AWSTracer.cs index ecf8418e6a..001b2915e5 100644 --- a/src/OpenTelemetry.Instrumentation.AWS/Implementation/Tracing/AWSTracer.cs +++ b/src/OpenTelemetry.Instrumentation.AWS/Implementation/Tracing/AWSTracer.cs @@ -29,7 +29,7 @@ public override TraceSpan CreateSpan( var tags = initialAttributes != null ? new ActivityTagsCollection(initialAttributes.AllAttributes) : null; var activityKind = ConvertToActivityKind(spanKind); - ActivityContext parentActivityContext = ConvertToActivityContext(parentContext); + var parentActivityContext = ConvertToActivityContext(parentContext); var activity = this.activitySource.StartActivity(name, activityKind, parentActivityContext, tags); return new AWSTraceSpan(activity); @@ -66,6 +66,7 @@ private static ActivityKind ConvertToActivityKind(SpanKind spanKind) SpanKind.SERVER => ActivityKind.Server, SpanKind.PRODUCER => ActivityKind.Producer, SpanKind.CONSUMER => ActivityKind.Consumer, + SpanKind.INTERNAL => ActivityKind.Internal, _ => ActivityKind.Internal, }; } diff --git a/src/OpenTelemetry.Instrumentation.AWS/Implementation/Tracing/AWSTracerProvider.cs b/src/OpenTelemetry.Instrumentation.AWS/Implementation/Tracing/AWSTracerProvider.cs index 44fa4986f2..99817b4f97 100644 --- a/src/OpenTelemetry.Instrumentation.AWS/Implementation/Tracing/AWSTracerProvider.cs +++ b/src/OpenTelemetry.Instrumentation.AWS/Implementation/Tracing/AWSTracerProvider.cs @@ -9,11 +9,11 @@ namespace OpenTelemetry.Instrumentation.AWS.Implementation.Tracing; internal sealed class AWSTracerProvider : TracerProvider { - private static readonly ConcurrentDictionary TracersDictionary = new ConcurrentDictionary(); + private static readonly ConcurrentDictionary TracersDictionary = new(); public override Tracer GetTracer(string scope) { - if (TracersDictionary.TryGetValue(scope, out AWSTracer? awsTracer)) + if (TracersDictionary.TryGetValue(scope, out var awsTracer)) { return awsTracer; } diff --git a/src/OpenTelemetry.Instrumentation.AWS/Implementation/Utils.cs b/src/OpenTelemetry.Instrumentation.AWS/Implementation/Utils.cs index 1cb7fe979a..3919ea16bd 100644 --- a/src/OpenTelemetry.Instrumentation.AWS/Implementation/Utils.cs +++ b/src/OpenTelemetry.Instrumentation.AWS/Implementation/Utils.cs @@ -9,7 +9,7 @@ internal class Utils { internal static object? GetTagValue(Activity activity, string tagName) { - foreach (KeyValuePair tag in activity.TagObjects) + foreach (var tag in activity.TagObjects) { if (tag.Key.Equals(tagName, StringComparison.Ordinal)) { @@ -22,17 +22,12 @@ internal class Utils internal static string RemoveSuffix(string originalString, string suffix) { - if (string.IsNullOrEmpty(originalString)) - { - return string.Empty; - } - - if (originalString.EndsWith(suffix, StringComparison.Ordinal)) - { - return originalString.Substring(0, originalString.Length - suffix.Length); - } - - return originalString; + return string.IsNullOrEmpty(originalString) + ? string.Empty + : originalString.EndsWith(suffix, StringComparison.Ordinal) + ? + originalString.Substring(0, originalString.Length - suffix.Length) + : originalString; } /// @@ -50,16 +45,8 @@ internal static string RemoveAmazonPrefixFromServiceName(string serviceName) private static string RemovePrefix(string originalString, string prefix) { - if (string.IsNullOrEmpty(originalString)) - { - return string.Empty; - } - - if (originalString.StartsWith(prefix, StringComparison.Ordinal)) - { - return originalString.Substring(prefix.Length); - } - - return originalString; + return string.IsNullOrEmpty(originalString) ? string.Empty : + originalString.StartsWith(prefix, StringComparison.Ordinal) ? originalString.Substring(prefix.Length) : + originalString; } } diff --git a/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSLambdaHttpUtils.cs b/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSLambdaHttpUtils.cs index 38273c5331..958f3923c1 100644 --- a/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSLambdaHttpUtils.cs +++ b/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSLambdaHttpUtils.cs @@ -20,11 +20,11 @@ internal static IEnumerable> GetHttpTags(TI { var tags = new List>(); - string? httpScheme = null; - string? httpTarget = null; - string? httpMethod = null; - string? hostName = null; - int? hostPort = null; + string? httpScheme; + string? httpTarget; + string? httpMethod; + string? hostName; + int? hostPort; switch (input) { @@ -81,6 +81,8 @@ internal static void SetHttpTagsFromResult(Activity? activity, object? result) case ApplicationLoadBalancerResponse albResponse: activity.SetTag(SemanticConventions.AttributeHttpStatusCode, albResponse.StatusCode); break; + default: + break; } } @@ -165,7 +167,7 @@ internal static (string? Host, int? Port) GetHostAndPort(string? httpScheme, str } #pragma warning disable CA1861 // Prefer 'static readonly' fields over constant array arguments if the called method is called repeatedly and is not mutating the passed array - var hostAndPort = hostHeader.Split(new char[] { ':' }, 2); + var hostAndPort = hostHeader.Split([':'], 2); #pragma warning restore CA1861 // Prefer 'static readonly' fields over constant array arguments if the called method is called repeatedly and is not mutating the passed array if (hostAndPort.Length > 1) { diff --git a/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSLambdaUtils.cs b/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSLambdaUtils.cs index 5c0430ce05..56902fa909 100644 --- a/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSLambdaUtils.cs +++ b/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSLambdaUtils.cs @@ -26,12 +26,7 @@ internal static class AWSLambdaUtils private static readonly Func, string, IEnumerable> Getter = (headers, name) => { - if (headers.TryGetValue(name, out var value)) - { - return new[] { value }; - } - - return Array.Empty(); + return headers.TryGetValue(name, out var value) ? [value] : []; }; internal static ActivityContext GetXRayParentContext() @@ -77,6 +72,8 @@ internal static (ActivityContext ParentContext, IEnumerable? Links case SNSEvent.SNSRecord snsRecord: parentContext = AWSMessagingUtils.ExtractParentContext(snsRecord); break; + default: + break; } return (parentContext.ActivityContext, links); @@ -179,12 +176,7 @@ internal static IEnumerable> GetFunctionTags::function: var items = functionArn.Split(':'); - if (items.Length >= 5) - { - return items[4]; - } - - return null; + return items.Length >= 5 ? items[4] : null; } private static string GetFaasId(string functionArn) @@ -207,7 +199,7 @@ private static string GetFaasTrigger(TInput input) => IsHttpRequest(input) ? "http" : "other"; private static bool IsHttpRequest(TInput input) => - input is APIGatewayProxyRequest || input is APIGatewayHttpApiV2ProxyRequest || input is ApplicationLoadBalancerRequest; + input is APIGatewayProxyRequest or APIGatewayHttpApiV2ProxyRequest or ApplicationLoadBalancerRequest; private static ActivityContext ParseXRayTraceHeader(string rawHeader) { diff --git a/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSMessagingUtils.cs b/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSMessagingUtils.cs index 47c571908e..50ea0bdeb1 100644 --- a/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSMessagingUtils.cs +++ b/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSMessagingUtils.cs @@ -58,7 +58,7 @@ internal static PropagationContext ExtractParentContext(SQSEvent.SQSMessage sqsM { // SQS subscribed to SNS topic with raw delivery disabled case, i.e. SNS record serialized into SQS body. // https://docs.aws.amazon.com/sns/latest/dg/sns-large-payload-raw-message-delivery.html - SNSEvent.SNSMessage? snsMessage = GetSnsMessage(sqsMessage); + var snsMessage = GetSnsMessage(sqsMessage); parentContext = ExtractParentContext(snsMessage); } @@ -89,33 +89,22 @@ internal static PropagationContext ExtractParentContext(SNSEvent.SNSMessage? mes private static IEnumerable? SqsMessageAttributeGetter(IDictionary attributes, string attributeName) { - if (!attributes.TryGetValue(attributeName, out var attribute)) - { - return null; - } - - return attribute?.StringValue != null ? - new[] { attribute.StringValue } : + return !attributes.TryGetValue(attributeName, out var attribute) ? null : + attribute?.StringValue != null ? new[] { attribute.StringValue } : attribute?.StringListValues; } private static IEnumerable? SnsMessageAttributeGetter(IDictionary attributes, string attributeName) { - if (!attributes.TryGetValue(attributeName, out var attribute)) - { - return null; - } - - switch (attribute?.Type) - { - case SnsAttributeTypeString when attribute.Value != null: - return new[] { attribute.Value }; - case SnsAttributeTypeStringArray when attribute.Value != null: - // Multiple values are stored as CSV (https://docs.aws.amazon.com/sns/latest/dg/sns-message-attributes.html). - return attribute.Value.Split(','); - default: - return null; - } + return !attributes.TryGetValue(attributeName, out var attribute) + ? null + : attribute?.Type switch + { + SnsAttributeTypeString when attribute.Value != null => [attribute.Value], + SnsAttributeTypeStringArray when attribute.Value != null => + attribute.Value.Split(','), // Multiple values are stored as CSV (https://docs.aws.amazon.com/sns/latest/dg/sns-message-attributes.html). + _ => null, + }; } private static SNSEvent.SNSMessage? GetSnsMessage(SQSEvent.SQSMessage sqsMessage) diff --git a/test/OpenTelemetry.Instrumentation.AWS.Tests/Implementation/RequestContextHelperTests.cs b/test/OpenTelemetry.Instrumentation.AWS.Tests/Implementation/RequestContextHelperTests.cs index 7e465a4694..d49ac7601c 100644 --- a/test/OpenTelemetry.Instrumentation.AWS.Tests/Implementation/RequestContextHelperTests.cs +++ b/test/OpenTelemetry.Instrumentation.AWS.Tests/Implementation/RequestContextHelperTests.cs @@ -37,7 +37,7 @@ public void AddAttributes_ParametersCollectionSizeReachesLimit_TraceDataNotInjec var context = new TestRequestContext(originalRequest, request); - var addAttributes = TestsHelper.CreateAddAttributesAction(serviceType, context); + var addAttributes = TestsHelper.CreateAddAttributesAction(serviceType); addAttributes?.Invoke(context, AWSMessagingUtils.InjectIntoDictionary(CreatePropagationContext())); Assert.Equal(30, parameters.Count); diff --git a/test/OpenTelemetry.Instrumentation.AWS.Tests/Implementation/TestsHelper.cs b/test/OpenTelemetry.Instrumentation.AWS.Tests/Implementation/TestsHelper.cs index e695853e2f..519b677628 100644 --- a/test/OpenTelemetry.Instrumentation.AWS.Tests/Implementation/TestsHelper.cs +++ b/test/OpenTelemetry.Instrumentation.AWS.Tests/Implementation/TestsHelper.cs @@ -16,9 +16,9 @@ internal static class TestsHelper /// Returns either or /// depending on . /// - /// This is meant to mimic thee logic in . + /// This is meant to mimic these logic in . /// - internal static Action>? CreateAddAttributesAction(string serviceType, IRequestContext context) + internal static Action>? CreateAddAttributesAction(string serviceType) { return serviceType switch { @@ -49,7 +49,7 @@ internal static AmazonWebServiceRequest CreateOriginalRequest(string serviceType throw new NotSupportedException($"Tests for service type {serviceType} not supported."); } - for (int i = 1; i <= attributesCount; i++) + for (var i = 1; i <= attributesCount; i++) { addAttribute(i); } @@ -59,15 +59,14 @@ internal static AmazonWebServiceRequest CreateOriginalRequest(string serviceType internal static void AddAttribute(this AmazonWebServiceRequest serviceRequest, string name, string value) { - var sendRequest = serviceRequest as SQS::SendMessageRequest; var publishRequest = serviceRequest as SNS::PublishRequest; - if (sendRequest != null) + if (serviceRequest is SQS::SendMessageRequest sendRequest) { sendRequest.MessageAttributes.Add(name, new SQS::MessageAttributeValue { DataType = "String", StringValue = value }); } - else if (publishRequest != null) + else { - publishRequest.MessageAttributes.Add(name, new SNS::MessageAttributeValue { DataType = "String", StringValue = value }); + publishRequest?.MessageAttributes.Add(name, new SNS::MessageAttributeValue { DataType = "String", StringValue = value }); } } @@ -81,17 +80,15 @@ internal static void AddStringParameter(this ParameterCollection parameters, str internal static void AddStringParameters(this ParameterCollection parameters, string serviceType, AmazonWebServiceRequest serviceRequest) { - var sendRequest = serviceRequest as SQS::SendMessageRequest; - var publishRequest = serviceRequest as SNS::PublishRequest; - int index = 1; - if (sendRequest != null) + var index = 1; + if (serviceRequest is SQS::SendMessageRequest sendRequest) { foreach (var a in sendRequest.MessageAttributes) { AddStringParameter(parameters, serviceType, a.Key, a.Value.StringValue, index++); } } - else if (publishRequest != null) + else if (serviceRequest is SNS::PublishRequest publishRequest) { foreach (var a in publishRequest.MessageAttributes) { diff --git a/test/OpenTelemetry.Instrumentation.AWS.Tests/TestAWSClientInstrumentation.cs b/test/OpenTelemetry.Instrumentation.AWS.Tests/TestAWSClientInstrumentation.cs index 558da3791e..7d466c0cf4 100644 --- a/test/OpenTelemetry.Instrumentation.AWS.Tests/TestAWSClientInstrumentation.cs +++ b/test/OpenTelemetry.Instrumentation.AWS.Tests/TestAWSClientInstrumentation.cs @@ -34,7 +34,7 @@ public async Task TestDDBScanSuccessful() var exportedItems = new List(); var parent = new Activity("parent").Start(); - string requestId = @"fakerequ-esti-dfak-ereq-uestidfakere"; + var requestId = @"fakerequ-esti-dfak-ereq-uestidfakere"; using (Sdk.CreateTracerProviderBuilder() .SetSampler(new AlwaysOnSampler()) @@ -48,7 +48,7 @@ public async Task TestDDBScanSuccessful() var scan_request = new ScanRequest { TableName = "SampleProduct", - AttributesToGet = new List { "Id", "Name" }, + AttributesToGet = ["Id", "Name"], }; #if NETFRAMEWORK ddb.Scan(scan_request); @@ -59,7 +59,7 @@ public async Task TestDDBScanSuccessful() Assert.NotEmpty(exportedItems); - Activity? awssdk_activity = exportedItems.FirstOrDefault(e => e.DisplayName == "DynamoDB.Scan"); + var awssdk_activity = exportedItems.FirstOrDefault(e => e.DisplayName == "DynamoDB.Scan"); Assert.NotNull(awssdk_activity); this.ValidateAWSActivity(awssdk_activity, parent); @@ -79,7 +79,7 @@ public async Task TestDDBSubtypeScanSuccessful() var exportedItems = new List(); var parent = new Activity("parent").Start(); - string requestId = @"fakerequ-esti-dfak-ereq-uestidfakere"; + var requestId = @"fakerequ-esti-dfak-ereq-uestidfakere"; using (Sdk.CreateTracerProviderBuilder() .SetSampler(new AlwaysOnSampler()) @@ -93,7 +93,7 @@ public async Task TestDDBSubtypeScanSuccessful() var scan_request = new ScanRequest { TableName = "SampleProduct", - AttributesToGet = new List() { "Id", "Name" }, + AttributesToGet = ["Id", "Name"], }; #if NETFRAMEWORK ddb.Scan(scan_request); @@ -104,7 +104,7 @@ public async Task TestDDBSubtypeScanSuccessful() Assert.NotEmpty(exportedItems); - Activity? awssdk_activity = exportedItems.FirstOrDefault(e => e.DisplayName == "DynamoDB.Scan"); + var awssdk_activity = exportedItems.FirstOrDefault(e => e.DisplayName == "DynamoDB.Scan"); Assert.NotNull(awssdk_activity); this.ValidateAWSActivity(awssdk_activity, parent); @@ -124,7 +124,7 @@ public async Task TestDDBScanUnsuccessful() var exportedItems = new List(); var parent = new Activity("parent").Start(); - string requestId = @"fakerequ-esti-dfak-ereq-uestidfakere"; + var requestId = @"fakerequ-esti-dfak-ereq-uestidfakere"; using (Sdk.CreateTracerProviderBuilder() .SetSampler(new AlwaysOnSampler()) @@ -134,14 +134,16 @@ public async Task TestDDBScanUnsuccessful() .Build()) { var ddb = new AmazonDynamoDBClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1); - AmazonServiceException amazonServiceException = new AmazonServiceException(); - amazonServiceException.StatusCode = System.Net.HttpStatusCode.NotFound; - amazonServiceException.RequestId = requestId; + var amazonServiceException = new AmazonServiceException + { + StatusCode = System.Net.HttpStatusCode.NotFound, + RequestId = requestId, + }; CustomResponses.SetResponse(ddb, (request) => { throw amazonServiceException; }); var scan_request = new ScanRequest { TableName = "SampleProduct", - AttributesToGet = new List() { "Id", "Name" }, + AttributesToGet = ["Id", "Name"], }; try @@ -160,7 +162,7 @@ public async Task TestDDBScanUnsuccessful() Assert.NotEmpty(exportedItems); - Activity? awssdk_activity = exportedItems.FirstOrDefault(e => e.DisplayName == "DynamoDB.Scan"); + var awssdk_activity = exportedItems.FirstOrDefault(e => e.DisplayName == "DynamoDB.Scan"); Assert.NotNull(awssdk_activity); this.ValidateAWSActivity(awssdk_activity, parent); @@ -181,7 +183,7 @@ public async Task TestSQSSendMessageSuccessful() var exportedItems = new List(); var parent = new Activity("parent").Start(); - string requestId = @"fakerequ-esti-dfak-ereq-uestidfakere"; + var requestId = @"fakerequ-esti-dfak-ereq-uestidfakere"; using (Sdk.CreateTracerProviderBuilder() .AddXRayTraceId() @@ -191,11 +193,13 @@ public async Task TestSQSSendMessageSuccessful() .Build()) { var sqs = new AmazonSQSClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1); - string dummyResponse = "{}"; + var dummyResponse = "{}"; CustomResponses.SetResponse(sqs, dummyResponse, requestId, true); - var send_msg_req = new SendMessageRequest(); - send_msg_req.QueueUrl = "https://sqs.us-east-1.amazonaws.com/123456789/MyTestQueue"; - send_msg_req.MessageBody = "Hello from OT"; + var send_msg_req = new SendMessageRequest + { + QueueUrl = "https://sqs.us-east-1.amazonaws.com/123456789/MyTestQueue", + MessageBody = "Hello from OT", + }; send_msg_req.MessageAttributes.Add("Custom", new MessageAttributeValue { StringValue = "Value", DataType = "String" }); #if NETFRAMEWORK sqs.SendMessage(send_msg_req); @@ -205,7 +209,7 @@ public async Task TestSQSSendMessageSuccessful() } Assert.NotEmpty(exportedItems); - Activity? awssdk_activity = exportedItems.FirstOrDefault(e => e.DisplayName == "SQS.SendMessage"); + var awssdk_activity = exportedItems.FirstOrDefault(e => e.DisplayName == "SQS.SendMessage"); Assert.NotNull(awssdk_activity); this.ValidateAWSActivity(awssdk_activity, parent); @@ -225,7 +229,7 @@ public async Task TestBedrockGetGuardrailSuccessful() var exportedItems = new List(); var parent = new Activity("parent").Start(); - string requestId = @"fakerequ-esti-dfak-ereq-uestidfakere"; + var requestId = @"fakerequ-esti-dfak-ereq-uestidfakere"; using (Sdk.CreateTracerProviderBuilder() .AddXRayTraceId() @@ -235,10 +239,9 @@ public async Task TestBedrockGetGuardrailSuccessful() .Build()) { var bedrock = new AmazonBedrockClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1); - string dummyResponse = "{\"GuardrailId\":\"123456789\"}"; + var dummyResponse = "{\"GuardrailId\":\"123456789\"}"; CustomResponses.SetResponse(bedrock, dummyResponse, requestId, true); - var getGuardrailRequest = new GetGuardrailRequest(); - getGuardrailRequest.GuardrailIdentifier = "123456789"; + var getGuardrailRequest = new GetGuardrailRequest { GuardrailIdentifier = "123456789" }; #if NETFRAMEWORK bedrock.GetGuardrail(getGuardrailRequest); #else @@ -247,7 +250,7 @@ public async Task TestBedrockGetGuardrailSuccessful() } Assert.NotEmpty(exportedItems); - Activity? awssdk_activity = exportedItems.FirstOrDefault(e => e.DisplayName == "Bedrock.GetGuardrail"); + var awssdk_activity = exportedItems.FirstOrDefault(e => e.DisplayName == "Bedrock.GetGuardrail"); Assert.NotNull(awssdk_activity); this.ValidateAWSActivity(awssdk_activity, parent); @@ -267,7 +270,7 @@ public async Task TestBedrockRuntimeInvokeModelSuccessful() var exportedItems = new List(); var parent = new Activity("parent").Start(); - string requestId = @"fakerequ-esti-dfak-ereq-uestidfakere"; + var requestId = @"fakerequ-esti-dfak-ereq-uestidfakere"; using (Sdk.CreateTracerProviderBuilder() .AddXRayTraceId() @@ -277,10 +280,9 @@ public async Task TestBedrockRuntimeInvokeModelSuccessful() .Build()) { var bedrockruntime = new AmazonBedrockRuntimeClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1); - string dummyResponse = "{}"; + var dummyResponse = "{}"; CustomResponses.SetResponse(bedrockruntime, dummyResponse, requestId, true); - var invokeModelRequest = new InvokeModelRequest(); - invokeModelRequest.ModelId = "amazon.titan-text-express-v1"; + var invokeModelRequest = new InvokeModelRequest { ModelId = "amazon.titan-text-express-v1" }; #if NETFRAMEWORK var response = bedrockruntime.InvokeModel(invokeModelRequest); #else @@ -289,7 +291,7 @@ public async Task TestBedrockRuntimeInvokeModelSuccessful() } Assert.NotEmpty(exportedItems); - Activity? awssdk_activity = exportedItems.FirstOrDefault(e => e.DisplayName == "Bedrock Runtime.InvokeModel"); + var awssdk_activity = exportedItems.FirstOrDefault(e => e.DisplayName == "Bedrock Runtime.InvokeModel"); Assert.NotNull(awssdk_activity); this.ValidateAWSActivity(awssdk_activity, parent); @@ -309,7 +311,7 @@ public async Task TestBedrockAgentGetAgentSuccessful() var exportedItems = new List(); var parent = new Activity("parent").Start(); - string requestId = @"fakerequ-esti-dfak-ereq-uestidfakere"; + var requestId = @"fakerequ-esti-dfak-ereq-uestidfakere"; using (Sdk.CreateTracerProviderBuilder() .AddXRayTraceId() @@ -319,10 +321,9 @@ public async Task TestBedrockAgentGetAgentSuccessful() .Build()) { var bedrockagent = new AmazonBedrockAgentClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1); - string dummyResponse = "{}"; + var dummyResponse = "{}"; CustomResponses.SetResponse(bedrockagent, dummyResponse, requestId, true); - var getAgentRequest = new GetAgentRequest(); - getAgentRequest.AgentId = "1234567890"; + var getAgentRequest = new GetAgentRequest { AgentId = "1234567890" }; #if NETFRAMEWORK var response = bedrockagent.GetAgent(getAgentRequest); #else @@ -331,7 +332,7 @@ public async Task TestBedrockAgentGetAgentSuccessful() } Assert.NotEmpty(exportedItems); - Activity? awssdk_activity = exportedItems.FirstOrDefault(e => e.DisplayName == "Bedrock Agent.GetAgent"); + var awssdk_activity = exportedItems.FirstOrDefault(e => e.DisplayName == "Bedrock Agent.GetAgent"); Assert.NotNull(awssdk_activity); this.ValidateAWSActivity(awssdk_activity, parent); @@ -351,7 +352,7 @@ public async Task TestBedrockAgentGetKnowledgeBaseSuccessful() var exportedItems = new List(); var parent = new Activity("parent").Start(); - string requestId = @"fakerequ-esti-dfak-ereq-uestidfakere"; + var requestId = @"fakerequ-esti-dfak-ereq-uestidfakere"; using (Sdk.CreateTracerProviderBuilder() .AddXRayTraceId() @@ -361,10 +362,9 @@ public async Task TestBedrockAgentGetKnowledgeBaseSuccessful() .Build()) { var bedrockagent = new AmazonBedrockAgentClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1); - string dummyResponse = "{}"; + var dummyResponse = "{}"; CustomResponses.SetResponse(bedrockagent, dummyResponse, requestId, true); - var getKnowledgeBaseRequest = new GetKnowledgeBaseRequest(); - getKnowledgeBaseRequest.KnowledgeBaseId = "1234567890"; + var getKnowledgeBaseRequest = new GetKnowledgeBaseRequest { KnowledgeBaseId = "1234567890" }; #if NETFRAMEWORK var response = bedrockagent.GetKnowledgeBase(getKnowledgeBaseRequest); #else @@ -373,7 +373,7 @@ public async Task TestBedrockAgentGetKnowledgeBaseSuccessful() } Assert.NotEmpty(exportedItems); - Activity? awssdk_activity = exportedItems.FirstOrDefault(e => e.DisplayName == "Bedrock Agent.GetKnowledgeBase"); + var awssdk_activity = exportedItems.FirstOrDefault(e => e.DisplayName == "Bedrock Agent.GetKnowledgeBase"); Assert.NotNull(awssdk_activity); this.ValidateAWSActivity(awssdk_activity, parent); @@ -393,7 +393,7 @@ public async Task TestBedrockAgentGetDataSourceSuccessful() var exportedItems = new List(); var parent = new Activity("parent").Start(); - string requestId = @"fakerequ-esti-dfak-ereq-uestidfakere"; + var requestId = @"fakerequ-esti-dfak-ereq-uestidfakere"; using (Sdk.CreateTracerProviderBuilder() .AddXRayTraceId() @@ -403,11 +403,9 @@ public async Task TestBedrockAgentGetDataSourceSuccessful() .Build()) { var bedrockagent = new AmazonBedrockAgentClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1); - string dummyResponse = "{}"; + var dummyResponse = "{}"; CustomResponses.SetResponse(bedrockagent, dummyResponse, requestId, true); - var getDataSourceRequest = new GetDataSourceRequest(); - getDataSourceRequest.DataSourceId = "1234567890"; - getDataSourceRequest.KnowledgeBaseId = "1234567890"; + var getDataSourceRequest = new GetDataSourceRequest { DataSourceId = "1234567890", KnowledgeBaseId = "1234567890", }; #if NETFRAMEWORK var response = bedrockagent.GetDataSource(getDataSourceRequest); #else @@ -416,7 +414,7 @@ public async Task TestBedrockAgentGetDataSourceSuccessful() } Assert.NotEmpty(exportedItems); - Activity? awssdk_activity = exportedItems.FirstOrDefault(e => e.DisplayName == "Bedrock Agent.GetDataSource"); + var awssdk_activity = exportedItems.FirstOrDefault(e => e.DisplayName == "Bedrock Agent.GetDataSource"); Assert.NotNull(awssdk_activity); this.ValidateAWSActivity(awssdk_activity, parent); @@ -436,7 +434,7 @@ public async Task TestBedrockAgentRuntimeInvokeAgentSuccessful() var exportedItems = new List(); var parent = new Activity("parent").Start(); - string requestId = @"fakerequ-esti-dfak-ereq-uestidfakere"; + var requestId = @"fakerequ-esti-dfak-ereq-uestidfakere"; using (Sdk.CreateTracerProviderBuilder() .AddXRayTraceId() @@ -445,23 +443,25 @@ public async Task TestBedrockAgentRuntimeInvokeAgentSuccessful() .AddInMemoryExporter(exportedItems) .Build()) { - var bedrockagentruntime = new AmazonBedrockAgentRuntimeClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1); - string dummyResponse = "{}"; - CustomResponses.SetResponse(bedrockagentruntime, dummyResponse, requestId, true); - var invokeAgentRequest = new InvokeAgentRequest(); - invokeAgentRequest.AgentId = "123456789"; - invokeAgentRequest.AgentAliasId = "testalias"; - invokeAgentRequest.SessionId = "test-session-id"; - invokeAgentRequest.InputText = "sample input text"; + var bedrockAgentRuntimeClient = new AmazonBedrockAgentRuntimeClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1); + var dummyResponse = "{}"; + CustomResponses.SetResponse(bedrockAgentRuntimeClient, dummyResponse, requestId, true); + var invokeAgentRequest = new InvokeAgentRequest + { + AgentId = "123456789", + AgentAliasId = "testalias", + SessionId = "test-session-id", + InputText = "sample input text", + }; #if NETFRAMEWORK - var response = bedrockagentruntime.InvokeAgent(invokeAgentRequest); + var response = bedrockAgentRuntimeClient.InvokeAgent(invokeAgentRequest); #else - var response = await bedrockagentruntime.InvokeAgentAsync(invokeAgentRequest); + var response = await bedrockAgentRuntimeClient.InvokeAgentAsync(invokeAgentRequest); #endif } Assert.NotEmpty(exportedItems); - Activity? awssdk_activity = exportedItems.FirstOrDefault(e => e.DisplayName == "Bedrock Agent Runtime.InvokeAgent"); + var awssdk_activity = exportedItems.FirstOrDefault(e => e.DisplayName == "Bedrock Agent Runtime.InvokeAgent"); Assert.NotNull(awssdk_activity); this.ValidateAWSActivity(awssdk_activity, parent); @@ -481,7 +481,7 @@ public async Task TestBedrockAgentRuntimeRetrieveSuccessful() var exportedItems = new List(); var parent = new Activity("parent").Start(); - string requestId = @"fakerequ-esti-dfak-ereq-uestidfakere"; + var requestId = @"fakerequ-esti-dfak-ereq-uestidfakere"; using (Sdk.CreateTracerProviderBuilder() .AddXRayTraceId() @@ -491,10 +491,9 @@ public async Task TestBedrockAgentRuntimeRetrieveSuccessful() .Build()) { var bedrockagentruntime = new AmazonBedrockAgentRuntimeClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1); - string dummyResponse = "{}"; + var dummyResponse = "{}"; CustomResponses.SetResponse(bedrockagentruntime, dummyResponse, requestId, true); - var retrieveRequest = new RetrieveRequest(); - retrieveRequest.KnowledgeBaseId = "123456789"; + var retrieveRequest = new RetrieveRequest { KnowledgeBaseId = "123456789" }; #if NETFRAMEWORK var response = bedrockagentruntime.Retrieve(retrieveRequest); #else @@ -503,7 +502,7 @@ public async Task TestBedrockAgentRuntimeRetrieveSuccessful() } Assert.NotEmpty(exportedItems); - Activity? awssdk_activity = exportedItems.FirstOrDefault(e => e.DisplayName == "Bedrock Agent Runtime.Retrieve"); + var awssdk_activity = exportedItems.FirstOrDefault(e => e.DisplayName == "Bedrock Agent Runtime.Retrieve"); Assert.NotNull(awssdk_activity); this.ValidateAWSActivity(awssdk_activity, parent); diff --git a/test/OpenTelemetry.Instrumentation.AWS.Tests/TestAWSClientMetricsInstrumentation.cs b/test/OpenTelemetry.Instrumentation.AWS.Tests/TestAWSClientMetricsInstrumentation.cs index 5f2f8b922c..46718423e1 100644 --- a/test/OpenTelemetry.Instrumentation.AWS.Tests/TestAWSClientMetricsInstrumentation.cs +++ b/test/OpenTelemetry.Instrumentation.AWS.Tests/TestAWSClientMetricsInstrumentation.cs @@ -65,9 +65,11 @@ public async Task TestSNSCreateTopicUnsuccessful() .Build(); var sns = new AmazonSimpleNotificationServiceClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1); - AmazonServiceException amazonServiceException = new AmazonServiceException(); - amazonServiceException.StatusCode = System.Net.HttpStatusCode.NotFound; - amazonServiceException.RequestId = "requestId"; + var amazonServiceException = new AmazonServiceException + { + StatusCode = System.Net.HttpStatusCode.NotFound, + RequestId = "requestId", + }; CustomResponses.SetResponse(sns, (request) => { throw amazonServiceException; }); var createTopicRequest = new CreateTopicRequest { @@ -120,7 +122,7 @@ public async Task TestSQSCreateQueueSuccessful() .Build(); var sqs = new AmazonSQSClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1); - string dummyResponse = "{}"; + var dummyResponse = "{}"; CustomResponses.SetResponse(sqs, dummyResponse, "requestId", true); var send_msg_req = new CreateQueueRequest() { diff --git a/test/OpenTelemetry.Instrumentation.AWS.Tests/TestRequest.cs b/test/OpenTelemetry.Instrumentation.AWS.Tests/TestRequest.cs index 8a83185af2..cb5d05ce85 100644 --- a/test/OpenTelemetry.Instrumentation.AWS.Tests/TestRequest.cs +++ b/test/OpenTelemetry.Instrumentation.AWS.Tests/TestRequest.cs @@ -12,11 +12,9 @@ namespace OpenTelemetry.Instrumentation.AWS.Tests; internal class TestRequest : IRequest { - private readonly ParameterCollection parameters; - public TestRequest(ParameterCollection? parameters = null) { - this.parameters = parameters ?? new ParameterCollection(); + this.ParameterCollection = parameters ?? []; } public string RequestName => throw new NotImplementedException(); @@ -27,7 +25,7 @@ public TestRequest(ParameterCollection? parameters = null) public IDictionary Parameters => throw new NotImplementedException(); - public ParameterCollection ParameterCollection => this.parameters; + public ParameterCollection ParameterCollection { get; } public IDictionary SubResources => throw new NotImplementedException(); diff --git a/test/OpenTelemetry.Instrumentation.AWS.Tests/Tools/CustomResponses.cs b/test/OpenTelemetry.Instrumentation.AWS.Tests/Tools/CustomResponses.cs index 2fbdec7d8d..04dbc175f2 100644 --- a/test/OpenTelemetry.Instrumentation.AWS.Tests/Tools/CustomResponses.cs +++ b/test/OpenTelemetry.Instrumentation.AWS.Tests/Tools/CustomResponses.cs @@ -31,8 +31,7 @@ public static void SetResponse( .GetValue(client, null) as RuntimePipeline; - var requestFactory = new MockHttpRequestFactory(); - requestFactory.ResponseCreator = responseCreator; + var requestFactory = new MockHttpRequestFactory { ResponseCreator = responseCreator }; var httpHandler = new HttpHandler(requestFactory, client); pipeline?.ReplaceHandler>(httpHandler); } @@ -44,7 +43,7 @@ public static void SetResponse( return (request) => { - Dictionary headers = new Dictionary(StringComparer.Ordinal); + var headers = new Dictionary(StringComparer.Ordinal); if (!string.IsNullOrEmpty(requestId)) { headers.Add(HeaderKeys.RequestIdHeader, requestId); @@ -52,12 +51,7 @@ public static void SetResponse( var response = MockWebResponse.Create(status, headers, content); - if (isOK) - { - return response; - } - - throw new HttpErrorResponseException(new HttpWebRequestResponseData(response)); + return isOK ? response : throw new HttpErrorResponseException(new HttpWebRequestResponseData(response)); }; } #else @@ -75,8 +69,7 @@ public static void SetResponse(AmazonServiceClient client, Func(requestFactory, client); pipeline?.ReplaceHandler>(httpHandler); } @@ -88,7 +81,7 @@ private static Func Create( return (request) => { - Dictionary headers = new Dictionary(StringComparer.Ordinal); + var headers = new Dictionary(StringComparer.Ordinal); if (!string.IsNullOrEmpty(requestId)) { headers.Add(HeaderKeys.RequestIdHeader, requestId); @@ -96,12 +89,9 @@ private static Func Create( var response = MockWebResponse.Create(status, headers, content); - if (isOK) - { - return response; - } - - throw new HttpErrorResponseException(CustomWebResponse.GenerateWebResponse(response)); + return isOK + ? response + : throw new HttpErrorResponseException(CustomWebResponse.GenerateWebResponse(response)); }; } #endif diff --git a/test/OpenTelemetry.Instrumentation.AWS.Tests/Tools/CustomWebResponse.cs b/test/OpenTelemetry.Instrumentation.AWS.Tests/Tools/CustomWebResponse.cs index 8c90c6c10c..ae7d4443c0 100644 --- a/test/OpenTelemetry.Instrumentation.AWS.Tests/Tools/CustomWebResponse.cs +++ b/test/OpenTelemetry.Instrumentation.AWS.Tests/Tools/CustomWebResponse.cs @@ -9,7 +9,7 @@ namespace OpenTelemetry.Instrumentation.AWS.Tests.Tools; internal class CustomWebResponse : IWebResponseData { - private HttpResponseMessageBody response; + private readonly HttpResponseMessageBody response; private string[]? headerNames; private Dictionary? headers; private HashSet? headerNamesSet; @@ -37,10 +37,7 @@ public CustomWebResponse(HttpResponseMessage responseMsg, HttpClient? httpClient public long ContentLength { get; private set; } - public IHttpResponseBody ResponseBody - { - get { return this.response; } - } + public IHttpResponseBody ResponseBody => this.response; public static IWebResponseData GenerateWebResponse(HttpResponseMessage response) { @@ -49,12 +46,9 @@ public static IWebResponseData GenerateWebResponse(HttpResponseMessage response) public string? GetHeaderValue(string headerName) { - if (this.headers != null && this.headers.TryGetValue(headerName, out var headerValue)) - { - return headerValue; - } - - return string.Empty; + return this.headers != null && this.headers.TryGetValue(headerName, out var headerValue) + ? headerValue + : string.Empty; } public bool IsHeaderPresent(string headerName) @@ -69,10 +63,10 @@ public bool IsHeaderPresent(string headerName) private void CopyHeaderValues(HttpResponseMessage response) { - List headerNames = new List(); + List headerNames = []; this.headers = new Dictionary(10, StringComparer.OrdinalIgnoreCase); - foreach (KeyValuePair> kvp in response.Headers) + foreach (var kvp in response.Headers) { headerNames.Add(kvp.Key); var headerValue = this.GetFirstHeaderValue(response.Headers, kvp.Key); @@ -92,17 +86,12 @@ private void CopyHeaderValues(HttpResponseMessage response) } } - this.headerNames = headerNames.ToArray(); + this.headerNames = [.. headerNames]; this.headerNamesSet = new HashSet(this.headerNames, StringComparer.OrdinalIgnoreCase); } private string? GetFirstHeaderValue(HttpHeaders headers, string key) { - if (headers.TryGetValues(key, out var headerValues)) - { - return headerValues.FirstOrDefault(); - } - - return string.Empty; + return headers.TryGetValues(key, out var headerValues) ? headerValues.FirstOrDefault() : string.Empty; } } diff --git a/test/OpenTelemetry.Instrumentation.AWS.Tests/Tools/MockHttpRequest.cs b/test/OpenTelemetry.Instrumentation.AWS.Tests/Tools/MockHttpRequest.cs index 28cb4d3b05..a7fbd08adb 100644 --- a/test/OpenTelemetry.Instrumentation.AWS.Tests/Tools/MockHttpRequest.cs +++ b/test/OpenTelemetry.Instrumentation.AWS.Tests/Tools/MockHttpRequest.cs @@ -57,10 +57,7 @@ public Stream GetRequestContent() public IWebResponseData GetResponse() { - if (this.GetResponseAction != null) - { - this.GetResponseAction(); - } + this.GetResponseAction?.Invoke(); var response = this.ResponseCreator(this); return new HttpWebRequestResponseData(response); @@ -123,14 +120,9 @@ private HttpWebResponse CreateResponse(MockHttpRequest request) var resourceName = request.RequestUri.Host.Split('.').Last(); var response = MockWebResponse.CreateFromResource(resourceName); - if (response?.StatusCode >= HttpStatusCode.OK && response.StatusCode <= (HttpStatusCode)299) - { - return response; - } - else - { - throw new HttpErrorResponseException(new HttpWebRequestResponseData(response)); - } + return response?.StatusCode is >= HttpStatusCode.OK and <= (HttpStatusCode)299 + ? response + : throw new HttpErrorResponseException(new HttpWebRequestResponseData(response)); } } #else @@ -234,14 +226,9 @@ private HttpResponseMessage CreateResponse(MockHttpRequest request) var resourceName = request.RequestUri.Host.Split('.').Last(); var response = MockWebResponse.CreateFromResource(resourceName); - if (response.StatusCode >= HttpStatusCode.OK && response.StatusCode <= (HttpStatusCode)299) - { - return response; - } - else - { - throw new HttpErrorResponseException(CustomWebResponse.GenerateWebResponse(response)); - } + return response.StatusCode is >= HttpStatusCode.OK and <= (HttpStatusCode)299 + ? response + : throw new HttpErrorResponseException(CustomWebResponse.GenerateWebResponse(response)); } } #endif diff --git a/test/OpenTelemetry.Instrumentation.AWS.Tests/Tools/MockWebResponse.cs b/test/OpenTelemetry.Instrumentation.AWS.Tests/Tools/MockWebResponse.cs index a6fccca9ab..2baf2c4473 100644 --- a/test/OpenTelemetry.Instrumentation.AWS.Tests/Tools/MockWebResponse.cs +++ b/test/OpenTelemetry.Instrumentation.AWS.Tests/Tools/MockWebResponse.cs @@ -21,9 +21,8 @@ internal class MockWebResponse { var type = typeof(HttpWebResponse); var assembly = Assembly.GetAssembly(type); - var obj = assembly?.CreateInstance("System.Net.HttpWebResponse") as HttpWebResponse; - if (obj == null) + if (assembly?.CreateInstance("System.Net.HttpWebResponse") is not HttpWebResponse obj) { return null; } @@ -38,7 +37,7 @@ internal class MockWebResponse } body ??= string.Empty; - Stream responseBodyStream = Utils.CreateStreamFromString(body); + var responseBodyStream = Utils.CreateStreamFromString(body); var statusFieldInfo = type.GetField( "m_StatusCode", @@ -58,7 +57,7 @@ internal class MockWebResponse streamFieldInfo?.SetValue(obj, responseBodyStream); contentLengthFieldInfo?.SetValue(obj, responseBodyStream.Length); - return obj as HttpWebResponse; + return obj; } #else @@ -66,7 +65,7 @@ public static HttpResponseMessage CreateFromResource(string resourceName) { var rawResponse = Utils.GetResourceText(resourceName); - HttpResponse response = ParseRawReponse(rawResponse); + var response = ParseRawReponse(rawResponse); var statusCode = ParseStatusCode(response.StatusLine); return Create(statusCode, response.Headers, response.Body); @@ -95,7 +94,7 @@ public static HttpResponseMessage Create(HttpStatusCode statusCode, IDictionary< } httpResponseMessage!.StatusCode = statusCode; - string dummyJson = "{\"key1\":\"value1\"}"; + var dummyJson = "{\"key1\":\"value1\"}"; httpResponseMessage.Content = new StringContent(body ?? dummyJson); // Content should be in Json format else we get exception from downstream unmarshalling return httpResponseMessage; } @@ -103,8 +102,7 @@ public static HttpResponseMessage Create(HttpStatusCode statusCode, IDictionary< #endif public static HttpResponse ParseRawReponse(string rawResponse) { - HttpResponse response = new HttpResponse(); - response.StatusLine = rawResponse; + var response = new HttpResponse { StatusLine = rawResponse }; var responseLines = rawResponse.Split('\n'); @@ -152,8 +150,12 @@ private static HttpStatusCode ParseStatusCode(string? statusLine) { try { - string statusCode = statusLine?.Split(' ')[1] ?? string.Empty; + var statusCode = statusLine?.Split(' ')[1] ?? string.Empty; +#if NET + return Enum.Parse(statusCode); +#else return (HttpStatusCode)Enum.Parse(typeof(HttpStatusCode), statusCode); +#endif } catch (Exception exception) { @@ -161,7 +163,7 @@ private static HttpStatusCode ParseStatusCode(string? statusLine) } } - public class HttpResponse + internal class HttpResponse { public HttpResponse() { diff --git a/test/OpenTelemetry.Instrumentation.AWS.Tests/Tools/Utils.cs b/test/OpenTelemetry.Instrumentation.AWS.Tests/Tools/Utils.cs index 8c9630e4bc..87ec0182ef 100644 --- a/test/OpenTelemetry.Instrumentation.AWS.Tests/Tools/Utils.cs +++ b/test/OpenTelemetry.Instrumentation.AWS.Tests/Tools/Utils.cs @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 using System.Diagnostics; -using System.Reflection; namespace OpenTelemetry.Instrumentation.AWS.Tests.Tools; @@ -10,8 +9,8 @@ internal static class Utils { public static Stream CreateStreamFromString(string s) { - MemoryStream stream = new MemoryStream(); - StreamWriter writer = new StreamWriter(stream); + var stream = new MemoryStream(); + var writer = new StreamWriter(stream); writer.Write(s); writer.Flush(); stream.Position = 0; @@ -20,9 +19,9 @@ public static Stream CreateStreamFromString(string s) public static Stream? GetResourceStream(string resourceName) { - Assembly assembly = typeof(Utils).Assembly; + var assembly = typeof(Utils).Assembly; var resource = FindResourceName(resourceName); - Stream? stream = assembly.GetManifestResourceStream(resource); + var stream = assembly.GetManifestResourceStream(resource); return stream; } @@ -34,10 +33,8 @@ public static string GetResourceText(string resourceName) return string.Empty; } - using (StreamReader reader = new StreamReader(stream)) - { - return reader.ReadToEnd(); - } + using var reader = new StreamReader(stream); + return reader.ReadToEnd(); } public static string FindResourceName(string partialName) @@ -49,7 +46,7 @@ public static string FindResourceName(string partialName) public static IEnumerable FindResourceName(Predicate match) { - Assembly assembly = typeof(Utils).Assembly; + var assembly = typeof(Utils).Assembly; var allResources = assembly.GetManifestResourceNames(); foreach (var resource in allResources) { diff --git a/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/AWSLambdaWrapperTests.cs b/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/AWSLambdaWrapperTests.cs index a7d617bc70..d36277b099 100644 --- a/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/AWSLambdaWrapperTests.cs +++ b/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/AWSLambdaWrapperTests.cs @@ -225,7 +225,7 @@ public void OnFunctionStart_ColdStart_ColdStartTagHasCorrectValue(int invocation .AddAWSLambdaConfigurations(c => c.DisableAwsXRayContextExtraction = true) .Build()) { - for (int i = 1; i <= invocationsCount; i++) + for (var i = 1; i <= invocationsCount; i++) { activity = AWSLambdaWrapper.OnFunctionStart("test-input", new SampleLambdaContext()); } @@ -233,7 +233,7 @@ public void OnFunctionStart_ColdStart_ColdStartTagHasCorrectValue(int invocation Assert.NotNull(activity); Assert.NotNull(activity.TagObjects); - var expectedColdStartValue = invocationsCount == 1 ? true : false; + var expectedColdStartValue = invocationsCount == 1; Assert.Contains(activity.TagObjects, x => x.Key == AWSLambdaSemanticConventions.AttributeFaasColdStart && expectedColdStartValue.Equals(x.Value)); } diff --git a/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/Implementation/AWSLambdaHttpUtilsTests.cs b/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/Implementation/AWSLambdaHttpUtilsTests.cs index c44df16f1e..06a0e1dbbe 100644 --- a/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/Implementation/AWSLambdaHttpUtilsTests.cs +++ b/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/Implementation/AWSLambdaHttpUtilsTests.cs @@ -26,7 +26,7 @@ public void GetHttpTags_APIGatewayProxyRequest_ReturnsCorrectTags() MultiValueQueryStringParameters = new Dictionary> { #pragma warning disable CA1861 // Avoid constant arrays as arguments - { "q1", new[] { "value1" } }, + { "q1", ["value1"] }, #pragma warning restore CA1861 // Avoid constant arrays as arguments }, RequestContext = new APIGatewayProxyRequest.ProxyRequestContext @@ -95,7 +95,7 @@ public void GetHttpTags_ApplicationLoadBalancerRequestWithMultiValue_ReturnsCorr MultiValueQueryStringParameters = new Dictionary> { #pragma warning disable CA1861 // Avoid constant arrays as arguments - { "q1", new[] { "value1" } }, + { "q1", ["value1"] }, #pragma warning restore CA1861 // Avoid constant arrays as arguments }, HttpMethod = "GET", @@ -226,7 +226,7 @@ public void GetHttpTags_APIGatewayProxyRequestWithEmptyContext_ReturnsTagsFromRe MultiValueQueryStringParameters = new Dictionary> { #pragma warning disable CA1861 // Avoid constant arrays as arguments - { "q1", new[] { "value1" } }, + { "q1", ["value1"] }, #pragma warning restore CA1861 // Avoid constant arrays as arguments }, HttpMethod = "POST", @@ -444,7 +444,7 @@ public void GetQueryString_APIGatewayHttpApiV2ProxyRequest_CorrectQueryString(st Assert.Equal(expectedQueryString, queryString); } - private static void AssertTags(IReadOnlyDictionary expectedTags, IEnumerable>? actualTags) + private static void AssertTags(Dictionary expectedTags, IEnumerable>? actualTags) where TActualValue : class { Assert.NotNull(actualTags); diff --git a/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/Implementation/AWSMessagingUtilsTests.cs b/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/Implementation/AWSMessagingUtilsTests.cs index ba2aa4ed49..967bc3fe77 100644 --- a/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/Implementation/AWSMessagingUtilsTests.cs +++ b/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/Implementation/AWSMessagingUtilsTests.cs @@ -1,9 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -using System.Diagnostics; using Amazon.Lambda.SQSEvents; -using OpenTelemetry.Context.Propagation; using OpenTelemetry.Instrumentation.AWSLambda.Implementation; using OpenTelemetry.Trace; using Xunit; @@ -35,9 +33,9 @@ public void Dispose() public void ExtractParentContext_SetParentFromMessageBatchIsDisabled_ParentIsNotSet() { AWSMessagingUtils.SetParentFromMessageBatch = false; - var sqsEvent = CreateSqsEventWithMessages(new[] { SpanId1, SpanId2 }); + var sqsEvent = CreateSqsEventWithMessages([SpanId1, SpanId2]); - (PropagationContext parentContext, IEnumerable? links) = AWSMessagingUtils.ExtractParentContext(sqsEvent); + (var parentContext, var links) = AWSMessagingUtils.ExtractParentContext(sqsEvent); Assert.Equal(default, parentContext); Assert.Equal(2, links!.Count()); @@ -47,9 +45,9 @@ public void ExtractParentContext_SetParentFromMessageBatchIsDisabled_ParentIsNot public void ExtractParentContext_SetParentFromMessageBatchIsEnabled_ParentIsSetFromLastMessage() { AWSMessagingUtils.SetParentFromMessageBatch = true; - var sqsEvent = CreateSqsEventWithMessages(new[] { SpanId1, SpanId2 }); + var sqsEvent = CreateSqsEventWithMessages([SpanId1, SpanId2]); - (PropagationContext parentContext, IEnumerable? links) = AWSMessagingUtils.ExtractParentContext(sqsEvent); + (var parentContext, var links) = AWSMessagingUtils.ExtractParentContext(sqsEvent); Assert.NotEqual(default, parentContext); Assert.Equal(SpanId2, parentContext.ActivityContext.SpanId.ToHexString()); @@ -62,11 +60,11 @@ public void ExtractParentContext_SetParentFromMessageBatchIsEnabled_ParentIsSetF AWSMessagingUtils.SetParentFromMessageBatch = true; var sqsEvent = new SQSEvent { - Records = new List - { + Records = + [ new SQSMessage { - MessageAttributes = new(), + MessageAttributes = [], #pragma warning disable format // dotnet-format butchers the raw string & all following code (use dotnet format instead?) Body = /*lang=json,strict*/ """ @@ -87,10 +85,10 @@ public void ExtractParentContext_SetParentFromMessageBatchIsEnabled_ParentIsSetF } """, }, - }, + ], }; - (PropagationContext parentContext, IEnumerable? links) = AWSMessagingUtils.ExtractParentContext(sqsEvent); + (var parentContext, var links) = AWSMessagingUtils.ExtractParentContext(sqsEvent); Assert.NotEqual(default, parentContext); Assert.Equal(SpanId1, parentContext.ActivityContext.SpanId.ToHexString()); @@ -99,10 +97,10 @@ public void ExtractParentContext_SetParentFromMessageBatchIsEnabled_ParentIsSetF private static SQSEvent CreateSqsEventWithMessages(string[] spans) { - var @event = new SQSEvent { Records = new List() }; + var @event = new SQSEvent { Records = [] }; for (var i = 0; i < spans.Length; i++) { - var message = new SQSMessage { MessageAttributes = new Dictionary() }; + var message = new SQSMessage { MessageAttributes = [] }; message.MessageAttributes.Add("traceparent", new MessageAttribute { StringValue = $"00-{TraceId}-{spans[i]}-01" }); message.MessageAttributes.Add("tracestate", new MessageAttribute { StringValue = $"k1=v1,k2=v2" }); @event.Records.Add(message); diff --git a/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/SampleHandlers.cs b/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/SampleHandlers.cs index 41843b6084..94bf75053b 100644 --- a/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/SampleHandlers.cs +++ b/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/SampleHandlers.cs @@ -8,30 +8,33 @@ namespace OpenTelemetry.Instrumentation.AWSLambda.Tests; internal class SampleHandlers { // Action - public void SampleHandlerSyncInputAndNoReturn(string str, ILambdaContext context) +#pragma warning disable SA1313 + public void SampleHandlerSyncInputAndNoReturn(string _1, ILambdaContext _2) { } // Func - public string SampleHandlerSyncInputAndReturn(string str, ILambdaContext context) + public string SampleHandlerSyncInputAndReturn(string str, ILambdaContext _2) { return str; } // Func - public async Task SampleHandlerAsyncInputAndNoReturn(string str, ILambdaContext context) + public async Task SampleHandlerAsyncInputAndNoReturn(string _1, ILambdaContext _2) { await Task.Delay(10); } // Func> - public async Task SampleHandlerAsyncInputAndReturn(string str, ILambdaContext context) + public async Task SampleHandlerAsyncInputAndReturn(string str, ILambdaContext _2) { await Task.Delay(10); return str; } - public void SampleHandlerSyncNoReturnException(string str, ILambdaContext context) + // Action + public void SampleHandlerSyncNoReturnException(string str, ILambdaContext _2) +#pragma warning restore SA1313 { throw new Exception(str); } diff --git a/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/SampleLambdaContext.cs b/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/SampleLambdaContext.cs index cf608da60d..792ba8d606 100644 --- a/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/SampleLambdaContext.cs +++ b/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/SampleLambdaContext.cs @@ -5,7 +5,7 @@ namespace OpenTelemetry.Instrumentation.AWSLambda.Tests; -public class SampleLambdaContext : ILambdaContext +internal class SampleLambdaContext : ILambdaContext { public string AwsRequestId { get; } = "testrequestid";