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 24, 2023
2 parents c98d9e9 + 1e47f1c commit 933c3be
Show file tree
Hide file tree
Showing 43 changed files with 1,821 additions and 164 deletions.
41 changes: 41 additions & 0 deletions .github/ISSUE_TEMPLATE/comp_instrumentation_cassandra.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
name: OpenTelemetry.Instrumentation.Cassandra
about: Issue with OpenTelemetry.Instrumentation.Cassandra
labels: comp:instrumentation.cassandra
---

# Issue with OpenTelemetry.Instrumentation.Cassandra

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

* TBD

Runtime version (e.g. `net462`, `net48`, `net6.0`, `net7.0` etc. You can
find this information from the `*.csproj` file):

* TBD

**Is this a feature request or a bug?**

* [ ] Feature Request
* [ ] Bug

**What is the expected behavior?**

What do you expect to see?

**What is the actual behavior?**

What did you see instead? If you are reporting a bug, create a self-contained
project using the template of your choice 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 complex. We can't investigate custom
projects, so don't point us to such, please.
* If we can not reproduce the behavior you're reporting.

## Additional Context

Add any other context about the feature request here.
5 changes: 5 additions & 0 deletions .github/component_owners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ components:
src/OpenTelemetry.Instrumentation.AWSLambda/:
- rypdal
- Oberon00
src/OpenTelemetry.Instrumentation.Cassandra/:
- xsoheilalizadeh
src/OpenTelemetry.Instrumentation.ElasticsearchClient/:
- ejsmith
src/OpenTelemetry.Instrumentation.EventCounters/:
Expand Down Expand Up @@ -110,6 +112,8 @@ components:
test/OpenTelemetry.Instrumentation.AWSLambda.Tests/:
- rypdal
- Oberon00
test/OpenTelemetry.Instrumentation.Cassandra.Tests/:
- xsoheilalizadeh
test/OpenTelemetry.Instrumentation.ElasticsearchClient.Tests/:
- ejsmith
test/OpenTelemetry.Instrumentation.EventCounters.Tests/:
Expand All @@ -133,3 +137,4 @@ components:
test/OpenTelemetry.ResourceDetectors.Azure.Tests/:
- rajkumar-rangaraj
- vishweshbankwar

65 changes: 65 additions & 0 deletions .github/workflows/package-Instrumentation.Cassandra.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Pack OpenTelemetry.Instrumentation.Cassandra

on:
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
push:
tags:
- 'Instrumentation.Cassandra-*'

