Skip to content
Merged
Show file tree
Hide file tree
Changes from 63 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
0521dfa
Introduce OpenTelemetry.DependencyInjection and refactor SDK.
CodeBlanch Nov 18, 2022
59c1dc3
Update SqlClient instrumentation to use DependencyInjection package.
CodeBlanch Nov 18, 2022
338a73f
Tweak.
CodeBlanch Nov 18, 2022
d80bfe9
Merge from main.
CodeBlanch Nov 28, 2022
641fd3f
Manual merge fixes.
CodeBlanch Nov 28, 2022
2642179
Some refactoring.
CodeBlanch Nov 29, 2022
7486cc2
Renames.
CodeBlanch Nov 29, 2022
55c1e62
Bug fixes and refactoring.
CodeBlanch Nov 29, 2022
18e5a61
Cleanup and docs.
CodeBlanch Nov 30, 2022
535d8fe
More updates.
CodeBlanch Nov 30, 2022
a735a53
More cleanup.
CodeBlanch Nov 30, 2022
d2f237c
API updates.
CodeBlanch Nov 30, 2022
119514d
Namespace tweaks.
CodeBlanch Dec 1, 2022
cde4679
Refactoring and API changes.
CodeBlanch Dec 2, 2022
754a882
Example tweaks.
CodeBlanch Dec 2, 2022
a3b3bcd
Example cleanup.
CodeBlanch Dec 2, 2022
adf1a00
XML doc updates.
CodeBlanch Dec 2, 2022
6022f84
XML doc updates.
CodeBlanch Dec 2, 2022
1c1bf38
Bug fix.
CodeBlanch Dec 2, 2022
9cf302f
Test fixes.
CodeBlanch Dec 2, 2022
3a75954
Example fixup.
CodeBlanch Dec 2, 2022
6e29c32
Test fixup.
CodeBlanch Dec 2, 2022
bdff2bb
Test fixup.
CodeBlanch Dec 2, 2022
1274793
Example fixup.
CodeBlanch Dec 2, 2022
7f9b9a0
Test fixup.
CodeBlanch Dec 2, 2022
09ef294
Test fixup.
CodeBlanch Dec 2, 2022
c9f33ab
Test fixup.
CodeBlanch Dec 2, 2022
5a38dc0
Merge from main.
CodeBlanch Dec 2, 2022
3e89e15
CHANGELOG patch.
CodeBlanch Dec 2, 2022
d5e4be8
Add test project.
CodeBlanch Dec 2, 2022
7dfdb13
Cleanup.
CodeBlanch Dec 2, 2022
f972732
Added configure tests.
CodeBlanch Dec 2, 2022
adb8d89
MeterProviderBuilder extensions tests.
CodeBlanch Dec 2, 2022
311831e
TracerProviderBuilder extensions tests
CodeBlanch Dec 2, 2022
5a40ee5
Some README content.
CodeBlanch Dec 2, 2022
cf70bf4
CHANGELOG patch.
CodeBlanch Dec 2, 2022
339e28d
Doc updates.
CodeBlanch Dec 2, 2022
2869cde
Merge branch 'dependencyinjection-package-refactor' into sql-client-o…
CodeBlanch Dec 2, 2022
df95a5a
Example code fixes.
CodeBlanch Dec 2, 2022
99c0f84
Doc updates.
CodeBlanch Dec 2, 2022
8d895e9
Doc updates.
CodeBlanch Dec 2, 2022
fae1e39
Doc updates and cleanup.
CodeBlanch Dec 2, 2022
ae660bf
Doc updates.
CodeBlanch Dec 2, 2022
a6613f4
Skip ApiCompat on new project.
CodeBlanch Dec 2, 2022
47d6d87
API tweaks.
CodeBlanch Dec 3, 2022
164c0f1
Merge branch 'main' into dependencyinjection-package-refactor
CodeBlanch Dec 3, 2022
6015b06
Test fixes.
CodeBlanch Dec 3, 2022
e85f8ae
XML doc improvements.
CodeBlanch Dec 3, 2022
de72219
Tweaks.
CodeBlanch Dec 5, 2022
f9afd08
Merge from main.
CodeBlanch Dec 8, 2022
752ad56
Project file updates.
CodeBlanch Dec 8, 2022
b1848c0
Test fix.
CodeBlanch Dec 8, 2022
1b8c894
Project rename.
CodeBlanch Dec 8, 2022
b407cec
Merge branch 'dependencyinjection-package-refactor' into sql-client-o…
CodeBlanch Dec 8, 2022
1d1e79e
Updated for new project name.
CodeBlanch Dec 8, 2022
6b2971f
Merge from main.
CodeBlanch Dec 8, 2022
91d6784
Manual fixes for merge from main.
CodeBlanch Dec 8, 2022
d95757e
More manual fixes for merge from main.
CodeBlanch Dec 8, 2022
e5079e2
Merge.
CodeBlanch Dec 8, 2022
2329403
Merge remote-tracking branch 'upstream/main' into sql-client-options
CodeBlanch Dec 8, 2022
06d1dc5
Updates.
CodeBlanch Dec 8, 2022
8c09e31
Unit test.
CodeBlanch Dec 8, 2022
b1c9a31
CHANGELOG patch.
CodeBlanch Dec 9, 2022
de18f74
Merge branch 'main' into sql-client-options
CodeBlanch Dec 9, 2022
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
Expand Up @@ -13,4 +13,6 @@ OpenTelemetry.Instrumentation.SqlClient.SqlClientInstrumentationOptions.SetDbSta
OpenTelemetry.Instrumentation.SqlClient.SqlClientInstrumentationOptions.SetDbStatementForText.set -> void
OpenTelemetry.Instrumentation.SqlClient.SqlClientInstrumentationOptions.SqlClientInstrumentationOptions() -> void
OpenTelemetry.Trace.TracerProviderBuilderExtensions
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddSqlClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<OpenTelemetry.Instrumentation.SqlClient.SqlClientInstrumentationOptions> configureSqlClientInstrumentationOptions = null) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddSqlClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddSqlClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, string name, System.Action<OpenTelemetry.Instrumentation.SqlClient.SqlClientInstrumentationOptions> configureSqlClientInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddSqlClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<OpenTelemetry.Instrumentation.SqlClient.SqlClientInstrumentationOptions> configureSqlClientInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ OpenTelemetry.Instrumentation.SqlClient.SqlClientInstrumentationOptions.SetDbSta
OpenTelemetry.Instrumentation.SqlClient.SqlClientInstrumentationOptions.SetDbStatementForText.set -> void
OpenTelemetry.Instrumentation.SqlClient.SqlClientInstrumentationOptions.SqlClientInstrumentationOptions() -> void
OpenTelemetry.Trace.TracerProviderBuilderExtensions
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddSqlClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<OpenTelemetry.Instrumentation.SqlClient.SqlClientInstrumentationOptions> configureSqlClientInstrumentationOptions = null) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddSqlClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddSqlClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, string name, System.Action<OpenTelemetry.Instrumentation.SqlClient.SqlClientInstrumentationOptions> configureSqlClientInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddSqlClientInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<OpenTelemetry.Instrumentation.SqlClient.SqlClientInstrumentationOptions> configureSqlClientInstrumentationOptions) -> OpenTelemetry.Trace.TracerProviderBuilder
5 changes: 5 additions & 0 deletions src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
Framework.
([#3900](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3900))

* Added overloads which accept a name to the `TracerProviderBuilder`
`AddSqlClientInstrumentation` extension to allow for more fine-grained options
management
([#3994](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3994))

## 1.0.0-rc9.9

Released 2022-Nov-07
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Api\OpenTelemetry.Api.csproj" />
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Extensions.DependencyInjection\OpenTelemetry.Extensions.DependencyInjection.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Options" Version="$(MicrosoftExtensionsOptionsPkgVer)" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// limitations under the License.
// </copyright>

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using OpenTelemetry.Instrumentation.SqlClient;
using OpenTelemetry.Instrumentation.SqlClient.Implementation;
using OpenTelemetry.Internal;
Expand All @@ -29,18 +31,49 @@ public static class TracerProviderBuilderExtensions
/// Enables SqlClient instrumentation.
/// </summary>
/// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
/// <param name="configureSqlClientInstrumentationOptions">SqlClient configuration options.</param>
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
public static TracerProviderBuilder AddSqlClientInstrumentation(this TracerProviderBuilder builder)
=> AddSqlClientInstrumentation(builder, name: null, configureSqlClientInstrumentationOptions: null);

/// <summary>
/// Enables SqlClient instrumentation.
/// </summary>
/// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
/// <param name="configureSqlClientInstrumentationOptions">Callback action for configuring <see cref="SqlClientInstrumentationOptions"/>.</param>
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
public static TracerProviderBuilder AddSqlClientInstrumentation(
this TracerProviderBuilder builder,
Action<SqlClientInstrumentationOptions> configureSqlClientInstrumentationOptions = null)
Action<SqlClientInstrumentationOptions> configureSqlClientInstrumentationOptions)
=> AddSqlClientInstrumentation(builder, name: null, configureSqlClientInstrumentationOptions);

/// <summary>
/// Enables SqlClient instrumentation.
/// </summary>
/// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
/// <param name="name">Name which is used when retrieving options.</param>
/// <param name="configureSqlClientInstrumentationOptions">Callback action for configuring <see cref="SqlClientInstrumentationOptions"/>.</param>
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
public static TracerProviderBuilder AddSqlClientInstrumentation(
this TracerProviderBuilder builder,
string name,
Action<SqlClientInstrumentationOptions> configureSqlClientInstrumentationOptions)
{
Guard.ThrowIfNull(builder);

var sqlOptions = new SqlClientInstrumentationOptions();
configureSqlClientInstrumentationOptions?.Invoke(sqlOptions);
name ??= Options.DefaultName;

if (configureSqlClientInstrumentationOptions != null)
{
builder.ConfigureServices(services => services.Configure(name, configureSqlClientInstrumentationOptions));
}

builder.AddInstrumentation(sp =>
{
var sqlOptions = sp.GetRequiredService<IOptionsMonitor<SqlClientInstrumentationOptions>>().Get(name);

return new SqlClientInstrumentation(sqlOptions);
});

builder.AddInstrumentation(() => new SqlClientInstrumentation(sqlOptions));
builder.AddSource(SqlActivitySourceHelper.ActivitySourceName);

return builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
// limitations under the License.
// </copyright>

using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Linq;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.DependencyInjection;
using OpenTelemetry.Instrumentation.SqlClient.Implementation;
using OpenTelemetry.Tests;
using OpenTelemetry.Trace;
Expand Down Expand Up @@ -62,6 +60,27 @@ public void SqlClient_BadArgs()
Assert.Throws<ArgumentNullException>(() => builder.AddSqlClientInstrumentation());
}

[Fact]
public void SqlClient_NamedOptions()
{
int defaultExporterOptionsConfigureOptionsInvocations = 0;
int namedExporterOptionsConfigureOptionsInvocations = 0;

using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.ConfigureServices(services =>
{
services.Configure<SqlClientInstrumentationOptions>(o => defaultExporterOptionsConfigureOptionsInvocations++);

services.Configure<SqlClientInstrumentationOptions>("Instrumentation2", o => namedExporterOptionsConfigureOptionsInvocations++);
})
.AddSqlClientInstrumentation()
.AddSqlClientInstrumentation("Instrumentation2", configureSqlClientInstrumentationOptions: null)
.Build();

Assert.Equal(1, defaultExporterOptionsConfigureOptionsInvocations);
Assert.Equal(1, namedExporterOptionsConfigureOptionsInvocations);
}

[Trait("CategoryName", "SqlIntegrationTests")]
[SkipUnlessEnvVarFoundTheory(SqlConnectionStringEnvVarName)]
[InlineData(CommandType.Text, "select 1/1", false)]
Expand Down