Skip to content

Commit

Permalink
[Instrumentation.AWSLambda] Update to net6.0 (#1545)
Browse files Browse the repository at this point in the history
  • Loading branch information
martincostello committed Jan 22, 2024
1 parent 75a7f38 commit b21a0f9
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 17 deletions.
@@ -0,0 +1 @@
#nullable enable
Empty file.
10 changes: 3 additions & 7 deletions src/OpenTelemetry.Instrumentation.AWSLambda/AWSLambdaWrapper.cs
Expand Up @@ -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;
Expand All @@ -20,13 +19,10 @@ namespace OpenTelemetry.Instrumentation.AWSLambda;
/// </summary>
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<AssemblyInformationalVersionAttribute>()!.InformationalVersion.Split('+')[0];
private static readonly ActivitySource AWSLambdaActivitySource = new(ActivitySourceName, Version);

/// <summary>
/// Gets or sets a value indicating whether AWS X-Ray propagation should be ignored. Default value is false.
Expand Down
2 changes: 2 additions & 0 deletions src/OpenTelemetry.Instrumentation.AWSLambda/CHANGELOG.md
Expand Up @@ -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

Expand Down
Expand Up @@ -14,14 +14,26 @@ internal sealed class AWSLambdaResourceDetector : IResourceDetector
/// <returns>Detected resource.</returns>
public Resource Detect()
{
var resourceAttributes = new List<KeyValuePair<string, object>>
var resourceAttributes = new List<KeyValuePair<string, object>>(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);
}
}
Expand Up @@ -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);
}
Expand Down
Expand Up @@ -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
{
Expand Down
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Description>AWS Lambda tracing wrapper for OpenTelemetry .NET</Description>
<PackageTags>$(PackageTags);AWS Lambda</PackageTags>
<MinVerTagPrefix>Instrumentation.AWSLambda-</MinVerTagPrefix>
Expand Down

0 comments on commit b21a0f9

Please sign in to comment.