Skip to content

Commit 6facd6a

Browse files
committed
Clean up registration
1 parent 5ea3578 commit 6facd6a

File tree

6 files changed

+15
-77
lines changed

6 files changed

+15
-77
lines changed

src/OpenTelemetry.Instrumentation.Kusto/Implementation/KustoInstrumentation.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@ internal static class KustoInstrumentation
1717
return listener;
1818
});
1919

20-
public static KustoInstrumentationOptions TracingOptions { get; set; } = new KustoInstrumentationOptions();
21-
22-
public static KustoInstrumentationOptions MetricOptions { get; set; } = new KustoInstrumentationOptions();
20+
public static KustoInstrumentationOptions Options { get; } = new KustoInstrumentationOptions();
2321

2422
public static InstrumentationHandleManager HandleManager { get; } = new InstrumentationHandleManager();
2523

26-
public static void InitializeTracing() => _ = Listener.Value;
27-
28-
public static void InitializeMetrics() => _ = Listener.Value;
24+
public static void Initialize() => _ = Listener.Value;
2925
}

src/OpenTelemetry.Instrumentation.Kusto/Implementation/KustoTraceRecordListener.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private void CallEnrichment(KustoUtils.TraceRecord record)
7373
var activity = this.GetContext(record)?.Activity;
7474
if (activity is not null && activity.IsAllDataRequested)
7575
{
76-
KustoInstrumentation.TracingOptions.Enrich?.Invoke(activity, record);
76+
KustoInstrumentation.Options.Enrich?.Invoke(activity, record);
7777
}
7878
}
7979
catch (Exception ex)
@@ -139,9 +139,9 @@ private void HandleHttpRequestStart(KustoUtils.TraceRecord record)
139139

140140
if (!result.QueryText.IsEmpty)
141141
{
142-
var info = KustoProcessor.Process(shouldSummarize: KustoInstrumentation.TracingOptions.RecordQuerySummary, shouldSanitize: KustoInstrumentation.TracingOptions.RecordQueryText, result.QueryText.ToString());
142+
var info = KustoProcessor.Process(shouldSummarize: KustoInstrumentation.Options.RecordQuerySummary, shouldSanitize: KustoInstrumentation.Options.RecordQueryText, result.QueryText.ToString());
143143

144-
if (KustoInstrumentation.TracingOptions.RecordQueryText)
144+
if (KustoInstrumentation.Options.RecordQueryText)
145145
{
146146
tagList.Add(SemanticConventions.AttributeDbQueryText, info.Sanitized);
147147
}

src/OpenTelemetry.Instrumentation.Kusto/KustoInstrumentationOptions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,4 @@ public class KustoInstrumentationOptions
2727
/// Gets or sets an action to enrich the Activity with additional information from the TraceRecord.
2828
/// </summary>
2929
public Action<Activity, KustoUtils.TraceRecord>? Enrich { get; set; }
30-
31-
// TODO: Add flag for query parameter tracing
3230
}

src/OpenTelemetry.Instrumentation.Kusto/MeterProviderBuilderExtensions.cs

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4-
using Microsoft.Extensions.DependencyInjection;
5-
using Microsoft.Extensions.Options;
64
using OpenTelemetry.Instrumentation.Kusto;
75
using OpenTelemetry.Instrumentation.Kusto.Implementation;
86
using OpenTelemetry.Internal;
@@ -19,8 +17,8 @@ public static class MeterProviderBuilderExtensions
1917
/// </summary>
2018
/// <param name="builder"><see cref="MeterProviderBuilder"/> being configured.</param>
2119
/// <returns>The instance of <see cref="MeterProviderBuilder"/> to chain the calls.</returns>
22-
public static MeterProviderBuilder AddKustoInstrumentation(this MeterProviderBuilder builder)
23-
=> AddKustoInstrumentation(builder, options => { });
20+
public static MeterProviderBuilder AddKustoInstrumentation(this MeterProviderBuilder builder) =>
21+
builder.AddKustoInstrumentation(options => { });
2422

