From 78648078d0ccd98245587dba21561194ba95b4c0 Mon Sep 17 00:00:00 2001 From: philip pittle Date: Mon, 16 Dec 2024 22:37:39 -0800 Subject: [PATCH] Update libraries to impelement Semantic Convention 1.28 and 1.29 --- .../.publicApi/PublicAPI.Unshipped.txt | 2 +- .../AWSTracingPipelineCustomizer.cs | 4 +- .../README.md | 2 +- .../.publicApi/PublicAPI.Unshipped.txt | 2 +- .../README.md | 2 +- .../.publicApi/PublicAPI.Unshipped.txt | 2 +- src/OpenTelemetry.Resources.AWS/README.md | 2 +- src/Shared/AWS/AWSSemanticConventions.Base.cs | 62 ++++++++++--- ....0.cs => AWSSemanticConventions.Legacy.cs} | 10 +- src/Shared/AWS/AWSSemanticConventions.cs | 8 +- .../AWS/AWSSemanticConventions.v1.28.0.cs | 55 +++++++++++ .../AWS/AWSSemanticConventions.v1.29.0.cs | 35 +------ src/Shared/AWS/SemanticConventionVersion.cs | 8 +- .../AWSClientInstrumentationOptionsTests.cs | 92 +++++++++++++++++++ .../AWSLambdaInstrumentationOptionsTests.cs | 4 +- 15 files changed, 219 insertions(+), 71 deletions(-) rename src/Shared/AWS/{AWSSemanticConventions.v1.27.0.cs => AWSSemanticConventions.Legacy.cs} (93%) create mode 100644 src/Shared/AWS/AWSSemanticConventions.v1.28.0.cs create mode 100644 test/OpenTelemetry.Instrumentation.AWS.Tests/AWSClientInstrumentationOptionsTests.cs diff --git a/src/OpenTelemetry.Instrumentation.AWS/.publicApi/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Instrumentation.AWS/.publicApi/PublicAPI.Unshipped.txt index ebcf26b66c..2365f8b75b 100644 --- a/src/OpenTelemetry.Instrumentation.AWS/.publicApi/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Instrumentation.AWS/.publicApi/PublicAPI.Unshipped.txt @@ -2,7 +2,7 @@ OpenTelemetry.Instrumentation.AWS.SemanticConventionVersion OpenTelemetry.Instrumentation.AWS.SemanticConventionVersion.Latest = 0 -> OpenTelemetry.Instrumentation.AWS.SemanticConventionVersion OpenTelemetry.Instrumentation.AWS.SemanticConventionVersion.V1_29_0_Experimental = 2 -> OpenTelemetry.Instrumentation.AWS.SemanticConventionVersion -OpenTelemetry.Instrumentation.AWS.SemanticConventionVersion.V1_27_0_Experimental = 1 -> OpenTelemetry.Instrumentation.AWS.SemanticConventionVersion +OpenTelemetry.Instrumentation.AWS.SemanticConventionVersion.V1_28_0_Experimental = 1 -> OpenTelemetry.Instrumentation.AWS.SemanticConventionVersion OpenTelemetry.Instrumentation.AWS.AWSClientInstrumentationOptions OpenTelemetry.Instrumentation.AWS.AWSClientInstrumentationOptions.AWSClientInstrumentationOptions() -> void OpenTelemetry.Instrumentation.AWS.AWSClientInstrumentationOptions.SemanticConventionVersion.get -> OpenTelemetry.Instrumentation.AWS.SemanticConventionVersion diff --git a/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineCustomizer.cs b/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineCustomizer.cs index d9c1f550a5..6239999bb9 100644 --- a/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineCustomizer.cs +++ b/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineCustomizer.cs @@ -12,6 +12,8 @@ namespace OpenTelemetry.Instrumentation.AWS.Implementation; /// internal class AWSTracingPipelineCustomizer : IRuntimePipelineCustomizer { + public const string UniqueName = "AWS Tracing Registration Customization"; + private readonly AWSClientInstrumentationOptions options; public AWSTracingPipelineCustomizer(AWSClientInstrumentationOptions options) @@ -19,7 +21,7 @@ public AWSTracingPipelineCustomizer(AWSClientInstrumentationOptions options) this.options = options; } - public string UniqueName => "AWS Tracing Registration Customization"; + string IRuntimePipelineCustomizer.UniqueName => UniqueName; public void Customize(Type serviceClientType, RuntimePipeline pipeline) { diff --git a/src/OpenTelemetry.Instrumentation.AWS/README.md b/src/OpenTelemetry.Instrumentation.AWS/README.md index 8c464f81fd..6a14b3bfc2 100644 --- a/src/OpenTelemetry.Instrumentation.AWS/README.md +++ b/src/OpenTelemetry.Instrumentation.AWS/README.md @@ -53,7 +53,7 @@ emit the GET as `"http.request.method"`. Future versions the OpenTelemetry.*.AWS libraries will include updates to the Semantic Convention, which may break compatibility with a previous version. -The default will remain as `V1_27_0_Experimental` until the next major version bump. +The default will remain as `V1_28_0_Experimental` until the next major version bump. To opt in to automatic upgrades, you can use `SemanticConventionVersion.Latest` or you can specify a specific version: diff --git a/src/OpenTelemetry.Instrumentation.AWSLambda/.publicApi/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Instrumentation.AWSLambda/.publicApi/PublicAPI.Unshipped.txt index f50ad0fa08..f844321a21 100644 --- a/src/OpenTelemetry.Instrumentation.AWSLambda/.publicApi/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Instrumentation.AWSLambda/.publicApi/PublicAPI.Unshipped.txt @@ -2,7 +2,7 @@ OpenTelemetry.Instrumentation.AWSLambda.SemanticConventionVersion OpenTelemetry.Instrumentation.AWSLambda.SemanticConventionVersion.Latest = 0 -> OpenTelemetry.Instrumentation.AWSLambda.SemanticConventionVersion OpenTelemetry.Instrumentation.AWSLambda.SemanticConventionVersion.V1_29_0_Experimental = 2 -> OpenTelemetry.Instrumentation.AWSLambda.SemanticConventionVersion -OpenTelemetry.Instrumentation.AWSLambda.SemanticConventionVersion.V1_27_0_Experimental = 1 -> OpenTelemetry.Instrumentation.AWSLambda.SemanticConventionVersion +OpenTelemetry.Instrumentation.AWSLambda.SemanticConventionVersion.V1_28_0_Experimental = 1 -> OpenTelemetry.Instrumentation.AWSLambda.SemanticConventionVersion OpenTelemetry.Instrumentation.AWSLambda.AWSLambdaInstrumentationOptions OpenTelemetry.Instrumentation.AWSLambda.AWSLambdaInstrumentationOptions.AWSLambdaInstrumentationOptions() -> void OpenTelemetry.Instrumentation.AWSLambda.AWSLambdaInstrumentationOptions.DisableAwsXRayContextExtraction.get -> bool diff --git a/src/OpenTelemetry.Instrumentation.AWSLambda/README.md b/src/OpenTelemetry.Instrumentation.AWSLambda/README.md index 4b4d532c74..a91606754e 100644 --- a/src/OpenTelemetry.Instrumentation.AWSLambda/README.md +++ b/src/OpenTelemetry.Instrumentation.AWSLambda/README.md @@ -160,7 +160,7 @@ Future versions of OpenTelemetry.Instrumentation.AWSLambda library will include updates to the Semantic Convention, which may break compatibility with a previous version. -The default will remain as `V1_27_0_Experimental` until the next major version bump. +The default will remain as `V1_28_0_Experimental` until the next major version bump. To opt in to automatic upgrades, you can use `SemanticConventionVersion.Latest` or you can specify a specific version: diff --git a/src/OpenTelemetry.Resources.AWS/.publicApi/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Resources.AWS/.publicApi/PublicAPI.Unshipped.txt index 597202b520..95c1327a56 100644 --- a/src/OpenTelemetry.Resources.AWS/.publicApi/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Resources.AWS/.publicApi/PublicAPI.Unshipped.txt @@ -1,7 +1,7 @@ OpenTelemetry.Resources.AWS.SemanticConventionVersion OpenTelemetry.Resources.AWS.SemanticConventionVersion.Latest = 0 -> OpenTelemetry.Resources.AWS.SemanticConventionVersion OpenTelemetry.Resources.AWS.SemanticConventionVersion.V1_29_0_Experimental = 2 -> OpenTelemetry.Resources.AWS.SemanticConventionVersion -OpenTelemetry.Resources.AWS.SemanticConventionVersion.V1_27_0_Experimental = 1 -> OpenTelemetry.Resources.AWS.SemanticConventionVersion +OpenTelemetry.Resources.AWS.SemanticConventionVersion.V1_28_0_Experimental = 1 -> OpenTelemetry.Resources.AWS.SemanticConventionVersion OpenTelemetry.Resources.AWS.AWSResourceBuilderOptions OpenTelemetry.Resources.AWS.AWSResourceBuilderOptions.AWSResourceBuilderOptions() -> void OpenTelemetry.Resources.AWS.AWSResourceBuilderOptions.SemanticConventionVersion.get -> OpenTelemetry.Resources.AWS.SemanticConventionVersion diff --git a/src/OpenTelemetry.Resources.AWS/README.md b/src/OpenTelemetry.Resources.AWS/README.md index 36bf7779d7..9d25e83114 100644 --- a/src/OpenTelemetry.Resources.AWS/README.md +++ b/src/OpenTelemetry.Resources.AWS/README.md @@ -83,7 +83,7 @@ emit the GET as `"http.request.method"`. Future versions the OpenTelemetry.*.AWS libraries will include updates to the Semantic Convention, which may break compatibility with a previous version. -The default will remain as `V1_27_0_Experimental` until the next major version bump. +The default will remain as `V1_28_0_Experimental` until the next major version bump. To opt in to automatic upgrades, you can use `SemanticConventionVersion.Latest` or you can specify a specific version: diff --git a/src/Shared/AWS/AWSSemanticConventions.Base.cs b/src/Shared/AWS/AWSSemanticConventions.Base.cs index 0d24dc55d8..0305e9a1dd 100644 --- a/src/Shared/AWS/AWSSemanticConventions.Base.cs +++ b/src/Shared/AWS/AWSSemanticConventions.Base.cs @@ -27,7 +27,7 @@ internal partial class AWSSemanticConventions /// Defines all Semantic Conventions used by AWS extension projects. /// /// All values default to string.Empty and are then is only defined - /// in the first version specific class (ie ) + /// in the first version specific class (ie ) /// to use it. This helps ensure the attribute doesn't get used if the user has specified /// a specific . /// @@ -35,7 +35,7 @@ internal partial class AWSSemanticConventions /// private abstract class AWSSemanticConventionsBase { - // CLOUD Attributes + #region CLOUD Attributes /// /// The cloud account ID the resource is assigned to. /// @@ -153,8 +153,9 @@ private abstract class AWSSemanticConventionsBase /// CloudAttributes.CloudProviderValues.Aws /// public virtual string CloudProviderValuesAws => string.Empty; + #endregion - // CONTAINER Attributes + #region CONTAINER Attributes /// /// Container ID. Usually a UUID, as for example used to identify Docker containers. The UUID might be abbreviated. @@ -163,8 +164,9 @@ private abstract class AWSSemanticConventionsBase /// ContainerAttributes.AttributeContainerId /// public virtual string AttributeContainerID => string.Empty; + #endregion - // DB Attributes + #region DB Attributes /// /// The database management system (DBMS) product as identified by the client instrumentation. @@ -185,8 +187,9 @@ private abstract class AWSSemanticConventionsBase /// DbAttributes.DbSystemValues.Dynamodb /// public virtual string AttributeDynamoDb => string.Empty; + #endregion - // AWS Attributes + #region AWS Attributes /// /// The Amazon Resource Name (ARN) of an ECS container instance. @@ -331,7 +334,9 @@ private abstract class AWSSemanticConventionsBase /// public virtual string AttributeAWSBedrock => string.Empty; - // FAAS Attributes + #endregion + + #region FAAS Attributes /// /// Cloud provider-specific native identifier of the monitored cloud resource (e.g. an ARN on AWS, a fully qualified resource ID on Azure, a full resource name on GCP). @@ -434,8 +439,9 @@ private abstract class AWSSemanticConventionsBase /// FaasAttributes.AttributeFaasColdstart /// public virtual string AttributeFaasColdStart => string.Empty; + #endregion - // GEN AI Attributes + #region GEN AI Attributes /// /// The name of the GenAI model a request is being made to. /// @@ -463,7 +469,9 @@ private abstract class AWSSemanticConventionsBase /// public virtual string AttributeGenAiSystem => string.Empty; - // HOST Attributes + #endregion + + #region HOST Attributes /// /// Unique host ID. For Cloud, this must be the instance_id assigned by the cloud provider. For non-containerized systems, this should be the machine-id. See the table below for the sources to use to determine the machine-id based on operating system. @@ -489,7 +497,9 @@ private abstract class AWSSemanticConventionsBase /// public virtual string AttributeHostName => string.Empty; - // HTTP Attributes + #endregion + + #region HTTP Attributes /// /// Deprecated, use http.response.status_code instead. @@ -534,7 +544,7 @@ private abstract class AWSSemanticConventionsBase /// [Obsolete("Replaced by http.request.method.")] public virtual string AttributeHttpMethod => string.Empty; - + /// /// HTTP request method. /// @@ -559,7 +569,9 @@ private abstract class AWSSemanticConventionsBase /// public virtual string AttributeHttpRequestMethod => string.Empty; - // NET Attributes + #endregion + + #region NET Attributes /// /// Deprecated, use server.address. @@ -579,7 +591,9 @@ private abstract class AWSSemanticConventionsBase [Obsolete("Replaced by server.port.")] public virtual string AttributeNetHostPort => string.Empty; - // SERVER Attributes + #endregion + + #region SERVER Attributes /// /// Server domain name if available without reverse DNS lookup; otherwise, IP address or Unix domain socket name. @@ -613,7 +627,9 @@ private abstract class AWSSemanticConventionsBase /// public virtual string AttributeK8SClusterName => string.Empty; - // SERVICE Attributes + #endregion + + #region SERVICE Attributes /// /// Logical name of the service. @@ -686,7 +702,9 @@ private abstract class AWSSemanticConventionsBase /// public virtual string ServiceNameValuesAwsElasticBeanstalk => string.Empty; - // URL Attributes + #endregion + + #region URL Attributes /// /// The URI path component. @@ -704,6 +722,20 @@ private abstract class AWSSemanticConventionsBase /// /// /// Sensitive content provided in url.query SHOULD be scrubbed when instrumentations can identify it. + ///

+ /// + /// Query string values for the following keys SHOULD be redacted by default and replaced by the value REDACTED: + ///

+ ///

+ /// This list is subject to change over time. + ///

+ /// When a query string value is redacted, the query string key SHOULD still be preserved, e.g. + /// q=OpenTelemetry&sig=REDACTED. /// /// /// UrlAttributes.AttributeUrlQuery @@ -717,5 +749,7 @@ private abstract class AWSSemanticConventionsBase /// UrlAttributes.AttributeUrlScheme /// public virtual string AttributeUrlScheme => string.Empty; + + #endregion } } diff --git a/src/Shared/AWS/AWSSemanticConventions.v1.27.0.cs b/src/Shared/AWS/AWSSemanticConventions.Legacy.cs similarity index 93% rename from src/Shared/AWS/AWSSemanticConventions.v1.27.0.cs rename to src/Shared/AWS/AWSSemanticConventions.Legacy.cs index ba0c416d60..e391632c2b 100644 --- a/src/Shared/AWS/AWSSemanticConventions.v1.27.0.cs +++ b/src/Shared/AWS/AWSSemanticConventions.Legacy.cs @@ -13,16 +13,14 @@ namespace OpenTelemetry.AWS; internal partial class AWSSemanticConventions { ///

- /// Open Telemetry Semantic Conventions as of the 1.27.0 - /// https://github.com/open-telemetry/semantic-conventions/releases/tag/v1.27.0. + /// The Open Telemetry Semantic Conventions used by OpenTelemetry.*.AWS libraries as of + /// version 1.10.0-beta and represents a mixture of Semantic Conventions as these libraries had + /// not yet been upgraded to use a specific Semantic Convention version. /// /// - /// This is the first version to include Semantic Conventions defined in this manner, so it - /// defines string constants for all attributes. - /// /// Future version specific convention classes will only need to define new or changed attributes. /// - private class AWSSemanticConventions_V1_27_0 : AWSSemanticConventionsBase + private class AWSSemanticConventionsLegacy : AWSSemanticConventionsBase { // CLOUD Attributes public override string AttributeCloudAccountID => "cloud.account.id"; diff --git a/src/Shared/AWS/AWSSemanticConventions.cs b/src/Shared/AWS/AWSSemanticConventions.cs index e88774e4ec..75979a6b3d 100644 --- a/src/Shared/AWS/AWSSemanticConventions.cs +++ b/src/Shared/AWS/AWSSemanticConventions.cs @@ -64,9 +64,9 @@ internal partial class AWSSemanticConventions ///
/// /// Per SemanticConventionVersion, default should stay as - /// until next major version bump. + /// until next major version bump. /// - internal const SemanticConventionVersion DefaultSemanticConventionVersion = SemanticConventionVersion.V1_27_0_Experimental; + internal const SemanticConventionVersion DefaultSemanticConventionVersion = SemanticConventionVersion.V1_28_0_Experimental; private readonly SemanticConventionVersion semanticConventionVersion; @@ -485,8 +485,8 @@ private AWSSemanticConventionsBase GetSemanticConventionVersion() case SemanticConventionVersion.V1_29_0_Experimental: return new AWSSemanticConventions_V1_29_0(); - case SemanticConventionVersion.V1_27_0_Experimental: - return new AWSSemanticConventions_V1_27_0(); + case SemanticConventionVersion.V1_28_0_Experimental: + return new AWSSemanticConventions_V1_28_0(); default: throw new InvalidEnumArgumentException( diff --git a/src/Shared/AWS/AWSSemanticConventions.v1.28.0.cs b/src/Shared/AWS/AWSSemanticConventions.v1.28.0.cs new file mode 100644 index 0000000000..5242064a7a --- /dev/null +++ b/src/Shared/AWS/AWSSemanticConventions.v1.28.0.cs @@ -0,0 +1,55 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +namespace OpenTelemetry.AWS; + +// disable Style Warnings to improve readability of this specific file. +#pragma warning disable SA1124 +#pragma warning disable SA1005 +#pragma warning disable SA1514 +#pragma warning disable SA1201 +#pragma warning disable SA1516 + +internal partial class AWSSemanticConventions +{ + /// + /// Open Telemetry Semantic Conventions as of 1.28.0: + /// https://github.com/open-telemetry/semantic-conventions/releases/tag/v1.28.0. + /// + private class AWSSemanticConventions_V1_28_0 : AWSSemanticConventionsLegacy + { + public override string AttributeAWSDynamoTableName => "aws.dynamodb.table_names"; + + // FAAS Attributes + public override string AttributeFaasID => "cloud.resource_id"; + public override string AttributeFaasExecution => "faas.invocation_id"; + + // HTTP Attributes + [Obsolete("Replaced by http.response.status_code.")] + public override string AttributeHttpStatusCode => string.Empty; // value no longer written + [Obsolete("Replaced by url.scheme instead.")] + public override string AttributeHttpScheme => string.Empty; // value no longer written + + [Obsolete("Split to url.path and `url.query.")] + public override string AttributeHttpTarget => string.Empty; // value no longer written + [Obsolete("Replaced by http.request.method.")] + public override string AttributeHttpMethod => string.Empty; // value no longer written + public override string AttributeHttpResponseStatusCode => "http.response.status_code"; + public override string AttributeHttpRequestMethod => "http.request.method"; + + // NET Attributes + [Obsolete("Replaced by server.address.")] + public override string AttributeNetHostName => string.Empty; // value no longer written + [Obsolete("Replaced by server.port.")] + public override string AttributeNetHostPort => string.Empty; // value no longer written + + // SERVER Attributes + public override string AttributeServerAddress => "server.address"; + public override string AttributeServerPort => "server.port"; + + // URL Attributes + public override string AttributeUrlPath => "url.path"; + public override string AttributeUrlQuery => "url.query"; + public override string AttributeUrlScheme => "url.scheme"; + } +} diff --git a/src/Shared/AWS/AWSSemanticConventions.v1.29.0.cs b/src/Shared/AWS/AWSSemanticConventions.v1.29.0.cs index 15e6d055e6..1b989e1119 100644 --- a/src/Shared/AWS/AWSSemanticConventions.v1.29.0.cs +++ b/src/Shared/AWS/AWSSemanticConventions.v1.29.0.cs @@ -16,42 +16,9 @@ internal partial class AWSSemanticConventions /// Open Telemetry Semantic Conventions as of 1.29.0: /// https://github.com/open-telemetry/semantic-conventions/releases/tag/v1.29.0. ///
- private class AWSSemanticConventions_V1_29_0 : AWSSemanticConventions_V1_27_0 + private class AWSSemanticConventions_V1_29_0 : AWSSemanticConventions_V1_28_0 { // AWS Attributes public override string AttributeAWSBedrock => "aws.bedrock"; - public override string AttributeAWSDynamoTableName => "aws.dynamodb.table_names"; - - // FAAS Attributes - public override string AttributeFaasID => "cloud.resource_id"; - public override string AttributeFaasExecution => "faas.invocation_id"; - - // HTTP Attributes - [Obsolete("Replaced by http.response.status_code.")] - public override string AttributeHttpStatusCode => string.Empty; // value no longer written - [Obsolete("Replaced by url.scheme instead.")] - public override string AttributeHttpScheme => string.Empty; // value no longer written - - [Obsolete("Split to url.path and `url.query.")] - public override string AttributeHttpTarget => string.Empty; // value no longer written - [Obsolete("Replaced by http.request.method.")] - public override string AttributeHttpMethod => string.Empty; // value no longer written - public override string AttributeHttpResponseStatusCode => "http.response.status_code"; - public override string AttributeHttpRequestMethod => "http.request.method"; - - // NET Attributes - [Obsolete("Replaced by server.address.")] - public override string AttributeNetHostName => string.Empty; // value no longer written - [Obsolete("Replaced by server.port.")] - public override string AttributeNetHostPort => string.Empty; // value no longer written - - // SERVER Attributes - public override string AttributeServerAddress => "server.address"; - public override string AttributeServerPort => "server.port"; - - // URL Attributes - public override string AttributeUrlPath => "url.path"; - public override string AttributeUrlQuery => "url.query"; - public override string AttributeUrlScheme => "url.scheme"; } } diff --git a/src/Shared/AWS/SemanticConventionVersion.cs b/src/Shared/AWS/SemanticConventionVersion.cs index 4e6a0a2704..0c20c1e53e 100644 --- a/src/Shared/AWS/SemanticConventionVersion.cs +++ b/src/Shared/AWS/SemanticConventionVersion.cs @@ -37,7 +37,7 @@ namespace OpenTelemetry.Resources.AWS; /// version. /// /// -/// The default will remain as until the next major version +/// The default will remain as until the next major version /// bump. /// /// @@ -74,11 +74,11 @@ public enum SemanticConventionVersion Latest = 0, /// - /// Pin to the specific state of all Semantic Conventions as of the 1.27.0 + /// Pin to the specific state of all Semantic Conventions as of the 1.28.0 /// release. See: - /// https://github.com/open-telemetry/semantic-conventions/releases/tag/v1.27.0. + /// https://github.com/open-telemetry/semantic-conventions/releases/tag/v1.28.0. /// - V1_27_0_Experimental = 1, + V1_28_0_Experimental = 1, /// /// Pin to the specific state of all Semantic Conventions as of the 1.29.0 diff --git a/test/OpenTelemetry.Instrumentation.AWS.Tests/AWSClientInstrumentationOptionsTests.cs b/test/OpenTelemetry.Instrumentation.AWS.Tests/AWSClientInstrumentationOptionsTests.cs new file mode 100644 index 0000000000..29208c5548 --- /dev/null +++ b/test/OpenTelemetry.Instrumentation.AWS.Tests/AWSClientInstrumentationOptionsTests.cs @@ -0,0 +1,92 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +using System.Diagnostics; +using Amazon; +using Amazon.BedrockRuntime; +using Amazon.BedrockRuntime.Model; +using Amazon.Runtime; +using Amazon.Runtime.Internal; +using OpenTelemetry.Instrumentation.AWS.Implementation; +using OpenTelemetry.Instrumentation.AWS.Tests.Tools; +using OpenTelemetry.Trace; +using Xunit; + +namespace OpenTelemetry.Instrumentation.AWS.Tests; + +/// +/// Tests for AWS Semantic Conversion via +/// . +/// These tests verify that the switching mechanism works rather than +/// explicitly verifying what the semantic convention should be. +/// +public sealed class AWSClientInstrumentationOptionsTests +{ + [Fact] + public void CanUseSemanticConvention_V1_28_0() + { + var semanticVersion = SemanticConventionVersion.V1_28_0_Experimental; + + var tags = this.GetActivityTags(semanticVersion); + + // GenAI System attribute differs slightly between 1.28 and 1.29 + Assert.Equal("aws_bedrock", tags["gen_ai.system"]); + } + + [Fact] + public void CanUseSemanticConvention_V1_29_0() + { + var semanticVersion = SemanticConventionVersion.V1_29_0_Experimental; + + var tags = this.GetActivityTags(semanticVersion); + + // GenAI System attribute differs slightly between 1.28 and 1.29 + Assert.Equal("aws.bedrock", tags["gen_ai.system"]); + } + + private Dictionary GetActivityTags(SemanticConventionVersion semVersion) + { + var exportedItems = new List(); + + var parent = new Activity("parent").Start(); + var requestId = @"fakerequ-esti-dfak-ereq-uestidfakere"; + + try + { + using (Sdk.CreateTracerProviderBuilder() + .AddXRayTraceId() + .SetSampler(new AlwaysOnSampler()) + .AddAWSInstrumentation(o => + { + o.SemanticConventionVersion = semVersion; + }) + .AddInMemoryExporter(exportedItems) + .Build()) + { + var bedrockruntime = new AmazonBedrockRuntimeClient(new AnonymousAWSCredentials(), RegionEndpoint.USEast1); + var dummyResponse = "{}"; + CustomResponses.SetResponse(bedrockruntime, dummyResponse, requestId, true); + var invokeModelRequest = new InvokeModelRequest {ModelId = "amazon.titan-text-express-v1"}; + +#if NETFRAMEWORK + var response = bedrockruntime.InvokeModel(invokeModelRequest); +#else + var response = bedrockruntime.InvokeModelAsync(invokeModelRequest).Result; +#endif + } + } + finally + { + // unregister the AWS Runtime Pipeline Customizer, or it will conflict + // with the next test run + RuntimePipelineCustomizerRegistry.Instance.Deregister(AWSTracingPipelineCustomizer.UniqueName); + } + + return + exportedItems + .FirstOrDefault(a => a.DisplayName == "Bedrock Runtime.InvokeModel") + ?.Tags + .ToDictionary(x => x.Key, x => x.Value) + ?? new Dictionary(); + } +} diff --git a/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/Implementation/AWSLambdaInstrumentationOptionsTests.cs b/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/Implementation/AWSLambdaInstrumentationOptionsTests.cs index 06e68507e3..1311d1e1c5 100644 --- a/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/Implementation/AWSLambdaInstrumentationOptionsTests.cs +++ b/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/Implementation/AWSLambdaInstrumentationOptionsTests.cs @@ -22,9 +22,9 @@ namespace OpenTelemetry.Instrumentation.AWSLambda.Tests.Implementation; public sealed class AWSLambdaInstrumentationOptionsTests { [Fact] - public void CanUseSemanticConvention_V1_27_0() + public void CanUseSemanticConvention_V1_28_0() { - var semanticVersion = SemanticConventionVersion.V1_27_0_Experimental; + var semanticVersion = SemanticConventionVersion.V1_28_0_Experimental; var expectedTags = new List {