Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.

Commit 6333cbd

Browse files
Moved DeploymentIdTelemetryEnricher to NuGet.Services.Logging (#328)
1 parent 14bc609 commit 6333cbd

8 files changed

Lines changed: 44 additions & 14 deletions

File tree

src/NuGet.Services.Logging/NuGet.Services.Logging.csproj

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,19 @@
5050
<ItemGroup>
5151
<Compile Include="ApplicationInsights.cs" />
5252
<Compile Include="ApplicationInsightsConfiguration.cs" />
53-
<Compile Include="DeploymentLabelEnricher.cs" />
53+
<Compile Include="TelemetryInitializers\DeploymentIdTelemetryEnricher.cs" />
54+
<Compile Include="TelemetryInitializers\DeploymentLabelEnricher.cs" />
5455
<Compile Include="DurationMetric.cs" />
55-
<Compile Include="ExceptionTelemetryProcessor.cs" />
56+
<Compile Include="TelemetryProcessors\ExceptionTelemetryProcessor.cs" />
5657
<Compile Include="Extensions\DiagnosticsTelemetryModuleExtensions.cs" />
5758
<Compile Include="LoggingSetup.cs" />
5859
<Compile Include="Properties\AssemblyInfo.cs" />
5960
<Compile Include="Properties\AssemblyInfo.*.cs" />
60-
<Compile Include="RequestTelemetryProcessor.cs" />
61+
<Compile Include="TelemetryProcessors\RequestTelemetryProcessor.cs" />
6162
<Compile Include="Extensions\TelemetryClientExtensions.cs" />
6263
<Compile Include="TelemetryClientWrapper.cs" />
63-
<Compile Include="TelemetryContextInitializer.cs" />
64+
<Compile Include="TelemetryInitializers\SupportPropertiesTelemetryInitializer.cs" />
65+
<Compile Include="TelemetryInitializers\TelemetryContextInitializer.cs" />
6466
</ItemGroup>
6567
<ItemGroup>
6668
<PackageReference Include="MicroBuild.Core">
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
namespace NuGet.Services.Logging
5+
{
6+
public class DeploymentIdTelemetryEnricher : SupportPropertiesTelemetryInitializer
7+
{
8+
public DeploymentIdTelemetryEnricher(string deploymentId)
9+
: base("CloudDeploymentId", deploymentId)
10+
{
11+
}
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
namespace NuGet.Services.Logging
5+
{
6+
public class DeploymentLabelEnricher : SupportPropertiesTelemetryInitializer
7+
{
8+
public DeploymentLabelEnricher(string deploymentLabel)
9+
: base("DeploymentLabel", deploymentLabel)
10+
{
11+
}
12+
}
13+
}

src/NuGet.Services.Logging/DeploymentLabelEnricher.cs renamed to src/NuGet.Services.Logging/TelemetryInitializers/SupportPropertiesTelemetryInitializer.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,31 @@
88

99
namespace NuGet.Services.Logging
1010
{
11-
public class DeploymentLabelEnricher : ITelemetryInitializer
11+
public abstract class SupportPropertiesTelemetryInitializer
12+
: ITelemetryInitializer
1213
{
13-
private const string DeploymentLabel = "DeploymentLabel";
14-
private readonly string _deploymentLabel;
15-
16-
public DeploymentLabelEnricher(string deploymentLabel)
14+
protected SupportPropertiesTelemetryInitializer(string propertyName, string propertyValue)
1715
{
18-
_deploymentLabel = deploymentLabel ?? throw new ArgumentNullException(nameof(deploymentLabel));
16+
PropertyName = propertyName ?? throw new ArgumentNullException(nameof(propertyName));
17+
PropertyValue = propertyValue ?? throw new ArgumentNullException(nameof(propertyValue));
1918
}
2019

20+
public string PropertyName { get; }
21+
public string PropertyValue { get; }
22+
2123
public void Initialize(ITelemetry telemetry)
2224
{
2325
if (!(telemetry is ISupportProperties itemTelemetry))
2426
{
2527
return;
2628
}
2729

28-
if (itemTelemetry.Properties.ContainsKey(DeploymentLabel))
30+
if (itemTelemetry.Properties.ContainsKey(PropertyName))
2931
{
3032
return;
3133
}
3234

33-
itemTelemetry.Properties.Add(DeploymentLabel, _deploymentLabel);
35+
itemTelemetry.Properties.Add(PropertyName, PropertyValue);
3436
}
3537
}
36-
}
38+
}

src/NuGet.Services.Logging/TelemetryContextInitializer.cs renamed to src/NuGet.Services.Logging/TelemetryInitializers/TelemetryContextInitializer.cs

File renamed without changes.

src/NuGet.Services.Logging/ExceptionTelemetryProcessor.cs renamed to src/NuGet.Services.Logging/TelemetryProcessors/ExceptionTelemetryProcessor.cs

File renamed without changes.

src/NuGet.Services.Logging/RequestTelemetryProcessor.cs renamed to src/NuGet.Services.Logging/TelemetryProcessors/RequestTelemetryProcessor.cs

File renamed without changes.

tests/NuGet.Services.Logging.Tests/DeploymentLabelEnricherTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class DeploymentLabelEnricherTests
2121
public void ConstructorThrowsWhenDeploymentLabelNull()
2222
{
2323
var ex = Assert.Throws<ArgumentNullException>(() => new DeploymentLabelEnricher(deploymentLabel: null));
24-
Assert.Equal("deploymentLabel", ex.ParamName);
24+
Assert.Equal("propertyValue", ex.ParamName);
2525
}
2626

2727
[Fact]

0 commit comments

Comments
 (0)