Skip to content

Commit

Permalink
Merge branch 'main' into issue/AWS-Lambda-SQS-SNS-support
Browse files Browse the repository at this point in the history
  • Loading branch information
rypdal committed Mar 13, 2023
2 parents e51a882 + 7fda8d4 commit 4a09e75
Show file tree
Hide file tree
Showing 55 changed files with 1,457 additions and 182 deletions.
54 changes: 54 additions & 0 deletions .github/ISSUE_TEMPLATE/comp_extensions_enrichment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
name: OpenTelemetry.Extensions.Enrichment
about: Issue with OpenTelemetry.Extensions.Enrichment
labels: comp:extensions.enrichment
---

# Issue with OpenTelemetry.Extensions.Enrichment

**What type of request is this?**

* [ ] Feature Request
* [ ] Bug
* [ ] Question

## Request Details

**What are the OpenTelemetry packages and versions you are using?**

_List [all OpenTelemetry NuGet
packages](https://www.nuget.org/profiles/OpenTelemetry) and version that you are
using (e.g. `OpenTelemetry 1.4.0`)._

**What environment are you using?**

_Please include the runtime versions (e.g. `net462`, `net48`, `net6.0`, `net7.0`
etc.), OS details (e.g.Windows, Linux, etc.), architecture (e.g. 32bit, 64bit,
etc.), and anything else important (e.g. IIS, container, etc.)._

**What is the expected behavior?**

_Describe what you expected to see._

**What is the actual behavior?**

_Describe what you saw instead._

**What are the steps to reproduce the issue?**

_Describe how to reproduce the issue._

If you are reporting a non-obvious bug, please create a self-contained project
and apply the minimum required code to result in the issue you're observing.

We will close this issue if:

* The repro project you share with us is too complex. We can't investigate
custom projects please try to keep it to just what is needed to demonstrate
the issue.

* We can't reproduce the behavior you're reporting.

## Additional Context

_Include any other context about the bug or feature request here._
4 changes: 4 additions & 0 deletions .github/component_owners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ components:
- vishweshbankwar
src/OpenTelemetry.Extensions.Docker/:
- iskiselev
src/OpenTelemetry.Extensions.Enrichment/:
- xakep139
src/OpenTelemetry.Extensions.PersistentStorage.Abstractions/:
- vishweshbankwar
src/OpenTelemetry.Extensions.PersistentStorage/:
Expand Down Expand Up @@ -98,6 +100,8 @@ components:
- codeblanch
test/OpenTelemetry.Extensions.Docker.Tests/:
- iskiselev
test/OpenTelemetry.Extensions.Enrichment.Tests/:
- xakep139
test/OpenTelemetry.Extensions.PersistentStorage.Tests/:
- vishweshbankwar
test/OpenTelemetry.Instrumentation.AWSLambda.Tests/:
Expand Down
67 changes: 67 additions & 0 deletions .github/workflows/package-Extensions.Enrichment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Pack OpenTelemetry.Extensions.Enrichment

on:
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
push:
tags:
- 'Extensions.Enrichment-*' # trigger when we create a tag with prefix "Extensions.Enrichment-"

jobs:
build-test-pack:
runs-on: ${{ matrix.os }}
permissions:
contents: write
env:
PROJECT: OpenTelemetry.Extensions.Enrichment

strategy:
matrix:
os: [windows-latest]

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # fetching all

- uses: actions/setup-dotnet@v3.0.3
with:
dotnet-version: '7.0.x'

- name: Install dependencies
run: dotnet restore src/${{env.PROJECT}}

- name: dotnet build ${{env.PROJECT}}
run: dotnet build src/${{env.PROJECT}} --configuration Release --no-restore -p:Deterministic=true

- name: dotnet test ${{env.PROJECT}}
run: dotnet test test/${{env.PROJECT}}.Tests

- name: dotnet pack ${{env.PROJECT}}
run: dotnet pack src/${{env.PROJECT}} --configuration Release --no-build

- name: Publish Artifacts
uses: actions/upload-artifact@v3
with:
name: ${{env.PROJECT}}-packages
path: '**/${{env.PROJECT}}/bin/**/*.*nupkg'

- name: Publish Nuget
run: |
nuget push **/${{env.PROJECT}}/bin/**/*.nupkg -Source https://api.nuget.org/v3/index.json -ApiKey ${{ secrets.NUGET_TOKEN }} -SymbolApiKey ${{ secrets.NUGET_TOKEN }}
- name: Create GitHub Prerelease
if: ${{ (contains(github.ref_name, '-alpha.') || contains(github.ref_name, '-beta.') || contains(github.ref_name, '-rc.')) }}
run: gh release create ${{ github.ref_name }} --title ${{ github.ref_name }} --verify-tag --notes "See [CHANGELOG](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/${{ github.ref_name }}/src/${{env.PROJECT}}/CHANGELOG.md) for details." --prerelease
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create GitHub Release
if: ${{ !(contains(github.ref_name, '-alpha.') || contains(github.ref_name, '-beta.') || contains(github.ref_name, '-rc.')) }}
run: gh release create ${{ github.ref_name }} --title ${{ github.ref_name }} --verify-tag --notes "See [CHANGELOG](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/${{ github.ref_name }}/src/${{env.PROJECT}}/CHANGELOG.md) for details." --latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions build/Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<DefineConstants>$(DefineConstants);SIGNED</DefineConstants>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<NetFrameworkMinimumSupportedVersion>net462</NetFrameworkMinimumSupportedVersion>
<NetMinimumSupportedVersion>net6.0</NetMinimumSupportedVersion>
<NetStandardMinimumSupportedVersion>netstandard2.0</NetStandardMinimumSupportedVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Debug'">
Expand Down
14 changes: 14 additions & 0 deletions opentelemetry-dotnet-contrib.sln
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.OneC
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.OneCollector.Tests", "test\OpenTelemetry.Exporter.OneCollector.Tests\OpenTelemetry.Exporter.OneCollector.Tests.csproj", "{61520801-1CAA-4041-A3EF-CFFB9D4A180B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Extensions.Enrichment", "src\OpenTelemetry.Extensions.Enrichment\OpenTelemetry.Extensions.Enrichment.csproj", "{5BA85306-64B8-4E04-90EB-7069C187E250}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Extensions.Enrichment.Tests", "test\OpenTelemetry.Extensions.Enrichment.Tests\OpenTelemetry.Extensions.Enrichment.Tests.csproj", "{5A7BE9DA-3582-49D8-A8E7-164C1E3CDB38}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -527,6 +531,14 @@ Global
{61520801-1CAA-4041-A3EF-CFFB9D4A180B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{61520801-1CAA-4041-A3EF-CFFB9D4A180B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{61520801-1CAA-4041-A3EF-CFFB9D4A180B}.Release|Any CPU.Build.0 = Release|Any CPU
{5BA85306-64B8-4E04-90EB-7069C187E250}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5BA85306-64B8-4E04-90EB-7069C187E250}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5BA85306-64B8-4E04-90EB-7069C187E250}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5BA85306-64B8-4E04-90EB-7069C187E250}.Release|Any CPU.Build.0 = Release|Any CPU
{5A7BE9DA-3582-49D8-A8E7-164C1E3CDB38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5A7BE9DA-3582-49D8-A8E7-164C1E3CDB38}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5A7BE9DA-3582-49D8-A8E7-164C1E3CDB38}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5A7BE9DA-3582-49D8-A8E7-164C1E3CDB38}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -608,6 +620,8 @@ Global
{DFC6A4A9-5262-4507-B747-CC6B814205E6} = {2097345F-4DD3-477D-BC54-A922F9B2B402}
{73C10993-03AC-42F4-85BB-96EAAA8212D9} = {22DF5DC0-1290-4E83-A9D8-6BB7DE3B3E63}
{61520801-1CAA-4041-A3EF-CFFB9D4A180B} = {2097345F-4DD3-477D-BC54-A922F9B2B402}
{5BA85306-64B8-4E04-90EB-7069C187E250} = {22DF5DC0-1290-4E83-A9D8-6BB7DE3B3E63}
{5A7BE9DA-3582-49D8-A8E7-164C1E3CDB38} = {2097345F-4DD3-477D-BC54-A922F9B2B402}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B0816796-CDB3-47D7-8C3C-946434DE3B66}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static class AWSXRayIdGenerator

