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

Enable Nulls on Contrib.Instrumentation.AWS & Test Projects #926

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
@@ -1,6 +1,7 @@
#nullable enable
OpenTelemetry.Contrib.Instrumentation.AWS.AWSClientInstrumentationOptions
OpenTelemetry.Contrib.Instrumentation.AWS.AWSClientInstrumentationOptions.AWSClientInstrumentationOptions() -> void
OpenTelemetry.Contrib.Instrumentation.AWS.AWSClientInstrumentationOptions.SuppressDownstreamInstrumentation.get -> bool
OpenTelemetry.Contrib.Instrumentation.AWS.AWSClientInstrumentationOptions.SuppressDownstreamInstrumentation.set -> void
OpenTelemetry.Trace.TracerProviderBuilderExtensions
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAWSInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<OpenTelemetry.Contrib.Instrumentation.AWS.AWSClientInstrumentationOptions> configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAWSInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder, System.Action<OpenTelemetry.Contrib.Instrumentation.AWS.AWSClientInstrumentationOptions!>? configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder!
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
@@ -1,6 +1,7 @@
#nullable enable
OpenTelemetry.Contrib.Instrumentation.AWS.AWSClientInstrumentationOptions
OpenTelemetry.Contrib.Instrumentation.AWS.AWSClientInstrumentationOptions.AWSClientInstrumentationOptions() -> void
OpenTelemetry.Contrib.Instrumentation.AWS.AWSClientInstrumentationOptions.SuppressDownstreamInstrumentation.get -> bool
OpenTelemetry.Contrib.Instrumentation.AWS.AWSClientInstrumentationOptions.SuppressDownstreamInstrumentation.set -> void
OpenTelemetry.Trace.TracerProviderBuilderExtensions
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAWSInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<OpenTelemetry.Contrib.Instrumentation.AWS.AWSClientInstrumentationOptions> configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAWSInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder, System.Action<OpenTelemetry.Contrib.Instrumentation.AWS.AWSClientInstrumentationOptions!>? configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder!
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 @@ -73,7 +73,7 @@ public override void InvokeSync(IExecutionContext executionContext)

public override async Task<T> InvokeAsync<T>(IExecutionContext executionContext)
{
T ret = null;
T? ret = null;

var activity = this.ProcessBeginRequest(executionContext);
try
Expand All @@ -100,9 +100,9 @@ public override async Task<T> InvokeAsync<T>(IExecutionContext executionContext)
return ret;
}