jobs:
build-test-pack:
runs-on: ${{ matrix.os }}
env:
PROJECT: OpenTelemetry.Instrumentation.Cassandra

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: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v7
- uses: actions/stale@v8
with:
stale-pr-message: 'This PR was marked stale due to lack of activity. It will be closed in 7 days.'
close-pr-message: 'Closed as inactive. Feel free to reopen if this PR is still being worked on.'
Expand Down
1 change: 1 addition & 0 deletions build/Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<OpenTelemetryCoreLatestVersion>[1.4.0,2.0)</OpenTelemetryCoreLatestVersion>
<OpenTelemetryCoreLatestPrereleaseVersion>[1.5.0-alpha.1]</OpenTelemetryCoreLatestPrereleaseVersion>
<StackExchangeRedisPkgVer>[2.1.58,3.0)</StackExchangeRedisPkgVer>
<CassandraCSharpDriverPkgVer>[3.16.0,4.0)</CassandraCSharpDriverPkgVer>
<StyleCopAnalyzersPkgVer>[1.2.0-beta.435,2.0)</StyleCopAnalyzersPkgVer>
<SystemNetHttp>[4.3.4,)</SystemNetHttp>
<SystemReflectionEmitLightweightPkgVer>4.7.0</SystemReflectionEmitLightweightPkgVer>
Expand Down
13 changes: 13 additions & 0 deletions opentelemetry-dotnet-contrib.sln
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "process-instrumentation", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples.EventCounters", "examples\event-counters\Examples.EventCounters\Examples.EventCounters.csproj", "{BA58CC8B-F5CA-4DC7-A3A8-D01B2E10731E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTelemetry.Instrumentation.Cassandra", "src\OpenTelemetry.Instrumentation.Cassandra\OpenTelemetry.Instrumentation.Cassandra.csproj", "{3313F7DF-E3A5-4A7F-965D-86807A017131}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTelemetry.Instrumentation.Cassandra.Tests", "test\OpenTelemetry.Instrumentation.Cassandra.Tests\OpenTelemetry.Instrumentation.Cassandra.Tests.csproj", "{FB48DC44-8C56-4329-9988-AEDF931E81E8}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.ResourceDetectors.Azure", "src\OpenTelemetry.ResourceDetectors.Azure\OpenTelemetry.ResourceDetectors.Azure.csproj", "{B07DC3CB-F724-40A5-889A-DA6601F462F3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.ResourceDetectors.Azure.Tests", "test\OpenTelemetry.ResourceDetectors.Azure.Tests\OpenTelemetry.ResourceDetectors.Azure.Tests.csproj", "{DFC6A4A9-5262-4507-B747-CC6B814205E6}"
Expand Down Expand Up @@ -505,6 +508,14 @@ Global
{BA58CC8B-F5CA-4DC7-A3A8-D01B2E10731E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BA58CC8B-F5CA-4DC7-A3A8-D01B2E10731E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BA58CC8B-F5CA-4DC7-A3A8-D01B2E10731E}.Release|Any CPU.Build.0 = Release|Any CPU
{3313F7DF-E3A5-4A7F-965D-86807A017131}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3313F7DF-E3A5-4A7F-965D-86807A017131}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3313F7DF-E3A5-4A7F-965D-86807A017131}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3313F7DF-E3A5-4A7F-965D-86807A017131}.Release|Any CPU.Build.0 = Release|Any CPU
{FB48DC44-8C56-4329-9988-AEDF931E81E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FB48DC44-8C56-4329-9988-AEDF931E81E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB48DC44-8C56-4329-9988-AEDF931E81E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB48DC44-8C56-4329-9988-AEDF931E81E8}.Release|Any CPU.Build.0 = Release|Any CPU
{B07DC3CB-F724-40A5-889A-DA6601F462F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B07DC3CB-F724-40A5-889A-DA6601F462F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B07DC3CB-F724-40A5-889A-DA6601F462F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -619,6 +630,8 @@ Global
{B40B975E-78B2-4712-8B4D-BADA67DF0C0A} = {22DF5DC0-1290-4E83-A9D8-6BB7DE3B3E63}
{C3B3BBAF-CC38-4D5C-AFA2-33184D07BF75} = {B75EE478-97F7-4E9F-9A5A-DB3D0988EDEA}
{BA58CC8B-F5CA-4DC7-A3A8-D01B2E10731E} = {B75EE478-97F7-4E9F-9A5A-DB3D0988EDEA}
{3313F7DF-E3A5-4A7F-965D-86807A017131} = {22DF5DC0-1290-4E83-A9D8-6BB7DE3B3E63}
{FB48DC44-8C56-4329-9988-AEDF931E81E8} = {2097345F-4DD3-477D-BC54-A922F9B2B402}
{B07DC3CB-F724-40A5-889A-DA6601F462F3} = {22DF5DC0-1290-4E83-A9D8-6BB7DE3B3E63}
{DFC6A4A9-5262-4507-B747-CC6B814205E6} = {2097345F-4DD3-477D-BC54-A922F9B2B402}
{73C10993-03AC-42F4-85BB-96EAAA8212D9} = {22DF5DC0-1290-4E83-A9D8-6BB7DE3B3E63}
Expand Down
2 changes: 2 additions & 0 deletions src/OpenTelemetry.Contrib.Extensions.AWSXRay/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
([#380](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/380))
* Raised minimum .NET version to `net462`
([#875](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/875))
* Replaced Newtonsoft.Json dependency with System.Text.Json
([#1092](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1092))
* Updated OTel SDK package version to 1.3.1
([#875](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/875))
* Enhancement - AWSECSResourceDetector - Implement `aws.{ecs.*,log.*}` resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="OpenTelemetry" Version="$(OpenTelemetryCoreLatestVersion)" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>
Expand All @@ -21,6 +20,10 @@
<Compile Remove="Resources\Http\ServerCertificateValidationProvider.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' Or '$(TargetFramework)' == '$(NetFrameworkMinimumSupportedVersion)'">
<PackageReference Include="System.Text.Json" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Internal\Guard.cs" Link="Includes\Guard.cs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text.Json;
using System.Text.RegularExpressions;

using Newtonsoft.Json.Linq;

using OpenTelemetry.Resources;

namespace OpenTelemetry.Contrib.Extensions.AWSXRay.Resources;
Expand Down Expand Up @@ -88,18 +87,18 @@ internal static List<KeyValuePair<string, object>> ExtractMetadataV4ResourceAttr
var metadataV4ContainerResponse = ResourceDetectorUtils.SendOutRequest(metadataV4Url, "GET", null, httpClientHandler).Result;
var metadataV4TaskResponse = ResourceDetectorUtils.SendOutRequest($"{metadataV4Url.TrimEnd('/')}/task", "GET", null, httpClientHandler).Result;

var containerResponse = JObject.Parse(metadataV4ContainerResponse);
var taskResponse = JObject.Parse(metadataV4TaskResponse);
using var containerResponse = JsonDocument.Parse(metadataV4ContainerResponse);
using var taskResponse = JsonDocument.Parse(metadataV4TaskResponse);

var containerArn = containerResponse.Value<string>("ContainerARN");
if (containerArn == null)
if (!containerResponse.RootElement.TryGetProperty("ContainerARN", out var containerArnElement)
|| containerArnElement.GetString() is not string containerArn)
{
AWSXRayEventSource.Log.ResourceAttributesExtractException(nameof(AWSECSResourceDetector), new ArgumentException("The ECS Metadata V4 response did not contain the 'ContainerARN' field"));
return new List<KeyValuePair<string, object>>();
}

var clusterArn = taskResponse.Value<string>("Cluster");
if (clusterArn == null)
if (!taskResponse.RootElement.TryGetProperty("Cluster", out var clusterArnElement)
|| clusterArnElement.GetString() is not string clusterArn)
{
AWSXRayEventSource.Log.ResourceAttributesExtractException(nameof(AWSECSResourceDetector), new ArgumentException("The ECS Metadata V4 response did not contain the 'Cluster' field"));
return new List<KeyValuePair<string, object>>();
Expand All @@ -117,10 +116,15 @@ internal static List<KeyValuePair<string, object>> ExtractMetadataV4ResourceAttr
new KeyValuePair<string, object>(AWSSemanticConventions.AttributeEcsClusterArn, clusterArn),
};

var launchType = taskResponse.Value<string>("LaunchType") switch
if (!taskResponse.RootElement.TryGetProperty("LaunchType", out var launchTypeElement))
{
launchTypeElement = default;
}

var launchType = launchTypeElement switch
{
string type when string.Equals("ec2", type, StringComparison.OrdinalIgnoreCase) => AWSSemanticConventions.ValueEcsLaunchTypeEc2,
string type when string.Equals("fargate", type, StringComparison.OrdinalIgnoreCase) => AWSSemanticConventions.ValueEcsLaunchTypeFargate,
{ ValueKind: JsonValueKind.String } when string.Equals("ec2", launchTypeElement.GetString(), StringComparison.OrdinalIgnoreCase) => AWSSemanticConventions.ValueEcsLaunchTypeEc2,
{ ValueKind: JsonValueKind.String } when string.Equals("fargate", launchTypeElement.GetString(), StringComparison.OrdinalIgnoreCase) => AWSSemanticConventions.ValueEcsLaunchTypeFargate,
_ => null,
};

Expand All @@ -130,31 +134,29 @@ string type when string.Equals("fargate", type, StringComparison.OrdinalIgnoreCa
}
else
{
AWSXRayEventSource.Log.ResourceAttributesExtractException(nameof(AWSECSResourceDetector), new ArgumentException($"The ECS Metadata V4 response contained the unrecognized launch type '{taskResponse["LaunchType"]}'"));
AWSXRayEventSource.Log.ResourceAttributesExtractException(nameof(AWSECSResourceDetector), new ArgumentException($"The ECS Metadata V4 response contained the unrecognized launch type '{launchTypeElement}'"));
}

var taskArn = taskResponse.Value<string>("TaskARN");
if (taskArn != null)
if (taskResponse.RootElement.TryGetProperty("TaskARN", out var taskArnElement) && taskArnElement.ValueKind == JsonValueKind.String)
{
resourceAttributes.Add(new KeyValuePair<string, object>(AWSSemanticConventions.AttributeEcsTaskArn, taskArn));
resourceAttributes.Add(new KeyValuePair<string, object>(AWSSemanticConventions.AttributeEcsTaskArn, taskArnElement.GetString()!));
}

var family = taskResponse.Value<string>("Family");
if (family != null)
if (taskResponse.RootElement.TryGetProperty("Family", out var familyElement) && familyElement.ValueKind == JsonValueKind.String)
{
resourceAttributes.Add(new KeyValuePair<string, object>(AWSSemanticConventions.AttributeEcsTaskFamily, family));
resourceAttributes.Add(new KeyValuePair<string, object>(AWSSemanticConventions.AttributeEcsTaskFamily, familyElement.GetString()!));
}

var revision = taskResponse.Value<string>("Revision");
if (revision != null)
if (taskResponse.RootElement.TryGetProperty("Revision", out var revisionElement) && revisionElement.ValueKind == JsonValueKind.String)
{
resourceAttributes.Add(new KeyValuePair<string, object>(AWSSemanticConventions.AttributeEcsTaskRevision, revision));
resourceAttributes.Add(new KeyValuePair<string, object>(AWSSemanticConventions.AttributeEcsTaskRevision, revisionElement.GetString()!));
}

if (string.Equals("awslogs", containerResponse.Value<string>("LogDriver"), StringComparison.Ordinal))
if (containerResponse.RootElement.TryGetProperty("LogDriver", out var logDriverElement)
&& logDriverElement.ValueKind == JsonValueKind.String
&& logDriverElement.ValueEquals("awslogs"))
{
JObject? logOptions = containerResponse.Value<JObject>("LogOptions");
if (logOptions != null)
if (containerResponse.RootElement.TryGetProperty("LogOptions", out var logOptionsElement))
{
var regex = new Regex(@"arn:aws:ecs:([^:]+):([^:]+):.*");
var match = regex.Match(containerArn);
Expand All @@ -167,15 +169,15 @@ string type when string.Equals("fargate", type, StringComparison.OrdinalIgnoreCa
var logsRegion = match.Groups[1];
var logsAccount = match.Groups[2];

var logGroupName = logOptions.Value<string>("awslogs-group");
if (logGroupName != null)
if (logOptionsElement.TryGetProperty("awslogs-group", out var logGroupElement) && logGroupElement.ValueKind == JsonValueKind.String)
{
var logGroupName = logGroupElement.GetString()!;
resourceAttributes.Add(new KeyValuePair<string, object>(AWSSemanticConventions.AttributeLogGroupNames, new string[] { logGroupName }));
resourceAttributes.Add(new KeyValuePair<string, object>(AWSSemanticConventions.AttributeLogGroupArns, new string[] { $"arn:aws:logs:{logsRegion}:{logsAccount}:log-group:{logGroupName}:*" }));

var logStreamName = logOptions.Value<string>("awslogs-stream");
if (logStreamName != null)
if (logOptionsElement.TryGetProperty("awslogs-stream", out var logStreamElement) && logStreamElement.ValueKind == JsonValueKind.String)
{
var logStreamName = logStreamElement.GetString()!;
resourceAttributes.Add(new KeyValuePair<string, object>(AWSSemanticConventions.AttributeLogStreamNames, new string[] { logStreamName }));
resourceAttributes.Add(new KeyValuePair<string, object>(AWSSemanticConventions.AttributeLogStreamArns, new string[] { $"arn:aws:logs:{logsRegion}:{logsAccount}:log-group:{logGroupName}:log-stream:{logStreamName}" }));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
// limitations under the License.
// </copyright>

using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.Models;

internal class AWSEBSMetadataModel
{
[JsonProperty(PropertyName = "deployment_id")]
[JsonPropertyName("deployment_id")]
public string? DeploymentId { get; set; }

[JsonProperty(PropertyName = "environment_name")]
[JsonPropertyName("environment_name")]
public string? EnvironmentName { get; set; }

[JsonProperty(PropertyName = "version_label")]
[JsonPropertyName("version_label")]
public string? VersionLabel { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
// limitations under the License.
// </copyright>

using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.Models;

internal class AWSEKSClusterDataModel
{
[JsonProperty(PropertyName = "cluster.name")]
[JsonPropertyName("cluster.name")]
public string? ClusterName { get; set; }
}
Loading

0 comments on commit 933c3be

Please sign in to comment.