-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1807 from mirecad/feature/appinisghts-opration-name
Use grouped operation name in application insights telemetry
- Loading branch information
Showing
5 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
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,32 @@ | ||
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 context = _accessor.HttpContext; | ||
var url = context?.GetDotvvmContext()?.Route?.Url; | ||
if (url != null && telemetry is RequestTelemetry) | ||
{ | ||
var method = context.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
25 changes: 25 additions & 0 deletions
25
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,25 @@ | ||
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 context = HttpContext.Current; | ||
var url = context?.GetOwinContext()?.GetDotvvmContext()?.Route?.Url; | ||
if (url != null && telemetry is RequestTelemetry) | ||
{ | ||
var method = context.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