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

Add ECS and Logs attributes based on Metadata v4 endpoint #875

Merged
merged 3 commits into from
Mar 13, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"Examples.GrpcCore.AspNetCore": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,
"applicationUrl": "http://localhost:5000/weatherforecast",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"Examples.GrpcCore.AspNetCore": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "http://localhost:5000/weatherforecast",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#nullable enable
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!
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
mmanciop marked this conversation as resolved.
Show resolved Hide resolved
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!
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
#nullable enable
*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.AWSLambdaResourceDetector.Detect() -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>?'
*REMOVED*OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.AWSLambdaResourceDetector.Detect() -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>?
*REMOVED*OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.AWSEBSResourceDetector.Detect() -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>?
*REMOVED*OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.AWSEC2ResourceDetector.Detect() -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>?
*REMOVED*OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.AWSECSResourceDetector.Detect() -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>?
*REMOVED*OpenTelemetry.Contrib.Extensions.AWSXRay.Resources.AWSEKSResourceDetector.Detect() -> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>?
*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
mmanciop marked this conversation as resolved.
Show resolved Hide resolved
([#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)" />
mmanciop marked this conversation as resolved.
Show resolved Hide resolved
<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 @@ -36,11 +38,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 @@ -59,28 +59,43 @@ public class AWSEBSResourceDetector : IResourceDetector

var metadata = GetEBSMetadata(filePath);

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

return resourceAttributes;
return Resource.Empty;
}

internal static List<KeyValuePair<string, object?>>? ExtractResourceAttributes(AWSEBSMetadataModel? metadata)
internal static 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 = GetAWSEC2Token();
var identity = GetAWSEC2Identity(token);
var hostName = GetAWSEC2HostName(token);

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

return resourceAttributes;
return Resource.Empty;
}

internal static 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?>>()
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