Skip to content

Commit

Permalink
[Instrumentation.Owin] Nullable (#1601)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek authored Mar 13, 2024
1 parent 609565c commit 01c2257
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#nullable enable
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ OpenTelemetry.Instrumentation.Owin.OwinEnrichEventType
OpenTelemetry.Instrumentation.Owin.OwinEnrichEventType.BeginRequest = 0 -> OpenTelemetry.Instrumentation.Owin.OwinEnrichEventType
OpenTelemetry.Instrumentation.Owin.OwinEnrichEventType.EndRequest = 1 -> OpenTelemetry.Instrumentation.Owin.OwinEnrichEventType
OpenTelemetry.Instrumentation.Owin.OwinInstrumentationOptions
OpenTelemetry.Instrumentation.Owin.OwinInstrumentationOptions.Enrich.get -> System.Action<System.Diagnostics.Activity, OpenTelemetry.Instrumentation.Owin.OwinEnrichEventType, Microsoft.Owin.IOwinContext, System.Exception>
OpenTelemetry.Instrumentation.Owin.OwinInstrumentationOptions.Enrich.get -> System.Action<System.Diagnostics.Activity!, OpenTelemetry.Instrumentation.Owin.OwinEnrichEventType, Microsoft.Owin.IOwinContext!, System.Exception?>?
OpenTelemetry.Instrumentation.Owin.OwinInstrumentationOptions.Enrich.set -> void
OpenTelemetry.Instrumentation.Owin.OwinInstrumentationOptions.Filter.get -> System.Func<Microsoft.Owin.IOwinContext, bool>
OpenTelemetry.Instrumentation.Owin.OwinInstrumentationOptions.Filter.get -> System.Func<Microsoft.Owin.IOwinContext!, bool>?
OpenTelemetry.Instrumentation.Owin.OwinInstrumentationOptions.Filter.set -> void
OpenTelemetry.Instrumentation.Owin.OwinInstrumentationOptions.OwinInstrumentationOptions() -> void
OpenTelemetry.Instrumentation.Owin.OwinInstrumentationOptions.RecordException.get -> bool
OpenTelemetry.Instrumentation.Owin.OwinInstrumentationOptions.RecordException.set -> void
OpenTelemetry.Metrics.OwinInstrumentationMeterProviderBuilderExtensions
OpenTelemetry.Trace.TracerProviderBuilderExtensions
Owin.AppBuilderExtensions
static OpenTelemetry.Metrics.OwinInstrumentationMeterProviderBuilderExtensions.AddOwinInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder builder) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddOwinInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddOwinInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<OpenTelemetry.Instrumentation.Owin.OwinInstrumentationOptions> configure) -> OpenTelemetry.Trace.TracerProviderBuilder
static Owin.AppBuilderExtensions.UseOpenTelemetry(this Owin.IAppBuilder appBuilder) -> Owin.IAppBuilder
static OpenTelemetry.Metrics.OwinInstrumentationMeterProviderBuilderExtensions.AddOwinInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder! builder) -> OpenTelemetry.Metrics.MeterProviderBuilder!
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddOwinInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder) -> OpenTelemetry.Trace.TracerProviderBuilder!
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddOwinInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder, System.Action<OpenTelemetry.Instrumentation.Owin.OwinInstrumentationOptions!>? configure) -> OpenTelemetry.Trace.TracerProviderBuilder!
static Owin.AppBuilderExtensions.UseOpenTelemetry(this Owin.IAppBuilder! appBuilder) -> Owin.IAppBuilder!
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private static void BeginRequest(IOwinContext owinContext)
var textMapPropagator = Propagators.DefaultTextMapPropagator;
var ctx = textMapPropagator.Extract(default, owinContext.Request, OwinRequestHeaderValuesGetter);