private Activity ProcessBeginRequest(IExecutionContext executionContext)
private Activity? ProcessBeginRequest(IExecutionContext executionContext)
{
Activity activity = null;
Activity? activity = null;

var requestContext = executionContext.RequestContext;
var service = AWSServiceHelper.GetAWSServiceName(requestContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ namespace OpenTelemetry.Contrib.Instrumentation.AWS.Implementation;

internal class Utils
{
internal static object GetTagValue(Activity activity, string tagName)
internal static object? GetTagValue(Activity activity, string tagName)
{
foreach (KeyValuePair<string, object> tag in activity.TagObjects)
foreach (KeyValuePair<string, object?> tag in activity.TagObjects)
{
if (tag.Key.Equals(tagName))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<!-- OmniSharp/VS Code requires TargetFrameworks to be in descending order for IntelliSense and analysis. -->
<TargetFrameworks>netstandard2.0;net452</TargetFrameworks>
<Description>AWS client instrumentation for OpenTelemetry .NET</Description>
<MinVerTagPrefix>Instrumentation.AWS-</MinVerTagPrefix>
<MinVerTagPrefix>Instrumentation.AWS-</MinVerTagPrefix>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static class TracerProviderBuilderExtensions
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
public static TracerProviderBuilder AddAWSInstrumentation(
this TracerProviderBuilder builder,
Action<AWSClientInstrumentationOptions> configure = null)
Action<AWSClientInstrumentationOptions>? configure = null)
{
Guard.ThrowIfNull(builder);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<!-- OmniSharp/VS Code requires TargetFrameworks to be in descending order for IntelliSense and analysis. -->
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks Condition="$(OS) == 'Windows_NT'">$(TargetFrameworks);net452</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,30 @@ internal static class CustomResponses
{
#if NET452
public static void SetResponse(
AmazonServiceClient client, string content, string requestId, bool isOK)
AmazonServiceClient client, string? content, string requestId, bool isOK)
{
var response = Create(content, requestId, isOK);
SetResponse(client, response);
}

public static void SetResponse(
AmazonServiceClient client,
Func<MockHttpRequest, HttpWebResponse> responseCreator)
Func<MockHttpRequest, HttpWebResponse?> responseCreator)
{
var pipeline = client
.GetType()
.GetProperty("RuntimePipeline", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
.GetProperty("RuntimePipeline", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)?
.GetValue(client, null)
as RuntimePipeline;

var requestFactory = new MockHttpRequestFactory();
requestFactory.ResponseCreator = responseCreator;
var httpHandler = new HttpHandler<Stream>(requestFactory, client);
pipeline.ReplaceHandler<HttpHandler<Stream>>(httpHandler);
pipeline?.ReplaceHandler<HttpHandler<Stream>>(httpHandler);
}

private static Func<MockHttpRequest, HttpWebResponse> Create(
string content, string requestId, bool isOK)
private static Func<MockHttpRequest, HttpWebResponse?> Create(
string? content, string requestId, bool isOK)
{
var status = isOK ? HttpStatusCode.OK : HttpStatusCode.NotFound;

Expand All @@ -82,7 +82,7 @@ private static Func<MockHttpRequest, HttpWebResponse> Create(
};
}
#else
public static void SetResponse(AmazonServiceClient client, string content, string requestId, bool isOK)
public static void SetResponse(AmazonServiceClient client, string? content, string requestId, bool isOK)
{
var response = Create(content, requestId, isOK);
SetResponse(client, response);
Expand All @@ -92,18 +92,18 @@ public static void SetResponse(AmazonServiceClient client, Func<MockHttpRequest,
{
var pipeline = client
.GetType()
.GetProperty("RuntimePipeline", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
.GetProperty("RuntimePipeline", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)?
.GetValue(client, null)
as RuntimePipeline;

var requestFactory = new MockHttpRequestFactory();
requestFactory.ResponseCreator = responseCreator;
var httpHandler = new HttpHandler<HttpContent>(requestFactory, client);
pipeline.ReplaceHandler<HttpHandler<HttpContent>>(httpHandler);
pipeline?.ReplaceHandler<HttpHandler<HttpContent>>(httpHandler);
}

private static Func<MockHttpRequest, HttpResponseMessage> Create(
string content, string requestId, bool isOK)
string? content, string requestId, bool isOK)
{
var status = isOK ? HttpStatusCode.OK : HttpStatusCode.NotFound;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ namespace OpenTelemetry.Contrib.Instrumentation.AWS.Tests;
internal class CustomWebResponse : IWebResponseData
{
private HttpResponseMessageBody response;
private string[] headerNames;
private Dictionary<string, string> headers;
private HashSet<string> headerNamesSet;
private string[]? headerNames;
private Dictionary<string, string>? headers;
private HashSet<string>? headerNamesSet;

public CustomWebResponse(HttpResponseMessage response)
: this(response, null, false)
{
}

public CustomWebResponse(HttpResponseMessage responseMsg, HttpClient httpClient, bool disposeClient)
public CustomWebResponse(HttpResponseMessage responseMsg, HttpClient? httpClient, bool disposeClient)
{
this.response = new HttpResponseMessageBody(responseMsg, httpClient, disposeClient);

Expand All @@ -50,7 +50,7 @@ public CustomWebResponse(HttpResponseMessage responseMsg, HttpClient httpClient,

public bool IsSuccessStatusCode { get; private set; }

public string ContentType { get; private set; }
public string? ContentType { get; private set; }

public long ContentLength { get; private set; }

Expand All @@ -66,8 +66,8 @@ public static IWebResponseData GenerateWebResponse(HttpResponseMessage response)

public string GetHeaderValue(string headerName)
{
string headerValue;
if (this.headers.TryGetValue(headerName, out headerValue))
string? headerValue;
if (this.headers != null && this.headers.TryGetValue(headerName, out headerValue))
{
return headerValue;
}
Expand All @@ -77,10 +77,10 @@ public string GetHeaderValue(string headerName)

public bool IsHeaderPresent(string headerName)
{
return this.headerNamesSet.Contains(headerName);
return this.headerNamesSet != null && this.headerNamesSet.Contains(headerName);
}

public string[] GetHeaderNames()
public string[]? GetHeaderNames()
{
return this.headerNames;
}
Expand Down Expand Up @@ -116,7 +116,7 @@ private void CopyHeaderValues(HttpResponseMessage response)

private string GetFirstHeaderValue(HttpHeaders headers, string key)
{
IEnumerable<string> headerValues = null;
IEnumerable<string>? headerValues = null;
if (headers.TryGetValues(key, out headerValues))
{
return headerValues.FirstOrDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ namespace OpenTelemetry.Contrib.Instrumentation.AWS.Tests;

internal class HttpResponseMessageBody : IHttpResponseBody
{
private HttpClient httpClient;
private HttpClient? httpClient;
private HttpResponseMessage response;
private bool disposeClient = false;
private bool disposed = false;

public HttpResponseMessageBody(HttpResponseMessage response, HttpClient httpClient, bool disposeClient)
public HttpResponseMessageBody(HttpResponseMessage response, HttpClient? httpClient, bool disposeClient)
{
this.httpClient = httpClient;
this.response = response;
Expand Down Expand Up @@ -65,7 +65,8 @@ Task<Stream> IHttpResponseBody.OpenResponseAsync()
}
else
{
return null;
var ms = new MemoryStream();
return Task.FromResult<Stream>(ms);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ namespace OpenTelemetry.Contrib.Instrumentation.AWS.Tests;
#if NET452
internal class MockHttpRequest : IHttpRequest<Stream>
{
private Stream requestStream = null;
private Stream? requestStream = null;

public MockHttpRequest(Uri requestUri, Action action, Func<MockHttpRequest, HttpWebResponse> responseCreator = null)
public MockHttpRequest(Uri requestUri, Action? action, Func<MockHttpRequest, HttpWebResponse?>? responseCreator = null)
{
this.RequestUri = requestUri;
this.GetResponseAction = action;
Expand All @@ -51,13 +51,13 @@ public MockHttpRequest(Uri requestUri, Action action, Func<MockHttpRequest, Http

public bool IsGetRequestContentCalled { get; set; }

public string Method { get; set; }
public string? Method { get; set; }

public Uri RequestUri { get; set; }

public Action GetResponseAction { get; set; }
public Action? GetResponseAction { get; set; }

public Func<MockHttpRequest, HttpWebResponse> ResponseCreator { get; set; }
public Func<MockHttpRequest, HttpWebResponse?> ResponseCreator { get; set; }

public void ConfigureRequest(IRequestContext requestContext)
{
Expand Down Expand Up @@ -106,7 +106,7 @@ public Task<Stream> GetRequestContentAsync()
return Task.FromResult<Stream>(new MemoryStream());
}

public Task<IWebResponseData> GetResponseAsync(System.Threading.CancellationToken cancellationToken)
public Task<IWebResponseData> GetResponseAsync(CancellationToken cancellationToken)
{
this.GetResponseAction?.Invoke();

Expand Down Expand Up @@ -144,7 +144,7 @@ private HttpWebResponse CreateResponse(MockHttpRequest request)
var resourceName = request.RequestUri.Host.Split('.').Last();
var response = MockWebResponse.CreateFromResource(resourceName);

if (response.StatusCode >= HttpStatusCode.OK && response.StatusCode <= (HttpStatusCode)299)
if (response?.StatusCode >= HttpStatusCode.OK && response.StatusCode <= (HttpStatusCode)299)
{
return response;
}
Expand All @@ -157,7 +157,7 @@ private HttpWebResponse CreateResponse(MockHttpRequest request)
#else
internal class MockHttpRequest : IHttpRequest<HttpContent>
{
public MockHttpRequest(Uri requestUri, Action action, Func<MockHttpRequest, HttpResponseMessage> responseCreator = null)
public MockHttpRequest(Uri requestUri, Action? action, Func<MockHttpRequest, HttpResponseMessage>? responseCreator = null)
{
this.RequestUri = requestUri;
this.GetResponseAction = action;
Expand All @@ -174,11 +174,11 @@ public MockHttpRequest(Uri requestUri, Action action, Func<MockHttpRequest, Http

public bool IsGetRequestContentCalled { get; set; }

public string Method { get; set; }
public string? Method { get; set; }

public Uri RequestUri { get; set; }

public Action GetResponseAction { get; set; }
public Action? GetResponseAction { get; set; }

public Func<MockHttpRequest, HttpResponseMessage> ResponseCreator { get; set; }

Expand Down Expand Up @@ -206,7 +206,7 @@ public HttpContent GetRequestContent()
}
catch (AggregateException e)
{
throw e.InnerException;
throw e.InnerException ?? e;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ namespace OpenTelemetry.Contrib.Instrumentation.AWS.Tests;
#if NET452
internal class MockHttpRequestFactory : IHttpRequestFactory<Stream>
{
public Action GetResponseAction { get; set; }
public Action? GetResponseAction { get; set; }

public Func<MockHttpRequest, HttpWebResponse> ResponseCreator { get; set; }
public Func<MockHttpRequest, HttpWebResponse?>? ResponseCreator { get; set; }

public MockHttpRequest LastCreatedRequest { get; private set; }
public MockHttpRequest? LastCreatedRequest { get; private set; }

public IHttpRequest<Stream> CreateHttpRequest(Uri requestUri)
{
Expand All @@ -46,11 +46,11 @@ public void Dispose()
#else
internal class MockHttpRequestFactory : IHttpRequestFactory<HttpContent>
{
public Action GetResponseAction { get; set; }
public Action? GetResponseAction { get; set; }

public MockHttpRequest LastCreatedRequest { get; private set; }
public MockHttpRequest? LastCreatedRequest { get; private set; }

public Func<MockHttpRequest, HttpResponseMessage> ResponseCreator { get; set; }
public Func<MockHttpRequest, HttpResponseMessage>? ResponseCreator { get; set; }

public IHttpRequest<HttpContent> CreateHttpRequest(Uri requestUri)
{
Expand Down
Loading