open-telemetry / opentelemetry-dotnet-contrib

This repository contains set of components extending functionality of the OpenTelemetry .NET SDK. Instrumentation libraries, exporters, and other components can find their home here.
https://opentelemetry.io
Apache License 2.0
462 stars 276 forks source link

[bug] HttpRequest.Headers becomes Read-Only #2176

Open bubrick opened 2 weeks ago

bubrick commented 2 weeks ago

Component

OpenTelemetry.Instrumentation.Wcf

Package Version

Package Name Version
OpenTelemetry.Instrumentation.AspNet 1.9.0-beta.1
OpenTelemetry.Instrumentation.Wcf 1.0.0-rc.17

Runtime Version

net48

Description

HttpRequest.Headers becomes read-only when OpenTelemetry packages are installed. By default, System.Web does not make headers read-only for IIS7 requests, but AspNetParentSpanCorrector always makes it read-only

Steps to Reproduce

// global.asax.cs
protected void Application_BeginRequest(object sender, EventArgs e)
{
    Request.Headers.Set("MyExtraHeader", "hello-world");
}

Expected Result

Header added successfully when application is hosted in IIS

Actual Result

Collection is read-only. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NotSupportedException: Collection is read-only.

Additional Context

Seems to be introduced in this commit. Should probably check if the headers collection is already modifiable and take no action in such case, returning to the current behavior otherwise.

github-actions[bot] commented 2 weeks ago

Tagging component owner(s).

@codeblanch