Skip to content

Remove the static collection in the HTTP module#1498

Merged
kevingosse merged 3 commits into
masterfrom
kevin/httpmodule
May 28, 2021
Merged

Remove the static collection in the HTTP module#1498
kevingosse merged 3 commits into
masterfrom
kevin/httpmodule

Conversation

@kevingosse

Copy link
Copy Markdown
Contributor

The collection was there to make sure only one scope is created when the module is registered multiple times. This collection can be source of concerns for customers who see it as a GC root holding large amounts of memory. We can achieve the same results by checking the state stored in the HttpContext and this will clear any confusion.

@kevingosse
kevingosse requested a review from a team as a code owner May 28, 2021 12:15

@andrewlock andrewlock left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully this will give us more defence in support calls!

Not directly related to your changes, but should we explicitly clear the context item here too, incase the SpanContextPropagator.Instance.Inject() call fails and throws?

Comment thread src/Datadog.Trace.AspNet/TracingHttpModule.cs
scope.Dispose();

// Clear the context to make sure another TracingHttpModule doesn't try to close the same scope
app.Context.Items.Remove(_httpContextScopeKey);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth putting this in a finally block so we're sure it's always removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. I thought about it, but since scope.Dispose() is the last operation, I don't think that's an issue if an exception is thrown and another module redo the same processing. But I don't mind adding a finally block, whatever makes you feel better 😃

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 352e75d

@kevingosse

Copy link
Copy Markdown
Contributor Author

Hopefully this will give us more defence in support calls!

Not directly related to your changes, but should we explicitly clear the context item here too, incase the SpanContextPropagator.Instance.Inject() call fails and throws?

I guess I should move the line httpContext.Items[_httpContextScopeKey] = scope; at the end, to make the comment consistent.

@kevingosse
kevingosse merged commit bd2eba7 into master May 28, 2021
@kevingosse
kevingosse deleted the kevin/httpmodule branch May 28, 2021 16:04
@andrewlock andrewlock added this to the 1.27.0 milestone Jun 1, 2021
@lucaspimentel lucaspimentel added area:automatic-instrumentation Automatic instrumentation managed C# code (Datadog.Trace.ClrProfiler.Managed) and removed area:integrations/aspnet labels Jul 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:automatic-instrumentation Automatic instrumentation managed C# code (Datadog.Trace.ClrProfiler.Managed) type:refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants