-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
track telemetry on api requests (#3355)
* start tracking min,max,total bytes seen on stow again and # of instances * add useragent from request header to api request telemetry
- Loading branch information
Showing
8 changed files
with
167 additions
and
4 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
src/Microsoft.Health.Dicom.Api/Features/Telemetry/DicomTelemetry.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,11 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
namespace Microsoft.Health.Dicom.Api.Features.Telemetry; | ||
|
||
internal static class DicomTelemetry | ||
{ | ||
public const string ContextItemPrefix = "Dicom_"; | ||
} |
37 changes: 37 additions & 0 deletions
37
src/Microsoft.Health.Dicom.Api/Features/Telemetry/HttpDicomTelemetryClient.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,37 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using EnsureThat; | ||
using Microsoft.ApplicationInsights; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Health.Dicom.Core.Features.Telemetry; | ||
|
||
namespace Microsoft.Health.Dicom.Api.Features.Telemetry; | ||
|
||
internal class HttpDicomTelemetryClient : IDicomTelemetryClient | ||
{ | ||
private readonly TelemetryClient _telemetryClient; | ||
private readonly IHttpContextAccessor _httpContextAccessor; | ||
|
||
public HttpDicomTelemetryClient(TelemetryClient telemetryClient, IHttpContextAccessor httpContextAccessor) | ||
{ | ||
_telemetryClient = EnsureArg.IsNotNull(telemetryClient, nameof(telemetryClient)); | ||
_httpContextAccessor = EnsureArg.IsNotNull(httpContextAccessor, nameof(httpContextAccessor)); | ||
} | ||
|
||
public void TrackMetric(string name, int value) | ||
{ | ||
// Note: Context Items are prefixed so that the telemetry initializer knows which items to include in the telemetry | ||
_httpContextAccessor.HttpContext.Items[DicomTelemetry.ContextItemPrefix + name] = value; | ||
_telemetryClient.GetMetric(name).TrackValue(value); | ||
} | ||
|
||
public void TrackMetric(string name, long value) | ||
{ | ||
// Note: Context Items are prefixed so that the telemetry initializer knows which items to include in the telemetry | ||
_httpContextAccessor.HttpContext.Items[DicomTelemetry.ContextItemPrefix + name] = value; | ||
_telemetryClient.GetMetric(name).TrackValue(value); | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
src/Microsoft.Health.Dicom.Core/Extensions/DicomTelemetryClientExtensions.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,36 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using EnsureThat; | ||
using Microsoft.Health.Dicom.Core.Features.Telemetry; | ||
|
||
namespace Microsoft.Health.Dicom.Core.Extensions; | ||
|
||
internal static class DicomTelemetryClientExtensions | ||
{ | ||
public static void TrackInstanceCount(this IDicomTelemetryClient telemetryClient, int count) | ||
{ | ||
EnsureArg.IsNotNull(telemetryClient, nameof(telemetryClient)); | ||
telemetryClient.TrackMetric("InstanceCount", count); | ||
} | ||
|
||
public static void TrackTotalInstanceBytes(this IDicomTelemetryClient telemetryClient, long bytes) | ||
{ | ||
EnsureArg.IsNotNull(telemetryClient, nameof(telemetryClient)); | ||
telemetryClient.TrackMetric("TotalInstanceBytes", bytes); | ||
} | ||
|
||
public static void TrackMinInstanceBytes(this IDicomTelemetryClient telemetryClient, long bytes) | ||
{ | ||
EnsureArg.IsNotNull(telemetryClient, nameof(telemetryClient)); | ||
telemetryClient.TrackMetric("MinInstanceBytes", bytes); | ||
} | ||
|
||
public static void TrackMaxInstanceBytes(this IDicomTelemetryClient telemetryClient, long bytes) | ||
{ | ||
EnsureArg.IsNotNull(telemetryClient, nameof(telemetryClient)); | ||
telemetryClient.TrackMetric("MaxInstanceBytes", bytes); | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
src/Microsoft.Health.Dicom.Core/Features/Telemetry/IDicomTelemetryClient.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,14 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
|
||
namespace Microsoft.Health.Dicom.Core.Features.Telemetry; | ||
|
||
public interface IDicomTelemetryClient | ||
{ | ||
void TrackMetric(string name, int value); | ||
|
||
void TrackMetric(string name, long value); | ||
} |