internal static void ReplaceTraceId(Sampler? sampler = null)
{
#pragma warning disable CA2000 // Dispose objects before losing scope
var awsXRayActivityListener = new ActivityListener
{
ActivityStarted = (activity) =>
Expand All @@ -63,6 +64,7 @@ internal static void ReplaceTraceId(Sampler? sampler = null)

ShouldListenTo = (_) => true,
};
#pragma warning restore CA2000 // Dispose objects before losing scope

ActivitySource.AddActivityListener(awsXRayActivityListener);
}
Expand Down Expand Up @@ -141,7 +143,9 @@ private static string GenerateHexNumber(int digits)
/// <param name="buffer">An array of bytes to contain random numbers.</param>
private static void NextBytes(byte[] buffer)
{
#pragma warning disable CA5394 // Do not use insecure randomness
Global.NextBytes(buffer);
#pragma warning restore CA5394 // Do not use insecure randomness
}

/// <summary>
Expand All @@ -151,7 +155,9 @@ private static void NextBytes(byte[] buffer)
/// <returns>A 32-bit signed integer that is greater than or equal to 0, and less than maxValue.</returns>
private static int Next(int maxValue)
{
#pragma warning disable CA5394 // Do not use insecure randomness
return Global.Next(maxValue);
#pragma warning restore CA5394 // Do not use insecure randomness
}

