-
Notifications
You must be signed in to change notification settings - Fork 785
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New design for TelemetryHttpModule using ActivitySource + OpenTelemet…
…ry.API part 3 (#2256) * Update ASP.NET instrumentation to use the new TelemetryHttpModule. * Fixed TelemetryHttpModule not starting its Activity objects. Added an example of request suppression. * Tweaks an logging improvements. * Sealed AspNetInstrumentationEventSource. * Code review.
- Loading branch information
1 parent
a012493
commit 8b1fd83
Showing
16 changed files
with
268 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// <copyright file="SuppressInstrumentationHttpModule.cs" company="OpenTelemetry Authors"> | ||
// 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. | ||
// </copyright> | ||
|
||
using System; | ||
using System.Web; | ||
using OpenTelemetry; | ||
|
||
namespace Examples.AspNet | ||
{ | ||
/// <summary> | ||
/// A demo <see cref="IHttpModule"/> 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. | ||
/// </summary> | ||
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/TelemetryHttpModuleOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// <copyright file="TelemetryHttpModuleOptions.cs" company="OpenTelemetry Authors"> | ||
// 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. | ||
// </copyright> | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using System.Web; | ||
using OpenTelemetry.Context.Propagation; | ||
|
||
namespace OpenTelemetry.Instrumentation.AspNet | ||
{ | ||
/// <summary> | ||
/// Stores options for the <see cref="TelemetryHttpModule"/>. | ||
/// </summary> | ||
public class TelemetryHttpModuleOptions | ||
{ | ||
private TextMapPropagator textMapPropagator = new TraceContextPropagator(); | ||
|
||
internal TelemetryHttpModuleOptions() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the <see cref=" Context.Propagation.TextMapPropagator"/> to use to | ||
/// extract <see cref="PropagationContext"/> from incoming requests. | ||
/// </summary> | ||
public TextMapPropagator TextMapPropagator | ||
{ | ||
get => this.textMapPropagator; | ||
set => this.textMapPropagator = value ?? throw new ArgumentNullException(nameof(value)); | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets a callback action to be fired when a request is started. | ||
/// </summary> | ||
public Action<Activity, HttpContext> OnRequestStartedCallback { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a callback action to be fired when a request is stopped. | ||
/// </summary> | ||
public Action<Activity, HttpContext> OnRequestStoppedCallback { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a callback action to be fired when an unhandled | ||
/// exception is thrown processing a request. | ||
/// </summary> | ||
public Action<Activity, HttpContext, Exception> OnExceptionCallback { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.