Activity activity = OwinInstrumentationActivitySource.ActivitySource.StartActivity(
Activity? activity = OwinInstrumentationActivitySource.ActivitySource.StartActivity(
OwinInstrumentationActivitySource.IncomingRequestActivityName,
ActivityKind.Server,
ctx.ActivityContext);
Expand Down Expand Up @@ -123,7 +123,7 @@ private static void BeginRequest(IOwinContext owinContext)

try
{
OwinInstrumentationActivitySource.Options.Enrich?.Invoke(
OwinInstrumentationActivitySource.Options?.Enrich?.Invoke(
activity,
OwinEnrichEventType.BeginRequest,
owinContext,
Expand All @@ -147,7 +147,7 @@ private static void BeginRequest(IOwinContext owinContext)
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void RequestEnd(IOwinContext owinContext, Exception exception, long startTimestamp)
private static void RequestEnd(IOwinContext owinContext, Exception? exception, long startTimestamp)
{
if (owinContext.Environment.TryGetValue(ContextKey, out object context)
&& context is Activity activity)
Expand All @@ -165,7 +165,7 @@ private static void RequestEnd(IOwinContext owinContext, Exception exception, lo
{
activity.SetStatus(Status.Error);

if (OwinInstrumentationActivitySource.Options.RecordException)
if (OwinInstrumentationActivitySource.Options != null && OwinInstrumentationActivitySource.Options.RecordException)
{
activity.RecordException(exception);
}
Expand All @@ -179,7 +179,7 @@ private static void RequestEnd(IOwinContext owinContext, Exception exception, lo

try
{
OwinInstrumentationActivitySource.Options.Enrich?.Invoke(
OwinInstrumentationActivitySource.Options?.Enrich?.Invoke(
activity,
OwinEnrichEventType.EndRequest,
owinContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal static class OwinInstrumentationActivitySource

private static readonly Version Version = AssemblyName.Version;

public static ActivitySource ActivitySource { get; } = new ActivitySource(ActivitySourceName, Version.ToString());
public static ActivitySource ActivitySource { get; } = new(ActivitySourceName, Version.ToString());

public static OwinInstrumentationOptions Options { get; set; }
public static OwinInstrumentationOptions? Options { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<Description>OpenTelemetry instrumentation for OWIN</Description>
<PackageTags>$(PackageTags);distributed-tracing;OWIN</PackageTags>
<MinVerTagPrefix>Instrumentation.Owin-</MinVerTagPrefix>
<Nullable>disable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public class OwinInstrumentationOptions
/// If Filter returns true, the request is collected.
/// If Filter returns false or throw exception, the request is filtered out.
/// </summary>
public Func<IOwinContext, bool> Filter { get; set; }
public Func<IOwinContext, bool>? Filter { get; set; }

/// <summary>
/// Gets or sets an action to enrich the <see cref="Activity"/> created by the instrumentation.
/// </summary>
public Action<Activity, OwinEnrichEventType, IOwinContext, Exception> Enrich { get; set; }
public Action<Activity, OwinEnrichEventType, IOwinContext, Exception?>? Enrich { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the exception will be recorded as <see cref="ActivityEvent"/> or not.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static TracerProviderBuilder AddOwinInstrumentation(this TracerProviderBu
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
public static TracerProviderBuilder AddOwinInstrumentation(
this TracerProviderBuilder builder,
Action<OwinInstrumentationOptions> configure)
Action<OwinInstrumentationOptions>? configure)
{
Guard.ThrowIfNull(builder);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace OpenTelemetry.Instrumentation.Owin.Tests.Controllers;
public class TestController : ApiController
{
// GET api/test/{id}
public string Get(string id = null)
public string Get(string? id = null)
{
return $"id:{id}";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,18 @@ namespace OpenTelemetry.Instrumentation.Owin.Tests;
public class DiagnosticsMiddlewareTests : IDisposable
{
private readonly Uri serviceBaseUri;
private readonly IDisposable listener;
private readonly IDisposable? listener;
private readonly EventWaitHandle requestCompleteHandle = new(false, EventResetMode.AutoReset);

public DiagnosticsMiddlewareTests()
{
Random random = new Random();
var retryCount = 5;
while (retryCount > 0)
do
{
this.serviceBaseUri = new Uri($"http://localhost:{random.Next(2000, 5000)}/");
try
{
this.serviceBaseUri = new Uri($"http://localhost:{random.Next(2000, 5000)}/");

this.listener = WebApp.Start(
this.serviceBaseUri.ToString(),
appBuilder =>
Expand Down Expand Up @@ -81,6 +80,7 @@ public DiagnosticsMiddlewareTests()
retryCount--;
}
}
while (retryCount > 0);

if (this.listener == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<Description>Unit test project for OpenTelemetry OWIN instrumentation</Description>
<TargetFrameworks>$(NetFrameworkMinimumSupportedVersion)</TargetFrameworks>
<Nullable>disable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 01c2257

Please sign in to comment.