diff --git a/src/OpenTelemetry.Instrumentation.AWSLambda/.publicApi/net6.0/PublicAPI.Shipped.txt b/src/OpenTelemetry.Instrumentation.AWSLambda/.publicApi/net6.0/PublicAPI.Shipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/OpenTelemetry.Instrumentation.AWSLambda/.publicApi/net6.0/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/OpenTelemetry.Instrumentation.AWSLambda/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Instrumentation.AWSLambda/.publicApi/net6.0/PublicAPI.Unshipped.txt similarity index 100% rename from src/OpenTelemetry.Instrumentation.AWSLambda/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt rename to src/OpenTelemetry.Instrumentation.AWSLambda/.publicApi/net6.0/PublicAPI.Unshipped.txt diff --git a/src/OpenTelemetry.Instrumentation.AWSLambda/.publicApi/netstandard2.0/PublicAPI.Shipped.txt b/src/OpenTelemetry.Instrumentation.AWSLambda/.publicApi/netstandard2.0/PublicAPI.Shipped.txt deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/OpenTelemetry.Instrumentation.AWSLambda/AWSLambdaWrapper.cs b/src/OpenTelemetry.Instrumentation.AWSLambda/AWSLambdaWrapper.cs index 223a529417..3102659426 100644 --- a/src/OpenTelemetry.Instrumentation.AWSLambda/AWSLambdaWrapper.cs +++ b/src/OpenTelemetry.Instrumentation.AWSLambda/AWSLambdaWrapper.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; using System.Threading.Tasks; @@ -20,13 +19,10 @@ namespace OpenTelemetry.Instrumentation.AWSLambda; /// public static class AWSLambdaWrapper { - private static readonly AssemblyName AssemblyName = typeof(AWSLambdaWrapper).Assembly.GetName(); + internal const string ActivitySourceName = "OpenTelemetry.Instrumentation.AWSLambda"; - [SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1202:ElementsMustBeOrderedByAccess", Justification = "Initialization order.")] - internal static readonly string ActivitySourceName = AssemblyName.Name; - - private static readonly Version Version = AssemblyName.Version; - private static readonly ActivitySource AWSLambdaActivitySource = new(ActivitySourceName, Version.ToString()); + private static readonly string Version = typeof(AWSLambdaWrapper).Assembly.GetCustomAttribute()!.InformationalVersion.Split('+')[0]; + private static readonly ActivitySource AWSLambdaActivitySource = new(ActivitySourceName, Version); /// /// Gets or sets a value indicating whether AWS X-Ray propagation should be ignored. Default value is false. diff --git a/src/OpenTelemetry.Instrumentation.AWSLambda/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.AWSLambda/CHANGELOG.md index 527ae83f3c..81fa0799b1 100644 --- a/src/OpenTelemetry.Instrumentation.AWSLambda/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.AWSLambda/CHANGELOG.md @@ -9,6 +9,8 @@ If null state analysis is enabled in your depending project, you may encounter new warnings. ([#1295](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1295)) +* BREAKING: Target `net6.0` instead of `netstandard2.0` + ([#1545](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1545)) ## 1.2.0-beta.1 diff --git a/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSLambdaResourceDetector.cs b/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSLambdaResourceDetector.cs index 4446468214..5e8ba32490 100644 --- a/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSLambdaResourceDetector.cs +++ b/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSLambdaResourceDetector.cs @@ -14,14 +14,26 @@ internal sealed class AWSLambdaResourceDetector : IResourceDetector /// Detected resource. public Resource Detect() { - var resourceAttributes = new List> + var resourceAttributes = new List>(4) { new(AWSLambdaSemanticConventions.AttributeCloudProvider, AWSLambdaUtils.GetCloudProvider()), - new(AWSLambdaSemanticConventions.AttributeCloudRegion, AWSLambdaUtils.GetAWSRegion()), - new(AWSLambdaSemanticConventions.AttributeFaasName, AWSLambdaUtils.GetFunctionName()), - new(AWSLambdaSemanticConventions.AttributeFaasVersion, AWSLambdaUtils.GetFunctionVersion()), }; + if (AWSLambdaUtils.GetAWSRegion() is { } region) + { + resourceAttributes.Add(new(AWSLambdaSemanticConventions.AttributeCloudRegion, region)); + } + + if (AWSLambdaUtils.GetFunctionName() is { } functionName) + { + resourceAttributes.Add(new(AWSLambdaSemanticConventions.AttributeFaasName, functionName)); + } + + if (AWSLambdaUtils.GetFunctionVersion() is { } functionVersion) + { + resourceAttributes.Add(new(AWSLambdaSemanticConventions.AttributeFaasVersion, functionVersion)); + } + return new Resource(resourceAttributes); } } diff --git a/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSLambdaUtils.cs b/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSLambdaUtils.cs index adcb083eb7..eccbbc2ca8 100644 --- a/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSLambdaUtils.cs +++ b/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSLambdaUtils.cs @@ -86,17 +86,17 @@ internal static string GetCloudProvider() return CloudProvider; } - internal static string GetAWSRegion() + internal static string? GetAWSRegion() { return Environment.GetEnvironmentVariable(AWSRegion); } - internal static string GetFunctionName(ILambdaContext? context = null) + internal static string? GetFunctionName(ILambdaContext? context = null) { return context?.FunctionName ?? Environment.GetEnvironmentVariable(FunctionName); } - internal static string GetFunctionVersion() + internal static string? GetFunctionVersion() { return Environment.GetEnvironmentVariable(FunctionVersion); } diff --git a/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSMessagingUtils.cs b/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSMessagingUtils.cs index 8d6a205f7d..0202903329 100644 --- a/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSMessagingUtils.cs +++ b/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSMessagingUtils.cs @@ -127,8 +127,8 @@ internal static PropagationContext ExtractParentContext(SNSEvent.SNSMessage? mes var body = sqsMessage.Body; if (body != null && - body.TrimStart().StartsWith("{", StringComparison.Ordinal) && - body.Contains(SnsMessageAttributes)) + body.TrimStart().StartsWith('{') && + body.Contains(SnsMessageAttributes, StringComparison.Ordinal)) { try { diff --git a/src/OpenTelemetry.Instrumentation.AWSLambda/OpenTelemetry.Instrumentation.AWSLambda.csproj b/src/OpenTelemetry.Instrumentation.AWSLambda/OpenTelemetry.Instrumentation.AWSLambda.csproj index be934118fc..0f519fc865 100644 --- a/src/OpenTelemetry.Instrumentation.AWSLambda/OpenTelemetry.Instrumentation.AWSLambda.csproj +++ b/src/OpenTelemetry.Instrumentation.AWSLambda/OpenTelemetry.Instrumentation.AWSLambda.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + net6.0 AWS Lambda tracing wrapper for OpenTelemetry .NET $(PackageTags);AWS Lambda Instrumentation.AWSLambda-