Skip to content
Open
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
1 change: 1 addition & 0 deletions src/OpenTelemetry.Resources.AWS/AWSEC2Detector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ internal List<KeyValuePair<string, object>> ExtractResourceAttributes(AWSEC2Iden
.AddAttributeCloudAccountID(identity?.AccountId)
.AddAttributeCloudAvailabilityZone(identity?.AvailabilityZone)
.AddAttributeHostID(identity?.InstanceId)
.AddAttributeHostImageId(identity?.ImageId)
.AddAttributeHostType(identity?.InstanceType)
.AddAttributeCloudRegion(identity?.Region)
.Build();
Expand Down
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Resources.AWS/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

* Added `host.image.id` resource attribute to `AWSEC2Detector`, populated from
the EC2 instance identity document's `imageId` (AMI ID).
([#5110](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/5110))

## 1.18.0

Released 2026-Aug-21
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

namespace OpenTelemetry.Resources.AWS.Models;

// See https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html

internal class AWSEC2IdentityDocumentModel
{
[JsonPropertyName("accountId")]
Expand All @@ -21,4 +23,7 @@ internal class AWSEC2IdentityDocumentModel

[JsonPropertyName("instanceType")]
public string? InstanceType { get; set; }

[JsonPropertyName("imageId")]
public string? ImageId { get; set; }
}
2 changes: 1 addition & 1 deletion src/OpenTelemetry.Resources.AWS/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ The resource detectors will record the following metadata based on where
your application is running:

- **AWSEC2Detector**: cloud provider, cloud platform, account id,
cloud availability zone, host id, host type, aws region, host name.
cloud availability zone, host id, host type, host image id, aws region, host name.
- **AWSEBSDetector**: cloud provider, cloud platform, service name,
service namespace, instance id, service version.
- **AWSECSDetector**: cloud provider, cloud platform, cloud resource id,
Expand Down
8 changes: 8 additions & 0 deletions src/Shared/AWS/AWSSemanticConventions.Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,14 @@ private abstract class AWSSemanticConventionsBase
/// </remarks>
public virtual string AttributeHostType => string.Empty;

/// <summary>
/// VM image ID or host OS image ID. For Cloud, this value is from the provider.
/// </summary>
/// <remarks>
/// HostAttributes.AttributeHostImageId
/// </remarks>
public virtual string AttributeHostImageId => string.Empty;

/// <summary>
/// Name of the host. On Unix systems, it may contain what the hostname command returns, or the fully qualified hostname, or another name specified by the user.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/Shared/AWS/AWSSemanticConventions.Legacy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ private abstract class AWSSemanticConventionsLegacy : AWSSemanticConventionsBase
public override string AttributeHostID => "host.id";
public override string AttributeHostType => "host.type";
public override string AttributeHostName => "host.name";
public override string AttributeHostImageId => "host.image.id";

// HTTP Attributes
[Obsolete("Replaced by <c>http.response.status_code</c>.")]
Expand Down
4 changes: 4 additions & 0 deletions src/Shared/AWS/AWSSemanticConventions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ public AttributeBuilderImpl AddAttributeHostType(object? value, bool addIfEmpty
public AttributeBuilderImpl AddAttributeHostName(object? value, bool addIfEmpty = false) =>
this.awsSemanticConventions.Add(this, x => x.AttributeHostName, value, addIfEmpty);

/// <inheritdoc cref="AWSSemanticConventionsBase.AttributeHostImageId"/>
public AttributeBuilderImpl AddAttributeHostImageId(object? value, bool addIfEmpty = false) =>
this.awsSemanticConventions.Add(this, x => x.AttributeHostImageId, value, addIfEmpty);

#endregion

#region Http
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public void TestExtractResourceAttributes(SemanticConventionVersion semanticConv
Assert.Equal("Test availability zone", resourceAttributes[ExpectedSemanticConventions.AttributeCloudAvailabilityZone]);
Assert.Equal("Test instance id", resourceAttributes[ExpectedSemanticConventions.AttributeHostID]);
Assert.Equal("Test instance type", resourceAttributes[ExpectedSemanticConventions.AttributeHostType]);
Assert.Equal("Test image id", resourceAttributes[ExpectedSemanticConventions.AttributeHostImageId]);
Assert.Equal("Test aws region", resourceAttributes[ExpectedSemanticConventions.AttributeCloudRegion]);
Assert.Equal("Test host name", resourceAttributes[ExpectedSemanticConventions.AttributeHostName]);
}
Expand All @@ -103,6 +104,7 @@ public void TestDeserializeResponse()
Assert.Equal("us-east-1a", ec2IdentityDocumentModel.AvailabilityZone);
Assert.Equal("i-12345678901234567", ec2IdentityDocumentModel.InstanceId);
Assert.Equal("t2.micro", ec2IdentityDocumentModel.InstanceType);
Assert.Equal("ami-12345678901234567", ec2IdentityDocumentModel.ImageId);
Assert.Equal("us-east-1", ec2IdentityDocumentModel.Region);
}

Expand All @@ -114,6 +116,7 @@ private static class ExpectedSemanticConventions
public const string AttributeCloudAvailabilityZone = "cloud.availability_zone";
public const string AttributeCloudRegion = "cloud.region";
public const string AttributeHostID = "host.id";
public const string AttributeHostImageId = "host.image.id";
public const string AttributeHostType = "host.type";
public const string AttributeHostName = "host.name";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ public SampleAWSEC2IdentityDocumentModel()
this.Region = "Test aws region";
this.InstanceId = "Test instance id";
this.InstanceType = "Test instance type";
this.ImageId = "Test image id";
}
}