-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: app insights - add grouped operation name
- Loading branch information
Showing
5 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/Tracing/ApplicationInsights.AspNetCore/OperationNameTelemetryInitializer.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,31 @@ | ||
using DotVVM.Framework.Hosting; | ||
using Microsoft.ApplicationInsights.DataContracts; | ||
using Microsoft.ApplicationInsights.Extensibility; | ||
using Microsoft.ApplicationInsights.Channel; | ||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace DotVVM.Tracing.ApplicationInsights.AspNetCore; | ||
|
||
public class OperationNameTelemetryInitializer : ITelemetryInitializer | ||
{ | ||
private readonly IHttpContextAccessor _accessor; | ||
|
||
public OperationNameTelemetryInitializer(IHttpContextAccessor accessor) | ||
{ | ||
_accessor = accessor; | ||
} | ||
|
||
public void Initialize(ITelemetry telemetry) | ||
{ | ||
var url = _accessor.HttpContext?.GetDotvvmContext()?.Route?.Url; | ||
if (string.IsNullOrWhiteSpace(url) == false && telemetry is RequestTelemetry) | ||
{ | ||
var method = _accessor.HttpContext.Request.Method; | ||
var operationName = $"{method} /{url}"; | ||
|
||
var requestTelemetry = telemetry as RequestTelemetry; | ||
requestTelemetry.Name = operationName; | ||
requestTelemetry.Context.Operation.Name = operationName; | ||
} | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
src/Tracing/ApplicationInsights.Owin/OperationNameTelemetryInitializer.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,24 @@ | ||
using System.Web; | ||
using DotVVM.Framework.Hosting; | ||
using Microsoft.ApplicationInsights.DataContracts; | ||
using Microsoft.ApplicationInsights.Extensibility; | ||
using Microsoft.ApplicationInsights.Channel; | ||
|
||
namespace DotVVM.Tracing.ApplicationInsights.Owin; | ||
|
||
public class OperationNameTelemetryInitializer : ITelemetryInitializer | ||
{ | ||
public void Initialize(ITelemetry telemetry) | ||
{ | ||
var url = HttpContext.Current?.GetOwinContext()?.GetDotvvmContext()?.Route?.Url; | ||
if (string.IsNullOrWhiteSpace(url) == false && telemetry is RequestTelemetry) | ||
{ | ||
var method = HttpContext.Current.Request.HttpMethod; | ||
var operationName = $"{method} /{url}"; | ||
|
||
var requestTelemetry = telemetry as RequestTelemetry; | ||
requestTelemetry.Name = operationName; | ||
requestTelemetry.Context.Operation.Name = operationName; | ||
} | ||
} | ||
} |
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