Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Instrumentation.AWSLambda] Update to net6.0 #1545

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1 @@
#nullable enable
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)
martincostello marked this conversation as resolved.
Show resolved Hide resolved
{
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