2523
/// <summary>
2624
/// Enables Kusto instrumentation.
@@ -29,40 +27,15 @@ public static MeterProviderBuilder AddKustoInstrumentation(this MeterProviderBui
2927
/// <param name="configureKustoInstrumentationOptions">Action to configure the <see cref="KustoInstrumentationOptions"/>.</param>
3028
/// <returns>The instance of <see cref="MeterProviderBuilder"/> to chain the calls.</returns>
3129
public static MeterProviderBuilder AddKustoInstrumentation(this MeterProviderBuilder builder, Action<KustoInstrumentationOptions> configureKustoInstrumentationOptions)
32-
{
33-
Guard.ThrowIfNull(configureKustoInstrumentationOptions);
34-
35-
return AddKustoInstrumentation(builder, name: null, configureKustoInstrumentationOptions);
36-
}
37-
38-
// TODO: Revisit named options
39-
40-
/// <summary>
41-
/// Enables Kusto instrumentation.
42-
/// </summary>
43-
/// <param name="builder"><see cref="MeterProviderBuilder"/> being configured.</param>
44-
/// <param name="name">The name of the options instance being configured.</param>
45-
/// <param name="configureOptions">Kusto instrumentation options.</param>
46-
/// <returns>The instance of <see cref="MeterProviderBuilder"/> to chain the calls.</returns>
47-
private static MeterProviderBuilder AddKustoInstrumentation(
48-
this MeterProviderBuilder builder,
49-
string? name,
50-
Action<KustoInstrumentationOptions>? configureOptions)
5130
{
5231
Guard.ThrowIfNull(builder);
53-
name ??= Options.DefaultName;
32+
Guard.ThrowIfNull(configureKustoInstrumentationOptions);
5433

55-
if (configureOptions != null)
56-
{
57-
builder.ConfigureServices(services => services.Configure(name, configureOptions));
58-
}
34+
configureKustoInstrumentationOptions(KustoInstrumentation.Options);
5935

6036
builder.AddInstrumentation(sp =>
6137
{
62-
var options = sp.GetRequiredService<IOptionsMonitor<KustoInstrumentationOptions>>().Get(name);
63-
KustoInstrumentation.MetricOptions = options;
64-
65-
KustoInstrumentation.InitializeMetrics();
38+
KustoInstrumentation.Initialize();
6639
return KustoInstrumentation.HandleManager.AddMetricHandle();
6740
});
6841

src/OpenTelemetry.Instrumentation.Kusto/OpenTelemetry.Instrumentation.Kusto.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
<ItemGroup>
2525
<PackageReference Include="Microsoft.Azure.Kusto.Cloud.Platform" />
2626
<PackageReference Include="Microsoft.Azure.Kusto.Language" />
27-
<PackageReference Include="Microsoft.Extensions.Options" />
28-
<PackageReference Include="OpenTelemetry.Api" />
2927
<PackageReference Include="OpenTelemetry.Api.ProviderBuilderExtensions" />
3028
</ItemGroup>
3129

src/OpenTelemetry.Instrumentation.Kusto/TracerProviderBuilderExtensions.cs

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4-
using Microsoft.Extensions.DependencyInjection;
5-
using Microsoft.Extensions.Options;
64
using OpenTelemetry.Instrumentation.Kusto;
75
using OpenTelemetry.Instrumentation.Kusto.Implementation;
86
using OpenTelemetry.Internal;
@@ -19,8 +17,8 @@ public static class TracerProviderBuilderExtensions
1917
/// </summary>
2018
/// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
2119
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
22-
public static TracerProviderBuilder AddKustoInstrumentation(this TracerProviderBuilder builder)
23-
=> AddKustoInstrumentation(builder, options => { });
20+
public static TracerProviderBuilder AddKustoInstrumentation(this TracerProviderBuilder builder) =>
21+
AddKustoInstrumentation(builder, options => { });
2422

2523
/// <summary>
2624
/// Enables Kusto instrumentation.
@@ -31,40 +29,15 @@ public static TracerProviderBuilder AddKustoInstrumentation(this TracerProviderB
3129
public static TracerProviderBuilder AddKustoInstrumentation(
3230
this TracerProviderBuilder builder,
3331
Action<KustoInstrumentationOptions> configureKustoInstrumentationOptions)
34-
{
35-
Guard.ThrowIfNull(configureKustoInstrumentationOptions);
36-
return AddKustoInstrumentation(builder, name: null, configureKustoInstrumentationOptions);
37-
}
38-
39-
// TODO: Revisit named options
40-
41-
/// <summary>
42-
/// Enables Kusto instrumentation.
43-
/// </summary>
44-
/// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
45-
/// <param name="name">The name of the options instance being configured.</param>
46-
/// <param name="configureOptions">Kusto instrumentation options.</param>
47-
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
48-
private static TracerProviderBuilder AddKustoInstrumentation(
49-
this TracerProviderBuilder builder,
50-
string? name,
51-
Action<KustoInstrumentationOptions>? configureOptions)
5232
{
5333
Guard.ThrowIfNull(builder);
34+
Guard.ThrowIfNull(configureKustoInstrumentationOptions);
5435

55-
name ??= Options.DefaultName;
56-
57-
if (configureOptions != null)
58-
{
59-
builder.ConfigureServices(services => services.Configure(name, configureOptions));
60-
}
36+
configureKustoInstrumentationOptions(KustoInstrumentation.Options);
6137

6238
builder.AddInstrumentation(sp =>
6339
{
64-
var options = sp.GetRequiredService<IOptionsMonitor<KustoInstrumentationOptions>>().Get(name);
65-
KustoInstrumentation.TracingOptions = options;
66-
67-
KustoInstrumentation.InitializeTracing();
40+
KustoInstrumentation.Initialize();
6841
return KustoInstrumentation.HandleManager.AddTracingHandle();
6942
});
7043

0 commit comments

Comments
 (0)