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

WIP [AzureMonitor] update vendored OTel libraries #48608

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3476692
upgrade OTel to v1.10 and fix api conflicts
TimothyMothra Nov 14, 2024
2df99e5
bugfix: should not create exception telemetry when message is empty
TimothyMothra Nov 14, 2024
71f7664
test bug: fixing bug with requestData.Success
TimothyMothra Nov 14, 2024
2b01dfe
adding support for net9.0 to csproj and global.json
TimothyMothra Nov 15, 2024
1186e54
upgrade OTel to v1.10 and fix api conflicts
TimothyMothra Nov 14, 2024
2a56b3d
bugfix: should not create exception telemetry when message is empty
TimothyMothra Nov 14, 2024
406b910
test bug: fixing bug with requestData.Success
TimothyMothra Nov 14, 2024
83b2fc7
adding support for net9.0 to csproj and global.json
TimothyMothra Nov 15, 2024
07de249
merge main
TimothyMothra Mar 5, 2025
716048f
merge main and resolve conflicts
TimothyMothra Mar 5, 2025
4f04a2d
cleanup
TimothyMothra Mar 5, 2025
3480ef3
bump version 1.11.*
TimothyMothra Mar 5, 2025
05ae548
fix for Http
TimothyMothra Mar 5, 2025
eb22143
changelogs
TimothyMothra Mar 5, 2025
bff190d
refresh vendored code
TimothyMothra Mar 5, 2025
fd7df7e
breaking change
TimothyMothra Mar 5, 2025
8d82804
hack fixes for conflicts
TimothyMothra Mar 5, 2025
db3bbd0
changelog placeholder
TimothyMothra Mar 5, 2025
fd2797f
merge main
TimothyMothra Mar 6, 2025
7c8e672
changelog
TimothyMothra Mar 6, 2025
edf6604
fix unit tests
TimothyMothra Mar 6, 2025
cd4fc8f
comment
TimothyMothra Mar 6, 2025
08acdac
Merge branch 'tilee/202503_upgrade_otel1.11' into tilee/202503_upgrad…
TimothyMothra Mar 6, 2025
bc08104
changelog
TimothyMothra Mar 6, 2025
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
22 changes: 11 additions & 11 deletions eng/Packages.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@

<ItemGroup Condition="$(MSBuildProjectName.StartsWith('Azure.Monitor.OpenTelemetry'))">
<!-- OpenTelemetry dependency approved for Azure.Monitor.OpenTelemetry.Exporter package only -->
<PackageReference Update="OpenTelemetry" Version="1.9.0" />
<PackageReference Update="OpenTelemetry.Extensions.Hosting" Version="1.9.0" />
<PackageReference Update="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0" />
<PackageReference Update="OpenTelemetry.Instrumentation.Http" Version="1.9.0" />
<PackageReference Update="OpenTelemetry.PersistentStorage.FileSystem" Version="1.0.0" />
<PackageReference Update="OpenTelemetry" Version="1.11.2" />
<PackageReference Update="OpenTelemetry.Extensions.Hosting" Version="1.11.2" />
<PackageReference Update="OpenTelemetry.Instrumentation.AspNetCore" Version="1.11.1" />
<PackageReference Update="OpenTelemetry.Instrumentation.Http" Version="1.11.1" />
<PackageReference Update="OpenTelemetry.PersistentStorage.FileSystem" Version="1.0.1" />
<PackageReference Update="Microsoft.AspNetCore.Http.Abstractions" Version="[2.1.1,6.0)" />
<PackageReference Update="Microsoft.AspNetCore.Http.Features" Version="[2.1.1,6.0)" />
</ItemGroup>
Expand Down Expand Up @@ -373,12 +373,12 @@
<PackageReference Update="NSubstitute" Version="3.1.0" />
<PackageReference Update="NUnit" Version="3.13.2" />
<PackageReference Update="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Update="OpenTelemetry" Version="1.9.0" />
<PackageReference Update="OpenTelemetry.Exporter.Console" Version="1.9.0" />
<PackageReference Update="OpenTelemetry.Exporter.InMemory" Version="1.9.0" />
<PackageReference Update="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0" />
<PackageReference Update="OpenTelemetry.Instrumentation.Http" Version="1.9.0" />
<PackageReference Update="OpenTelemetry.Instrumentation.SqlClient" Version="1.9.0-beta.1" />
<PackageReference Update="OpenTelemetry" Version="1.11.2" />
<PackageReference Update="OpenTelemetry.Exporter.Console" Version="1.11.2" />
<PackageReference Update="OpenTelemetry.Exporter.InMemory" Version="1.11.2" />
<PackageReference Update="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.11.2" />
<PackageReference Update="OpenTelemetry.Instrumentation.Http" Version="1.11.1" />
<PackageReference Update="OpenTelemetry.Instrumentation.SqlClient" Version="1.11.0-beta.2" />
<PackageReference Update="Polly" Version="7.1.0" />
<PackageReference Update="Polly.Contrib.WaitAndRetry" Version="1.1.1" />
<PackageReference Update="Portable.BouncyCastle" Version="1.9.0" />
Expand Down
15 changes: 15 additions & 0 deletions sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
<!-- Depending on monthly deliverables, we may switch between PackageReference or ProjectReference. Keeping both here to make the switch easier. -->

<!-- FOR PUBLIC RELEASES, MUST USE PackageReference. THIS REQUIRES A STAGGERED RELEASE IF SHIPPING A NEW EXPORTER. -->
<PackageReference Include="Azure.Monitor.OpenTelemetry.Exporter" />
<!--<PackageReference Include="Azure.Monitor.OpenTelemetry.Exporter" />-->

<!-- FOR LOCAL DEV, ProjectReference IS PREFERRED. -->
<!--<ProjectReference Include="..\..\Azure.Monitor.OpenTelemetry.Exporter\src\Azure.Monitor.OpenTelemetry.Exporter.csproj" />-->
<ProjectReference Include="..\..\Azure.Monitor.OpenTelemetry.Exporter\src\Azure.Monitor.OpenTelemetry.Exporter.csproj" />
</ItemGroup>

<!-- Shared sources from Azure.Core -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<KeyValuePair<string, object?>> CreationTags = new[]
public static readonly string MeterName = AssemblyName.Name!;
public static readonly Meter Meter = new(MeterName, Assembly.GetPackageVersion());

public static readonly Histogram<double> DbClientOperationDuration = Meter.CreateHistogram(
"db.client.operation.duration",
unit: "s",
description: "Duration of database client operations.",
advice: new InstrumentAdvice<double> { 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<string, object?>(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;
}
}
Loading