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

[Instrumentation.AspNet] Fix analysis warnings #960

Merged
merged 2 commits into from
Feb 7, 2023
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
Expand Up @@ -18,6 +18,7 @@
using System.Diagnostics;
using System.Reflection;
using System.Web;
using OpenTelemetry.Internal;

namespace OpenTelemetry.Instrumentation.AspNet;

Expand Down Expand Up @@ -57,6 +58,8 @@ public void Dispose()
/// <inheritdoc />
public void Init(HttpApplication context)
{
Guard.ThrowIfNull(context);

context.BeginRequest += this.Application_BeginRequest;
context.EndRequest += this.Application_EndRequest;
context.Error += this.Application_Error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public static MeterProviderBuilder AddAspNetInstrumentation(
{
Guard.ThrowIfNull(builder);

var instrumentation = new AspNetMetrics();
builder.AddMeter(AspNetMetrics.InstrumentationName);
return builder.AddInstrumentation(() => instrumentation);
return builder.AddInstrumentation(() => new AspNetMetrics());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,9 @@ public void Can_Create_RootActivity_And_Saved_In_HttContext()
}

[Fact]
#pragma warning disable CA1030 // Use events where appropriate
public void Fire_Exception_Events()
#pragma warning restore CA1030 // Use events where appropriate
{
int callbacksFired = 0;

Expand Down Expand Up @@ -529,13 +531,11 @@ public TestHttpContext(Exception error = null)

private class NoopTextMapPropagator : TextMapPropagator
{
private static readonly PropagationContext DefaultPropagationContext = default;

public override ISet<string> Fields => null;

public override PropagationContext Extract<T>(PropagationContext context, T carrier, Func<T, string, IEnumerable<string>> getter)
{
return DefaultPropagationContext;
return default;
}

public override void Inject<T>(PropagationContext context, T carrier, Action<T, string, string> setter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public override string[][] GetUnknownRequestHeaders()

public override string GetUnknownRequestHeader(string name)
{
if (this.headers.ContainsKey(name))
if (this.headers.TryGetValue(name, out var value))
{
return this.headers[name];
return value;
}

return base.GetUnknownRequestHeader(name);
Expand All @@ -91,9 +91,9 @@ public override string GetKnownRequestHeader(int index)
{
var name = GetKnownRequestHeaderName(index);

if (this.headers.ContainsKey(name))
if (this.headers.TryGetValue(name, out var value))
{
return this.headers[name];
return value;
}

return base.GetKnownRequestHeader(index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,16 +391,17 @@ private XDocument ApplyTransformation(string originalConfiguration, string trans
var document = new XmlTransformableDocument();
using var transformation = new XmlTransformation(stream, null);
stream = null;
#pragma warning disable CA3075 // Insecure DTD processing in XML
document.LoadXml(originalConfiguration);
#pragma warning restore CA3075 // Insecure DTD processing in XML
transformation.Apply(document);
result = XDocument.Parse(document.OuterXml);
}
finally
{
if (stream != null)
{
stream.Dispose();
}
#pragma warning disable CA1508 // Avoid dead conditional code
stream?.Dispose();
#pragma warning restore CA1508 // Avoid dead conditional code
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,16 +421,17 @@ private XDocument ApplyTransformation(string originalConfiguration, string trans
var document = new XmlTransformableDocument();
using var transformation = new XmlTransformation(stream, null);
stream = null;
#pragma warning disable CA3075 // Insecure DTD processing in XML
document.LoadXml(originalConfiguration);
#pragma warning restore CA3075 // Insecure DTD processing in XML
transformation.Apply(document);
result = XDocument.Parse(document.OuterXml);
}
finally
{
if (stream != null)
{
stream.Dispose();
}
#pragma warning disable CA1508 // Avoid dead conditional code
stream?.Dispose();
#pragma warning restore CA1508 // Avoid dead conditional code
}

return result;
Expand Down