diff --git a/examples/AspNet/Examples.AspNet.csproj b/examples/AspNet/Examples.AspNet.csproj
index b67f0c72313..fef00f55b5e 100644
--- a/examples/AspNet/Examples.AspNet.csproj
+++ b/examples/AspNet/Examples.AspNet.csproj
@@ -61,6 +61,7 @@
+
@@ -149,4 +150,4 @@
-
+
\ No newline at end of file
diff --git a/examples/AspNet/SuppressInstrumentationHttpModule.cs b/examples/AspNet/SuppressInstrumentationHttpModule.cs
new file mode 100644
index 00000000000..fb832109182
--- /dev/null
+++ b/examples/AspNet/SuppressInstrumentationHttpModule.cs
@@ -0,0 +1,58 @@
+//
+// Copyright The OpenTelemetry Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+using System;
+using System.Web;
+using OpenTelemetry;
+
+namespace Examples.AspNet
+{
+ ///
+ /// A demo which will suppress ASP.NET
+ /// instrumentation if a request contains "suppress=true" on the query
+ /// string. Suppressed spans will not be processed/exported by the
+ /// OpenTelemetry SDK.
+ ///
+ public class SuppressInstrumentationHttpModule : IHttpModule
+ {
+ private IDisposable suppressionScope;
+
+ public void Init(HttpApplication context)
+ {
+ context.BeginRequest += this.Application_BeginRequest;
+ context.EndRequest += this.Application_EndRequest;
+ }
+
+ public void Dispose()
+ {
+ }
+
+ private void Application_BeginRequest(object sender, EventArgs e)
+ {
+ var context = ((HttpApplication)sender).Context;
+
+ if (context.Request.QueryString["suppress"] == "true")
+ {
+ this.suppressionScope = SuppressInstrumentationScope.Begin();
+ }
+ }
+
+ private void Application_EndRequest(object sender, EventArgs e)
+ {
+ this.suppressionScope?.Dispose();
+ }
+ }
+}
diff --git a/examples/AspNet/Web.config b/examples/AspNet/Web.config
index fcf320ae33e..0ee991a134e 100644
--- a/examples/AspNet/Web.config
+++ b/examples/AspNet/Web.config
@@ -23,6 +23,7 @@
+
@@ -37,20 +38,16 @@
-
-
+
+
-
-
-
-
-
-
+
+
diff --git a/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/.publicApi/net461/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/.publicApi/net461/PublicAPI.Unshipped.txt
index 04b7b15df9b..367f7a1e6e6 100644
--- a/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/.publicApi/net461/PublicAPI.Unshipped.txt
+++ b/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/.publicApi/net461/PublicAPI.Unshipped.txt
@@ -3,12 +3,14 @@ const OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.AspNetSourceName
OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule
OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.Dispose() -> void
OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.Init(System.Web.HttpApplication context) -> void
-OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.OnExceptionCallback.get -> System.Action
-OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.OnExceptionCallback.set -> void
-OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.OnRequestStartedCallback.get -> System.Action
-OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.OnRequestStartedCallback.set -> void
-OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.OnRequestStoppedCallback.get -> System.Action
-OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.OnRequestStoppedCallback.set -> void
OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.TelemetryHttpModule() -> void
-OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.TextMapPropagator.get -> OpenTelemetry.Context.Propagation.TraceContextPropagator
-OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.TextMapPropagator.set -> void
+OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModuleOptions
+OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModuleOptions.OnExceptionCallback.get -> System.Action
+OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModuleOptions.OnExceptionCallback.set -> void
+OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModuleOptions.OnRequestStartedCallback.get -> System.Action
+OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModuleOptions.OnRequestStartedCallback.set -> void
+OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModuleOptions.OnRequestStoppedCallback.get -> System.Action
+OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModuleOptions.OnRequestStoppedCallback.set -> void
+OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModuleOptions.TextMapPropagator.get -> OpenTelemetry.Context.Propagation.TextMapPropagator
+OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModuleOptions.TextMapPropagator.set -> void
+static OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.Options.get -> OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModuleOptions
diff --git a/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/ActivityHelper.cs b/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/ActivityHelper.cs
index 7675b8e4516..29711309204 100644
--- a/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/ActivityHelper.cs
+++ b/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/ActivityHelper.cs
@@ -34,7 +34,8 @@ internal static class ActivityHelper
///
private const string ActivityKey = "__AspnetActivity__";
- private static readonly ActivitySource AspNetSource = new ActivitySource(TelemetryHttpModule.AspNetSourceName);
+ private static readonly Version Version = typeof(ActivityHelper).Assembly.GetName().Version;
+ private static readonly ActivitySource AspNetSource = new ActivitySource(TelemetryHttpModule.AspNetSourceName, Version.ToString());
private static readonly Func> HttpRequestHeaderValuesGetter = (request, name) => request.Headers.GetValues(name);
private static readonly object StartedButNotSampledObj = new object();
@@ -71,7 +72,7 @@ public static Activity StartAspNetActivity(TextMapPropagator textMapPropagator,
{
PropagationContext propagationContext = textMapPropagator.Extract(default, context.Request, HttpRequestHeaderValuesGetter);
- Activity activity = AspNetSource.CreateActivity(TelemetryHttpModule.AspNetActivityName, ActivityKind.Server, propagationContext.ActivityContext);
+ Activity activity = AspNetSource.StartActivity(TelemetryHttpModule.AspNetActivityName, ActivityKind.Server, propagationContext.ActivityContext);
if (activity != null)
{
@@ -147,13 +148,13 @@ public static void StopAspNetActivity(Activity aspNetActivity, HttpContext conte
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void WriteActivityException(Activity aspNetActivity, Exception exception, Action onExceptionCallback)
+ public static void WriteActivityException(Activity aspNetActivity, HttpContext context, Exception exception, Action onExceptionCallback)
{
if (aspNetActivity != null)
{
try
{
- onExceptionCallback?.Invoke(aspNetActivity, exception);
+ onExceptionCallback?.Invoke(aspNetActivity, context, exception);
}
catch (Exception callbackEx)
{
diff --git a/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/AspNetTelemetryEventSource.cs b/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/AspNetTelemetryEventSource.cs
index 38c6cb452ab..9fa3a5ef871 100644
--- a/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/AspNetTelemetryEventSource.cs
+++ b/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/AspNetTelemetryEventSource.cs
@@ -17,6 +17,7 @@
using System;
using System.Diagnostics;
using System.Diagnostics.Tracing;
+using OpenTelemetry.Internal;
namespace OpenTelemetry.Instrumentation.AspNet
{
@@ -63,7 +64,7 @@ public void ActivityException(Activity activity, Exception ex)
{
if (this.IsEnabled(EventLevel.Error, EventKeywords.All))
{
- this.ActivityException(activity?.Id, ex.ToString());
+ this.ActivityException(activity?.Id, ex.ToInvariantString());
}
}
@@ -72,7 +73,7 @@ public void CallbackException(Activity activity, string eventName, Exception ex)
{
if (this.IsEnabled(EventLevel.Error, EventKeywords.All))
{
- this.CallbackException(activity?.Id, eventName, ex.ToString());
+ this.CallbackException(activity?.Id, eventName, ex.ToInvariantString());
}
}
diff --git a/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.csproj b/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.csproj
index 9f9c307f674..9ac9a472c1f 100644
--- a/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.csproj
+++ b/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.csproj
@@ -12,6 +12,10 @@
false
+
+
+
+
diff --git a/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/TelemetryHttpModule.cs b/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/TelemetryHttpModule.cs
index f6cb354290d..337b956a648 100644
--- a/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/TelemetryHttpModule.cs
+++ b/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/TelemetryHttpModule.cs
@@ -15,11 +15,9 @@
//
using System;
-using System.ComponentModel;
using System.Diagnostics;
using System.Reflection;
using System.Web;
-using OpenTelemetry.Context.Propagation;
namespace OpenTelemetry.Instrumentation.AspNet
{
@@ -46,37 +44,10 @@ public class TelemetryHttpModule : IHttpModule
private static readonly MethodInfo OnStepMethodInfo = typeof(HttpApplication).GetMethod("OnExecuteRequestStep");
- private TraceContextPropagator traceContextPropagator = new TraceContextPropagator();
-
- ///
- /// Gets or sets the to use to
- /// extract from incoming requests.
- ///
- [EditorBrowsable(EditorBrowsableState.Never)]
- public TraceContextPropagator TextMapPropagator
- {
- get => this.traceContextPropagator;
- set => this.traceContextPropagator = value ?? throw new ArgumentNullException(nameof(value));
- }
-
- ///
- /// Gets or sets a callback action to be fired when a request is started.
- ///
- [EditorBrowsable(EditorBrowsableState.Never)]
- public Action OnRequestStartedCallback { get; set; }
-
- ///
- /// Gets or sets a callback action to be fired when a request is stopped.
- ///
- [EditorBrowsable(EditorBrowsableState.Never)]
- public Action OnRequestStoppedCallback { get; set; }
-
///
- /// Gets or sets a callback action to be fired when an unhandled
- /// exception is thrown processing a request.
+ /// Gets the applied to requests processed by the handler.
///
- [EditorBrowsable(EditorBrowsableState.Never)]
- public Action OnExceptionCallback { get; set; }
+ public static TelemetryHttpModuleOptions Options { get; } = new TelemetryHttpModuleOptions();
///
public void Dispose()
@@ -136,7 +107,7 @@ private void Application_BeginRequest(object sender, EventArgs e)
{
var context = ((HttpApplication)sender).Context;
AspNetTelemetryEventSource.Log.TraceCallback("Application_BeginRequest");
- ActivityHelper.StartAspNetActivity(this.TextMapPropagator, context, this.OnRequestStartedCallback);
+ ActivityHelper.StartAspNetActivity(Options.TextMapPropagator, context, Options.OnRequestStartedCallback);
}
private void Application_PreRequestHandlerExecute(object sender, EventArgs e)
@@ -168,13 +139,13 @@ private void Application_EndRequest(object sender, EventArgs e)
else
{
// Activity has never been started
- aspNetActivity = ActivityHelper.StartAspNetActivity(this.TextMapPropagator, context, this.OnRequestStartedCallback);
+ aspNetActivity = ActivityHelper.StartAspNetActivity(Options.TextMapPropagator, context, Options.OnRequestStartedCallback);
}
}
if (trackActivity)
{
- ActivityHelper.StopAspNetActivity(aspNetActivity, context, this.OnRequestStoppedCallback);
+ ActivityHelper.StopAspNetActivity(aspNetActivity, context, Options.OnRequestStoppedCallback);
}
}
@@ -189,10 +160,10 @@ private void Application_Error(object sender, EventArgs e)
{
if (!ActivityHelper.HasStarted(context, out Activity aspNetActivity))
{
- aspNetActivity = ActivityHelper.StartAspNetActivity(this.TextMapPropagator, context, this.OnRequestStartedCallback);
+ aspNetActivity = ActivityHelper.StartAspNetActivity(Options.TextMapPropagator, context, Options.OnRequestStartedCallback);
}
- ActivityHelper.WriteActivityException(aspNetActivity, exception, this.OnExceptionCallback);
+ ActivityHelper.WriteActivityException(aspNetActivity, context, exception, Options.OnExceptionCallback);
}
}
}
diff --git a/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/TelemetryHttpModuleOptions.cs b/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/TelemetryHttpModuleOptions.cs
new file mode 100644
index 00000000000..5110bfeb769
--- /dev/null
+++ b/src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/TelemetryHttpModuleOptions.cs
@@ -0,0 +1,61 @@
+//
+// Copyright The OpenTelemetry Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+using System;
+using System.Diagnostics;
+using System.Web;
+using OpenTelemetry.Context.Propagation;
+
+namespace OpenTelemetry.Instrumentation.AspNet
+{
+ ///
+ /// Stores options for the .
+ ///
+ public class TelemetryHttpModuleOptions
+ {
+ private TextMapPropagator textMapPropagator = new TraceContextPropagator();
+
+ internal TelemetryHttpModuleOptions()
+ {
+ }
+
+ ///
+ /// Gets or sets the to use to
+ /// extract from incoming requests.
+ ///
+ public TextMapPropagator TextMapPropagator
+ {
+ get => this.textMapPropagator;
+ set => this.textMapPropagator = value ?? throw new ArgumentNullException(nameof(value));
+ }
+
+ ///
+ /// Gets or sets a callback action to be fired when a request is started.
+ ///
+ public Action OnRequestStartedCallback { get; set; }
+
+ ///
+ /// Gets or sets a callback action to be fired when a request is stopped.
+ ///
+ public Action OnRequestStoppedCallback { get; set; }
+
+ ///
+ /// Gets or sets a callback action to be fired when an unhandled
+ /// exception is thrown processing a request.
+ ///
+ public Action OnExceptionCallback { get; set; }
+ }
+}
diff --git a/src/OpenTelemetry.Instrumentation.AspNet/.publicApi/net461/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Instrumentation.AspNet/.publicApi/net461/PublicAPI.Unshipped.txt
index 569931e171a..35b5f87638f 100644
--- a/src/OpenTelemetry.Instrumentation.AspNet/.publicApi/net461/PublicAPI.Unshipped.txt
+++ b/src/OpenTelemetry.Instrumentation.AspNet/.publicApi/net461/PublicAPI.Unshipped.txt
@@ -4,5 +4,7 @@ OpenTelemetry.Instrumentation.AspNet.AspNetInstrumentationOptions.Enrich.get ->
OpenTelemetry.Instrumentation.AspNet.AspNetInstrumentationOptions.Enrich.set -> void
OpenTelemetry.Instrumentation.AspNet.AspNetInstrumentationOptions.Filter.get -> System.Func
OpenTelemetry.Instrumentation.AspNet.AspNetInstrumentationOptions.Filter.set -> void
+OpenTelemetry.Instrumentation.AspNet.AspNetInstrumentationOptions.RecordException.get -> bool
+OpenTelemetry.Instrumentation.AspNet.AspNetInstrumentationOptions.RecordException.set -> void
OpenTelemetry.Trace.TracerProviderBuilderExtensions
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAspNetInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action configureAspNetInstrumentationOptions = null) -> OpenTelemetry.Trace.TracerProviderBuilder
diff --git a/src/OpenTelemetry.Instrumentation.AspNet/AspNetInstrumentation.cs b/src/OpenTelemetry.Instrumentation.AspNet/AspNetInstrumentation.cs
index 3360b08abea..2bd2a988be7 100644
--- a/src/OpenTelemetry.Instrumentation.AspNet/AspNetInstrumentation.cs
+++ b/src/OpenTelemetry.Instrumentation.AspNet/AspNetInstrumentation.cs
@@ -13,6 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
+
using System;
using OpenTelemetry.Instrumentation.AspNet.Implementation;
@@ -21,11 +22,9 @@ namespace OpenTelemetry.Instrumentation.AspNet
///
/// Asp.Net Requests instrumentation.
///
- internal class AspNetInstrumentation : IDisposable
+ internal sealed class AspNetInstrumentation : IDisposable
{
- internal const string AspNetDiagnosticListenerName = "OpenTelemetry.Instrumentation.AspNet.Telemetry";
-
- private readonly DiagnosticSourceSubscriber diagnosticSourceSubscriber;
+ private readonly HttpInListener httpInListener;
///
/// Initializes a new instance of the class.
@@ -33,17 +32,13 @@ internal class AspNetInstrumentation : IDisposable
/// Configuration options for ASP.NET instrumentation.
public AspNetInstrumentation(AspNetInstrumentationOptions options)
{
- this.diagnosticSourceSubscriber = new DiagnosticSourceSubscriber(
- name => new HttpInListener(name, options),
- listener => listener.Name == AspNetDiagnosticListenerName,
- null);
- this.diagnosticSourceSubscriber.Subscribe();
+ this.httpInListener = new HttpInListener(options);
}
///
public void Dispose()
{
- this.diagnosticSourceSubscriber?.Dispose();
+ this.httpInListener?.Dispose();
}
}
}
diff --git a/src/OpenTelemetry.Instrumentation.AspNet/AspNetInstrumentationOptions.cs b/src/OpenTelemetry.Instrumentation.AspNet/AspNetInstrumentationOptions.cs
index 613b3f922f7..4209ce23e05 100644
--- a/src/OpenTelemetry.Instrumentation.AspNet/AspNetInstrumentationOptions.cs
+++ b/src/OpenTelemetry.Instrumentation.AspNet/AspNetInstrumentationOptions.cs
@@ -26,11 +26,19 @@ namespace OpenTelemetry.Instrumentation.AspNet
public class AspNetInstrumentationOptions
{
///
- /// Gets or sets a Filter function that determines whether or not to collect telemetry about requests on a per request basis.
- /// The Filter gets the HttpContext, and should return a boolean.
- /// If Filter returns true, the request is collected.
- /// If Filter returns false or throw exception, the request is filtered out.
+ /// Gets or sets a filter callback function that determines on a per
+ /// request basis whether or not to collect telemetry.
///
+ ///
+ /// The filter callback receives the for the
+ /// current request and should return a boolean.
+ ///
+ /// - If filter returns the request is
+ /// collected.
+ /// - If filter returns or throws an
+ /// exception the request is filtered out (NOT collected).
+ ///
+ ///
public Func Filter { get; set; }
///
@@ -43,5 +51,13 @@ public class AspNetInstrumentationOptions
/// The type of this object depends on the event, which is given by the above parameter.
///
public Action Enrich { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether the exception will be recorded as ActivityEvent or not.
+ ///
+ ///
+ /// See: .
+ ///
+ public bool RecordException { get; set; }
}
}
diff --git a/src/OpenTelemetry.Instrumentation.AspNet/Implementation/AspNetInstrumentationEventSource.cs b/src/OpenTelemetry.Instrumentation.AspNet/Implementation/AspNetInstrumentationEventSource.cs
index c66228b74df..e7184746b22 100644
--- a/src/OpenTelemetry.Instrumentation.AspNet/Implementation/AspNetInstrumentationEventSource.cs
+++ b/src/OpenTelemetry.Instrumentation.AspNet/Implementation/AspNetInstrumentationEventSource.cs
@@ -24,50 +24,44 @@ namespace OpenTelemetry.Instrumentation.AspNet.Implementation
/// EventSource events emitted from the project.
///
[EventSource(Name = "OpenTelemetry-Instrumentation-AspNet")]
- internal class AspNetInstrumentationEventSource : EventSource
+ internal sealed class AspNetInstrumentationEventSource : EventSource
{
public static AspNetInstrumentationEventSource Log = new AspNetInstrumentationEventSource();
[NonEvent]
- public void RequestFilterException(Exception ex)
+ public void RequestFilterException(string operationName, Exception ex)
{
if (this.IsEnabled(EventLevel.Error, EventKeywords.All))
{
- this.RequestFilterException(ex.ToInvariantString());
+ this.RequestFilterException(operationName, ex.ToInvariantString());
}
}
- [Event(1, Message = "Payload is NULL in event '{1}' from handler '{0}', span will not be recorded.", Level = EventLevel.Warning)]
- public void NullPayload(string handlerName, string eventName)
- {
- this.WriteEvent(1, handlerName, eventName);
- }
-
- [Event(2, Message = "Request is filtered out.", Level = EventLevel.Verbose)]
- public void RequestIsFilteredOut(string eventName)
+ [NonEvent]
+ public void EnrichmentException(string eventName, Exception ex)
{
- this.WriteEvent(2, eventName);
+ if (this.IsEnabled(EventLevel.Error, EventKeywords.All))
+ {
+ this.EnrichmentException(eventName, ex.ToInvariantString());
+ }
}
- [Event(3, Message = "InstrumentationFilter threw exception. Request will not be collected. Exception {0}.", Level = EventLevel.Error)]
- public void RequestFilterException(string exception)
+ [Event(1, Message = "Request is filtered out and will not be collected. Operation='{0}'", Level = EventLevel.Verbose)]
+ public void RequestIsFilteredOut(string operationName)
{
- this.WriteEvent(3, exception);
+ this.WriteEvent(1, operationName);
}
- [NonEvent]
- public void EnrichmentException(Exception ex)
+ [Event(2, Message = "Filter callback threw an exception. Request will not be collected. Operation='{0}': {1}", Level = EventLevel.Error)]
+ public void RequestFilterException(string operationName, string exception)
{
- if (this.IsEnabled(EventLevel.Error, EventKeywords.All))
- {
- this.EnrichmentException(ex.ToInvariantString());
- }
+ this.WriteEvent(2, operationName, exception);
}
- [Event(4, Message = "Enrichment threw exception. Exception {0}.", Level = EventLevel.Error)]
- public void EnrichmentException(string exception)
+ [Event(3, Message = "Enrich callback threw an exception. Event='{0}': {1}", Level = EventLevel.Error)]
+ public void EnrichmentException(string eventName, string exception)
{
- this.WriteEvent(4, exception);
+ this.WriteEvent(3, eventName, exception);
}
}
}
diff --git a/src/OpenTelemetry.Instrumentation.AspNet/Implementation/HttpInListener.cs b/src/OpenTelemetry.Instrumentation.AspNet/Implementation/HttpInListener.cs
index 07867a036c1..3253f3c8f10 100644
--- a/src/OpenTelemetry.Instrumentation.AspNet/Implementation/HttpInListener.cs
+++ b/src/OpenTelemetry.Instrumentation.AspNet/Implementation/HttpInListener.cs
@@ -15,9 +15,7 @@
//
using System;
-using System.Collections.Generic;
using System.Diagnostics;
-using System.Reflection;
using System.Web;
using System.Web.Routing;
using OpenTelemetry.Context.Propagation;
@@ -25,93 +23,57 @@
namespace OpenTelemetry.Instrumentation.AspNet.Implementation
{
- internal class HttpInListener : ListenerHandler
+ internal sealed class HttpInListener : IDisposable
{
- internal const string ActivityNameByHttpInListener = "ActivityCreatedByHttpInListener";
- internal const string ActivityOperationName = "Microsoft.AspNet.HttpReqIn";
- internal static readonly AssemblyName AssemblyName = typeof(HttpInListener).Assembly.GetName();
- internal static readonly string ActivitySourceName = AssemblyName.Name;
- internal static readonly Version Version = AssemblyName.Version;
- internal static readonly ActivitySource ActivitySource = new ActivitySource(ActivitySourceName, Version.ToString());
- private static readonly Func> HttpRequestHeaderValuesGetter = (request, name) => request.Headers.GetValues(name);
private readonly PropertyFetcher