diff --git a/eng/Packages.Data.props b/eng/Packages.Data.props
index 10633975fd4d..4898fe1995fd 100644
--- a/eng/Packages.Data.props
+++ b/eng/Packages.Data.props
@@ -180,11 +180,11 @@
-
-
-
-
-
+
+
+
+
+
@@ -373,12 +373,12 @@
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/CHANGELOG.md b/sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/CHANGELOG.md
index 345edc891f42..8968c75a111c 100644
--- a/sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/CHANGELOG.md
+++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/CHANGELOG.md
@@ -10,6 +10,21 @@
### Other Changes
+* Update OpenTelemetry dependencies
+ ([#48574](https://github.com/Azure/azure-sdk-for-net/pull/48574))
+ - OpenTelemetry 1.11.2
+ - OpenTelemetry.Extensions.Hosting 1.11.2
+ - OpenTelemetry.Instrumentation.AspNetCore 1.11.1
+ - OpenTelemetry.Instrumentation.Http 1.11.1
+
+* Updated the code of vendored instrumentation library `OpenTelemetry.Instrumentation.SqlClient` from the OpenTelemetry .NET contrib repository.
+ Code has been updated to [1.11.0-beta.2](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/tree/Instrumentation.SqlClient-1.11.0-beta.2/src/OpenTelemetry.Instrumentation.SqlClient).
+ ([#48608](https://github.com/Azure/azure-sdk-for-net/pull/48608))
+
+* Updated the code of vendored resource detector library `OpenTelemetry.Resources.Azure` from the OpenTelemetry .NET contrib repository.
+ Code has been updated to [1.11.0-beta.2](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/tree/Resources.Azure-1.11.0-beta.2/src/OpenTelemetry.Resources.Azure).
+ ([#48608](https://github.com/Azure/azure-sdk-for-net/pull/48608))
+
## 1.3.0-beta.2 (2024-10-11)
### Bugs Fixed
diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/src/Azure.Monitor.OpenTelemetry.AspNetCore.csproj b/sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/src/Azure.Monitor.OpenTelemetry.AspNetCore.csproj
index d377f9c299b1..45441973b959 100644
--- a/sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/src/Azure.Monitor.OpenTelemetry.AspNetCore.csproj
+++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/src/Azure.Monitor.OpenTelemetry.AspNetCore.csproj
@@ -23,10 +23,10 @@
-
+
-
+
diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/src/Vendoring/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlActivitySourceHelper.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/src/Vendoring/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlActivitySourceHelper.cs
index f089caf08d9b..b1ad4815ab36 100644
--- a/sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/src/Vendoring/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlActivitySourceHelper.cs
+++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/src/Vendoring/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlActivitySourceHelper.cs
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
using System.Diagnostics;
+using System.Diagnostics.Metrics;
using System.Reflection;
using OpenTelemetry.Internal;
using OpenTelemetry.Trace;
@@ -20,10 +21,103 @@ internal sealed class SqlActivitySourceHelper
public static readonly AssemblyName AssemblyName = Assembly.GetName();
public static readonly string ActivitySourceName = AssemblyName.Name!;
public static readonly ActivitySource ActivitySource = new(ActivitySourceName, Assembly.GetPackageVersion());
- public static readonly string ActivityName = ActivitySourceName + ".Execute";
- public static readonly IEnumerable> CreationTags = new[]
+ public static readonly string MeterName = AssemblyName.Name!;
+ public static readonly Meter Meter = new(MeterName, Assembly.GetPackageVersion());
+
+ public static readonly Histogram DbClientOperationDuration = Meter.CreateHistogram(
+ "db.client.operation.duration",
+ unit: "s",
+ description: "Duration of database client operations.",
+ advice: new InstrumentAdvice { HistogramBucketBoundaries = [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5, 10] });
+
+ internal static readonly string[] SharedTagNames =
+ [
+ SemanticConventions.AttributeDbSystem,
+ SemanticConventions.AttributeDbCollectionName,
+ SemanticConventions.AttributeDbNamespace,
+ SemanticConventions.AttributeDbResponseStatusCode,
+ SemanticConventions.AttributeDbOperationName,
+ SemanticConventions.AttributeErrorType,
+ SemanticConventions.AttributeServerPort,
+ SemanticConventions.AttributeServerAddress,
+ ];
+
+ public static TagList GetTagListFromConnectionInfo(string? dataSource, string? databaseName, SqlClientTraceInstrumentationOptions options, out string activityName)
+ {
+ activityName = MicrosoftSqlServerDatabaseSystemName;
+
+ var tags = new TagList
+ {
+ { SemanticConventions.AttributeDbSystem, MicrosoftSqlServerDatabaseSystemName },
+ };
+
+ if (dataSource != null)
+ {
+ var connectionDetails = SqlConnectionDetails.ParseFromDataSource(dataSource);
+
+ if (options.EmitOldAttributes && !string.IsNullOrEmpty(databaseName))
+ {
+ tags.Add(SemanticConventions.AttributeDbName, databaseName);
+ activityName = databaseName!;
+ }
+
+ if (options.EmitNewAttributes && !string.IsNullOrEmpty(databaseName))
+ {
+ var dbNamespace = !string.IsNullOrEmpty(connectionDetails.InstanceName)
+ ? $"{connectionDetails.InstanceName}.{databaseName}" // TODO: Refactor SqlConnectionDetails to include database to avoid string allocation here.
+ : databaseName!;
+ tags.Add(SemanticConventions.AttributeDbNamespace, dbNamespace);
+ activityName = dbNamespace;
+ }
+
+ var serverAddress = connectionDetails.ServerHostName ?? connectionDetails.ServerIpAddress;
+ if (!string.IsNullOrEmpty(serverAddress))
+ {
+ tags.Add(SemanticConventions.AttributeServerAddress, serverAddress);
+ if (connectionDetails.Port.HasValue)
+ {
+ tags.Add(SemanticConventions.AttributeServerPort, connectionDetails.Port);
+ }
+
+ if (activityName == MicrosoftSqlServerDatabaseSystemName)
+ {
+ activityName = connectionDetails.Port.HasValue
+ ? $"{serverAddress}:{connectionDetails.Port}" // TODO: Another opportunity to refactor SqlConnectionDetails
+ : serverAddress!;
+ }
+ }
+
+ if (options.EmitOldAttributes && !string.IsNullOrEmpty(connectionDetails.InstanceName))
+ {
+ tags.Add(SemanticConventions.AttributeDbMsSqlInstanceName, connectionDetails.InstanceName);
+ }
+ }
+ else if (!string.IsNullOrEmpty(databaseName))
+ {
+ if (options.EmitNewAttributes)
+ {
+ tags.Add(SemanticConventions.AttributeDbNamespace, databaseName);
+ }
+
+ if (options.EmitOldAttributes)
+ {
+ tags.Add(SemanticConventions.AttributeDbName, databaseName);
+ }
+
+ activityName = databaseName!;
+ }
+
+ return tags;
+ }
+
+ internal static double CalculateDurationFromTimestamp(long begin, long? end = null)
{
- new KeyValuePair(SemanticConventions.AttributeDbSystem, MicrosoftSqlServerDatabaseSystemName),
- };
+ end ??= Stopwatch.GetTimestamp();
+ var timestampToTicks = TimeSpan.TicksPerSecond / (double)Stopwatch.Frequency;
+ var delta = end - begin;
+ var ticks = (long)(timestampToTicks * delta);
+ var duration = new TimeSpan(ticks);
+ return duration.TotalSeconds;
+ }
}
diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/src/Vendoring/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlClientDiagnosticListener.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/src/Vendoring/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlClientDiagnosticListener.cs
index bf3b77c5999a..c990695a5434 100644
--- a/sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/src/Vendoring/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlClientDiagnosticListener.cs
+++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/src/Vendoring/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlClientDiagnosticListener.cs
@@ -4,14 +4,15 @@
#if !NETFRAMEWORK
using System.Data;
using System.Diagnostics;
-using OpenTelemetry.Trace;
-#if NET6_0_OR_GREATER
+#if NET
using System.Diagnostics.CodeAnalysis;
#endif
+using System.Globalization;
+using OpenTelemetry.Trace;
namespace OpenTelemetry.Instrumentation.SqlClient.Implementation;
-#if NET6_0_OR_GREATER
+#if NET
[RequiresUnreferencedCode(SqlClientInstrumentation.SqlClientTrimmingUnsupportedMessage)]
#endif
internal sealed class SqlClientDiagnosticListener : ListenerHandler
@@ -27,47 +28,57 @@ internal sealed class SqlClientDiagnosticListener : ListenerHandler
private readonly PropertyFetcher