private static ActivitySamplingResult ComputeRootActivitySamplingResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ namespace OpenTelemetry.Contrib.Extensions.AWSXRay.Resources;
public class AWSEBSResourceDetector : IResourceDetector
{
private const string AWSEBSMetadataWindowsFilePath = "C:\\Program Files\\Amazon\\XRay\\environment.conf";
#if NETSTANDARD
private const string AWSEBSMetadataLinuxFilePath = "/var/elasticbeanstalk/xray/environment.conf";
#endif

/// <summary>
/// Detector the required and optional resource attributes from AWS ElasticBeanstalk.
Expand All @@ -55,9 +57,9 @@ public class AWSEBSResourceDetector : IResourceDetector
filePath = AWSEBSMetadataWindowsFilePath;
#endif

var metadata = this.GetEBSMetadata(filePath);
var metadata = GetEBSMetadata(filePath);

resourceAttributes = this.ExtractResourceAttributes(metadata);
resourceAttributes = ExtractResourceAttributes(metadata);
}
catch (Exception ex)
{
Expand All @@ -67,7 +69,7 @@ public class AWSEBSResourceDetector : IResourceDetector
return resourceAttributes;
}

internal List<KeyValuePair<string, object?>>? ExtractResourceAttributes(AWSEBSMetadataModel? metadata)
internal static List<KeyValuePair<string, object?>>? ExtractResourceAttributes(AWSEBSMetadataModel? metadata)
{
var resourceAttributes = new List<KeyValuePair<string, object?>>()
{
Expand All @@ -82,7 +84,7 @@ public class AWSEBSResourceDetector : IResourceDetector
return resourceAttributes;
}

internal AWSEBSMetadataModel? GetEBSMetadata(string filePath)
internal static AWSEBSMetadataModel? GetEBSMetadata(string filePath)
{
return ResourceDetectorUtils.DeserializeFromFile<AWSEBSMetadataModel>(filePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public class AWSEC2ResourceDetector : IResourceDetector

try
{
var token = this.GetAWSEC2Token();
var identity = this.GetAWSEC2Identity(token);
var hostName = this.GetAWSEC2HostName(token);
var token = GetAWSEC2Token();
var identity = GetAWSEC2Identity(token);
var hostName = GetAWSEC2HostName(token);

resourceAttributes = this.ExtractResourceAttributes(identity, hostName);
resourceAttributes = ExtractResourceAttributes(identity, hostName);
}
catch (Exception ex)
{
Expand All @@ -55,7 +55,7 @@ public class AWSEC2ResourceDetector : IResourceDetector
return resourceAttributes;
}

internal List<KeyValuePair<string, object?>> ExtractResourceAttributes(AWSEC2IdentityDocumentModel? identity, string hostName)
internal static List<KeyValuePair<string, object?>> ExtractResourceAttributes(AWSEC2IdentityDocumentModel? identity, string hostName)
{
var resourceAttributes = new List<KeyValuePair<string, object?>>()
{
Expand All @@ -72,30 +72,30 @@ public class AWSEC2ResourceDetector : IResourceDetector
return resourceAttributes;
}

internal AWSEC2IdentityDocumentModel? DeserializeResponse(string response)
internal static AWSEC2IdentityDocumentModel? DeserializeResponse(string response)
{
return ResourceDetectorUtils.DeserializeFromString<AWSEC2IdentityDocumentModel>(response);
}

private string GetAWSEC2Token()
private static string GetAWSEC2Token()
{
return ResourceDetectorUtils.SendOutRequest(AWSEC2MetadataTokenUrl, "PUT", new KeyValuePair<string, string>(AWSEC2MetadataTokenTTLHeader, "60")).Result;
}

private AWSEC2IdentityDocumentModel? GetAWSEC2Identity(string token)
private static AWSEC2IdentityDocumentModel? GetAWSEC2Identity(string token)
{
var identity = this.GetIdentityResponse(token);
var identityDocument = this.DeserializeResponse(identity);
var identity = GetIdentityResponse(token);
var identityDocument = DeserializeResponse(identity);

return identityDocument;
}

private string GetIdentityResponse(string token)
private static string GetIdentityResponse(string token)
{
return ResourceDetectorUtils.SendOutRequest(AWSEC2IdentityDocumentUrl, "GET", new KeyValuePair<string, string>(AWSEC2MetadataTokenHeader, token)).Result;
}

private string GetAWSEC2HostName(string token)
private static string GetAWSEC2HostName(string token)
{
return ResourceDetectorUtils.SendOutRequest(AWSEC2HostNameUrl, "GET", new KeyValuePair<string, string>(AWSEC2MetadataTokenHeader, token)).Result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ public class AWSECSResourceDetector : IResourceDetector
{
List<KeyValuePair<string, object?>>? resourceAttributes = null;

if (!this.IsECSProcess())
if (!IsECSProcess())
{
return resourceAttributes;
}

try
{
var containerId = this.GetECSContainerId(AWSECSMetadataPath);
var containerId = GetECSContainerId(AWSECSMetadataPath);

resourceAttributes = this.ExtractResourceAttributes(containerId);
resourceAttributes = ExtractResourceAttributes(containerId);
}
catch (Exception ex)
{
Expand All @@ -55,7 +55,7 @@ public class AWSECSResourceDetector : IResourceDetector
return resourceAttributes;
}

internal List<KeyValuePair<string, object?>> ExtractResourceAttributes(string? containerId)
internal static List<KeyValuePair<string, object?>> ExtractResourceAttributes(string? containerId)
{
var resourceAttributes = new List<KeyValuePair<string, object?>>()
{
Expand All @@ -67,7 +67,7 @@ public class AWSECSResourceDetector : IResourceDetector
return resourceAttributes;
}

internal string? GetECSContainerId(string path)
internal static string? GetECSContainerId(string path)
{
string? containerId = null;

Expand All @@ -87,7 +87,7 @@ public class AWSECSResourceDetector : IResourceDetector
return containerId;
}

internal bool IsECSProcess()
internal static bool IsECSProcess()
{
return Environment.GetEnvironmentVariable(AWSECSMetadataURLKey) != null || Environment.GetEnvironmentVariable(AWSECSMetadataURLV4Key) != null;
}
Expand Down
Loading

0 comments on commit 4a09e75

Please sign in to comment.