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

Agent: Integration with ASP.NET (full framework) via custom HttpModule [Research] #13

Closed
stevejgordon opened this issue Dec 12, 2023 · 1 comment

Comments

@stevejgordon
Copy link
Contributor

We should support ASP.NET (full framework) by either extending the OTel HttpModule or shipping our own.

@stevejgordon
Copy link
Contributor Author

Having reviewed the code, I see that this already works!

Basic steps

public class WebApiApplication : HttpApplication
{
	private const string SourceName = "Example.AspNetClassic";

	internal static readonly ActivitySource ActivitySource = new(SourceName);

	private IInstrumentationLifetime _lifetime;

	protected void Application_Start()
	{
		GlobalConfiguration.Configure(WebApiConfig.Register);
		FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

		_lifetime = new ElasticOpenTelemetryBuilder()
			.ConfigureResource(r => r.AddService("aspnet-classic-webapi-example"))
			.WithTracing(t => t
				.AddAspNetInstrumentation()
				.AddSource(SourceName))
			.Build();
	}

	protected void Application_End() => _lifetime?.Dispose();
}

Note: Unfortunately, as we depend on some historically problematic libraries, specifically System.Memory and System.Runtime.CompilerServices.Unsafe consumers may hit issues with the resolution of the package in the form of FileLoadException: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.

This can be worked around by manually adding suitable binding redirects such as:

<dependentAssembly>
	<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
	<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
	<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
	<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
</dependentAssembly>

An example has been added in #97

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant