Skip to content

Commit

Permalink
[Extensions.AWSXRay] Add ECS and Logs attributes based on Metadata v4…
Browse files Browse the repository at this point in the history
… endpoint

Co-authored-by: Piotr Kiełkowicz <[email protected]>
  • Loading branch information
Michele Mancioppi and Kielek committed Mar 9, 2023
1 parent 588264e commit a006dc6
Show file tree
Hide file tree
Showing 27 changed files with 703 additions and 278 deletions.

This file was deleted.

Empty file.
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
#nullable enable
OpenTelemetry.Contrib.Extensions.AWSXRay.AWSXRayIdGenerator
OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.AWSEBSResourceDetector
OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.AWSEBSResourceDetector.AWSEBSResourceDetector() -> void
OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.AWSEBSResourceDetector.Detect() -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>?
OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.AWSEBSResourceDetector.Detect() -> OpenTelemetry.Resources.Resource
OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.AWSEC2ResourceDetector
OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.AWSEC2ResourceDetector.AWSEC2ResourceDetector() -> void
OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.AWSEC2ResourceDetector.Detect() -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>?
OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.IResourceDetector
OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.IResourceDetector.Detect() -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>?
OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.AWSEC2ResourceDetector.Detect() -> OpenTelemetry.Resources.Resource
OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.ResourceDetectorUtils
OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.ResourceDetectorUtils.ResourceDetectorUtils() -> void
OpenTelemetry.Contrib.Extensions.AWSXRay.Trace.AWSXRayPropagator
OpenTelemetry.Contrib.Extensions.AWSXRay.Trace.AWSXRayPropagator.AWSXRayPropagator() -> void
OpenTelemetry.Resources.ResourceBuilderExtensions
OpenTelemetry.Trace.TracerProviderBuilderExtensions
override OpenTelemetry.Contrib.Extensions.AWSXRay.Trace.AWSXRayPropagator.Extract<T>(OpenTelemetry.Context.Propagation.PropagationContext context, T carrier, System.Func<T, string!, System.Collections.Generic.IEnumerable<string!>!>! getter) -> OpenTelemetry.Context.Propagation.PropagationContext
override OpenTelemetry.Contrib.Extensions.AWSXRay.Trace.AWSXRayPropagator.Fields.get -> System.Collections.Generic.ISet<string!>!
override OpenTelemetry.Contrib.Extensions.AWSXRay.Trace.AWSXRayPropagator.Inject<T>(OpenTelemetry.Context.Propagation.PropagationContext context, T carrier, System.Action<T, string!, string!>! setter) -> void
static OpenTelemetry.Resources.ResourceBuilderExtensions.AddDetector(this OpenTelemetry.Resources.ResourceBuilder! resourceBuilder, OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.IResourceDetector! resourceDetector) -> OpenTelemetry.Resources.ResourceBuilder!
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddXRayTraceId(this OpenTelemetry.Trace.TracerProviderBuilder! builder) -> OpenTelemetry.Trace.TracerProviderBuilder!
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddXRayTraceIdWithSampler(this OpenTelemetry.Trace.TracerProviderBuilder! builder, OpenTelemetry.Trace.Sampler! sampler) -> OpenTelemetry.Trace.TracerProviderBuilder!
override OpenTelemetry.Contrib.Extensions.AWSXRay.Trace.AWSXRayPropagator.Extract<T>(OpenTelemetry.Context.Propagation.PropagationContext context, T carrier, System.Func<T, string, System.Collections.Generic.IEnumerable<string>> getter) -> OpenTelemetry.Context.Propagation.PropagationContext
override OpenTelemetry.Contrib.Extensions.AWSXRay.Trace.AWSXRayPropagator.Fields.get -> System.Collections.Generic.ISet<string>
override OpenTelemetry.Contrib.Extensions.AWSXRay.Trace.AWSXRayPropagator.Inject<T>(OpenTelemetry.Context.Propagation.PropagationContext context, T carrier, System.Action<T, string, string> setter) -> void
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddXRayTraceId(this OpenTelemetry.Trace.TracerProviderBuilder builder) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddXRayTraceIdWithSampler(this OpenTelemetry.Trace.TracerProviderBuilder builder, OpenTelemetry.Trace.Sampler sampler) -> OpenTelemetry.Trace.TracerProviderBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.ResourceDetectorUtils
OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.ResourceDetectorUtils.ResourceDetectorUtils() -> void
OpenTelemetry.Contrib.Extensions.AWSXRay.Trace.AWSXRayPropagator
OpenTelemetry.Contrib.Extensions.AWSXRay.Trace.AWSXRayPropagator.AWSXRayPropagator() -> void
OpenTelemetry.Resources.ResourceBuilderExtensions
OpenTelemetry.Trace.TracerProviderBuilderExtensions
override OpenTelemetry.Contrib.Extensions.AWSXRay.Trace.AWSXRayPropagator.Extract<T>(OpenTelemetry.Context.Propagation.PropagationContext context, T carrier, System.Func<T, string!, System.Collections.Generic.IEnumerable<string!>!>! getter) -> OpenTelemetry.Context.Propagation.PropagationContext
override OpenTelemetry.Contrib.Extensions.AWSXRay.Trace.AWSXRayPropagator.Fields.get -> System.Collections.Generic.ISet<string!>!
override OpenTelemetry.Contrib.Extensions.AWSXRay.Trace.AWSXRayPropagator.Inject<T>(OpenTelemetry.Context.Propagation.PropagationContext context, T carrier, System.Action<T, string!, string!>! setter) -> void
static OpenTelemetry.Resources.ResourceBuilderExtensions.AddDetector(this OpenTelemetry.Resources.ResourceBuilder! resourceBuilder, OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.IResourceDetector! resourceDetector) -> OpenTelemetry.Resources.ResourceBuilder!
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddXRayTraceId(this OpenTelemetry.Trace.TracerProviderBuilder! builder) -> OpenTelemetry.Trace.TracerProviderBuilder!
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddXRayTraceIdWithSampler(this OpenTelemetry.Trace.TracerProviderBuilder! builder, OpenTelemetry.Trace.Sampler! sampler) -> OpenTelemetry.Trace.TracerProviderBuilder!
override OpenTelemetry.Contrib.Extensions.AWSXRay.Trace.AWSXRayPropagator.Extract<T>(OpenTelemetry.Context.Propagation.PropagationContext context, T carrier, System.Func<T, string, System.Collections.Generic.IEnumerable<string>> getter) -> OpenTelemetry.Context.Propagation.PropagationContext
override OpenTelemetry.Contrib.Extensions.AWSXRay.Trace.AWSXRayPropagator.Fields.get -> System.Collections.Generic.ISet<string>
override OpenTelemetry.Contrib.Extensions.AWSXRay.Trace.AWSXRayPropagator.Inject<T>(OpenTelemetry.Context.Propagation.PropagationContext context, T carrier, System.Action<T, string, string> setter) -> void
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddXRayTraceId(this OpenTelemetry.Trace.TracerProviderBuilder builder) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddXRayTraceIdWithSampler(this OpenTelemetry.Trace.TracerProviderBuilder builder, OpenTelemetry.Trace.Sampler sampler) -> OpenTelemetry.Trace.TracerProviderBuilder
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
#nullable enable
OpenTelemetry.Contrib.Extensions.AWSXRay.AWSXRayIdGenerator
OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.AWSEBSResourceDetector
OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.AWSEBSResourceDetector.AWSEBSResourceDetector() -> void
*REMOVED*OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.AWSEBSResourceDetector.Detect() -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>>
OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.AWSEBSResourceDetector.Detect() -> OpenTelemetry.Resources.Resource
*REMOVED*OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.AWSEC2ResourceDetector.Detect() -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>>
OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.AWSEC2ResourceDetector.Detect() -> OpenTelemetry.Resources.Resource
*REMOVED*OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.AWSECSResourceDetector.Detect() -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>>
OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.AWSECSResourceDetector.Detect() -> OpenTelemetry.Resources.Resource
*REMOVED*OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.AWSEKSResourceDetector.Detect() -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>>
OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.AWSEKSResourceDetector.Detect() -> OpenTelemetry.Resources.Resource
*REMOVED*OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.AWSLambdaResourceDetector.Detect() -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>>
OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.AWSLambdaResourceDetector.Detect() -> OpenTelemetry.Resources.Resource
*REMOVED*OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.IResourceDetector
*REMOVED*OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.IResourceDetector.Detect() -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>>
*REMOVED*OpenTelemetry.Resources.ResourceBuilderExtensions
*REMOVED*static OpenTelemetry.Resources.ResourceBuilderExtensions.AddDetector(this OpenTelemetry.Resources.ResourceBuilder resourceBuilder, OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.IResourceDetector resourceDetector) -> OpenTelemetry.Resources.ResourceBuilder
11 changes: 11 additions & 0 deletions src/OpenTelemetry.Contrib.Extensions.AWSXRay/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
* Enhancement - AWSXRayIdGenerator - Generate X-Ray IDs with global Random
instance instead of recreating with ThreadLocal
([#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))
* 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
attributes with data from ECS Metadata endpoint v4
([#875](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/875))
* Removal - IResourceDetector - Remove local IResourceDetector interface and its
supporting ResourceBuilderExtensions extension, and migrate all detectors to
implement OpenTelemetry.Resources.IResourceDetector
([#875](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/875))

## 1.2.0

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- OmniSharp/VS Code requires TargetFrameworks to be in descending order for IntelliSense and analysis. -->
<TargetFrameworks>netstandard2.0;net452</TargetFrameworks>
<TargetFrameworks>netstandard2.0;$(NetFrameworkMinimumSupportedVersion)</TargetFrameworks>
<Description>OpenTelemetry extensions for AWS X-Ray.</Description>
<MinVerTagPrefix>Extensions.AWSXRay-</MinVerTagPrefix>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="OpenTelemetry" Version="1.1.0" />
<PackageReference Include="OpenTelemetry" Version="$(OpenTelemetryCoreLatestVersion)" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'netstandard2.0'">
<ItemGroup Condition="'$(TargetFramework)' == '$(NetFrameworkMinimumSupportedVersion)'">
<Compile Remove="Resources\AWSECSResourceDetector.cs" />
<Compile Remove="Resources\AWSEKSResourceDetector.cs" />
<Compile Remove="Resources\AWSLambdaResourceDetector.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
#if NETSTANDARD
using System.Runtime.InteropServices;
#endif

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

namespace OpenTelemetry.Contrib.Extensions.AWSXRay.Resources;

Expand All @@ -34,11 +36,9 @@ public class AWSEBSResourceDetector : IResourceDetector
/// <summary>
/// Detector the required and optional resource attributes from AWS ElasticBeanstalk.
/// </summary>
/// <returns>List of key-value pairs of resource attributes.</returns>
public IEnumerable<KeyValuePair<string, object?>>? Detect()
/// <returns>Resource with key-value pairs of resource attributes.</returns>
public Resource Detect()
{
List<KeyValuePair<string, object?>>? resourceAttributes = null;

try
{
string? filePath = null;
Expand All @@ -57,28 +57,43 @@ public class AWSEBSResourceDetector : IResourceDetector

var metadata = this.GetEBSMetadata(filePath);

resourceAttributes = this.ExtractResourceAttributes(metadata);
return new Resource(this.ExtractResourceAttributes(metadata));
}
catch (Exception ex)
{
AWSXRayEventSource.Log.ResourceAttributesExtractException(nameof(AWSEBSResourceDetector), ex);
}

return resourceAttributes;
return Resource.Empty;
}

internal List<KeyValuePair<string, object?>>? ExtractResourceAttributes(AWSEBSMetadataModel? metadata)
internal List<KeyValuePair<string, object>> ExtractResourceAttributes(AWSEBSMetadataModel? metadata)
{
var resourceAttributes = new List<KeyValuePair<string, object?>>()
var resourceAttributes = new List<KeyValuePair<string, object>>()
{
new KeyValuePair<string, object?>(AWSSemanticConventions.AttributeCloudProvider, "aws"),
new KeyValuePair<string, object?>(AWSSemanticConventions.AttributeCloudPlatform, "aws_elastic_beanstalk"),
new KeyValuePair<string, object?>(AWSSemanticConventions.AttributeServiceName, "aws_elastic_beanstalk"),
new KeyValuePair<string, object?>(AWSSemanticConventions.AttributeServiceNamespace, metadata?.EnvironmentName),
new KeyValuePair<string, object?>(AWSSemanticConventions.AttributeServiceInstanceID, metadata?.DeploymentId),
new KeyValuePair<string, object?>(AWSSemanticConventions.AttributeServiceVersion, metadata?.VersionLabel),
new KeyValuePair<string, object>(AWSSemanticConventions.AttributeCloudProvider, "aws"),
new KeyValuePair<string, object>(AWSSemanticConventions.AttributeCloudPlatform, "aws_elastic_beanstalk"),
new KeyValuePair<string, object>(AWSSemanticConventions.AttributeServiceName, "aws_elastic_beanstalk"),
};

if (metadata != null)
{
if (metadata.EnvironmentName != null)
{
resourceAttributes.Add(new KeyValuePair<string, object>(AWSSemanticConventions.AttributeServiceNamespace, metadata.EnvironmentName));
}

if (metadata.DeploymentId != null)
{
resourceAttributes.Add(new KeyValuePair<string, object>(AWSSemanticConventions.AttributeServiceInstanceID, metadata.DeploymentId));
}

if (metadata.VersionLabel != null)
{
resourceAttributes.Add(new KeyValuePair<string, object>(AWSSemanticConventions.AttributeServiceVersion, metadata.VersionLabel));
}
}

return resourceAttributes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

using System;
using System.Collections.Generic;

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

namespace OpenTelemetry.Contrib.Extensions.AWSXRay.Resources;

Expand All @@ -34,41 +36,62 @@ public class AWSEC2ResourceDetector : IResourceDetector
/// <summary>
/// Detector the required and optional resource attributes from AWS EC2.
/// </summary>
/// <returns>List of key-value pairs of resource attributes.</returns>
public IEnumerable<KeyValuePair<string, object?>>? Detect()
/// <returns>Resource with key-value pairs of resource attributes.</returns>
public Resource Detect()
{
List<KeyValuePair<string, object?>>? resourceAttributes = null;

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

resourceAttributes = this.ExtractResourceAttributes(identity, hostName);
return new Resource(this.ExtractResourceAttributes(identity, hostName));
}
catch (Exception ex)
{
AWSXRayEventSource.Log.ResourceAttributesExtractException(nameof(AWSEC2ResourceDetector), ex);
}

return resourceAttributes;
return Resource.Empty;
}

internal List<KeyValuePair<string, object?>> ExtractResourceAttributes(AWSEC2IdentityDocumentModel? identity, string hostName)
internal List<KeyValuePair<string, object>> ExtractResourceAttributes(AWSEC2IdentityDocumentModel? identity, string hostName)
{
var resourceAttributes = new List<KeyValuePair<string, object?>>()
var resourceAttributes = new List<KeyValuePair<string, object>>()
{
new KeyValuePair<string, object?>(AWSSemanticConventions.AttributeCloudProvider, "aws"),
new KeyValuePair<string, object?>(AWSSemanticConventions.AttributeCloudPlatform, "aws_ec2"),
new KeyValuePair<string, object?>(AWSSemanticConventions.AttributeCloudAccountID, identity?.AccountId),
new KeyValuePair<string, object?>(AWSSemanticConventions.AttributeCloudAvailableZone, identity?.AvailabilityZone),
new KeyValuePair<string, object?>(AWSSemanticConventions.AttributeHostID, identity?.InstanceId),
new KeyValuePair<string, object?>(AWSSemanticConventions.AttributeHostType, identity?.InstanceType),
new KeyValuePair<string, object?>(AWSSemanticConventions.AttributeCloudRegion, identity?.Region),
new KeyValuePair<string, object?>(AWSSemanticConventions.AttributeHostName, hostName),
new KeyValuePair<string, object>(AWSSemanticConventions.AttributeCloudProvider, "aws"),
new KeyValuePair<string, object>(AWSSemanticConventions.AttributeCloudPlatform, "aws_ec2"),
new KeyValuePair<string, object>(AWSSemanticConventions.AttributeHostName, hostName),
};

if (identity != null)
{
if (identity.AccountId != null)
{
resourceAttributes.Add(new KeyValuePair<string, object>(AWSSemanticConventions.AttributeCloudAccountID, identity.AccountId));
}

if (identity.AvailabilityZone != null)
{
resourceAttributes.Add(new KeyValuePair<string, object>(AWSSemanticConventions.AttributeCloudAvailableZone, identity.AvailabilityZone));
}

if (identity.InstanceId != null)
{
resourceAttributes.Add(new KeyValuePair<string, object>(AWSSemanticConventions.AttributeHostID, identity.InstanceId));
}

if (identity.InstanceType != null)
{
resourceAttributes.Add(new KeyValuePair<string, object>(AWSSemanticConventions.AttributeHostType, identity.InstanceType));
}

if (identity.Region != null)
{
resourceAttributes.Add(new KeyValuePair<string, object>(AWSSemanticConventions.AttributeCloudRegion, identity.Region));
}
}

return resourceAttributes;
}

Expand Down
Loading

0 comments on commit a006dc6

Please sign in to comment.