Skip to content

Commit 52f90d0

Browse files
authored
Add managed entry point to process info and collection rule filters (#7984)
1 parent c60ab09 commit 52f90d0

File tree

21 files changed

+269
-10
lines changed

21 files changed

+269
-10
lines changed

documentation/api/definitions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ Some properties will have non-null values for processes that are running on .NET
530530
| `commandLine` | string | The command line of the process (includes process path and arguments) |
531531
| `operatingSystem` | string | `.NET 5+` The operating system on which the process is running (e.g. `windows`, `linux`, `macos`).<br/>`.NET Core 3.1` A value of `null`. |
532532
| `processArchitecture` | string | `.NET 5+` The architecture of the process (e.g. `x64`, `x86`).<br/>`.NET Core 3.1` A value of `null`. |
533+
| `managedEntryPointAssemblyName` | string | `9.1+` The name of the managed entry point assembly. The entry point assembly is typically the assembly that contains the `Program` class for the application. |
533534

534535
The `uid` property is useful for uniquely identifying a process when it is running in an environment where the process ID may not be unique (e.g. multiple containers within a Kubernetes pod will have entrypoint processes with process ID 1).
535536

documentation/api/process-get.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ Content-Type: application/json
7373
"name": "dotnet",
7474
"commandLine": "\"C:\\Program Files\\dotnet\\dotnet.exe\" ConsoleApp1.dll",
7575
"operatingSystem": "Windows",
76-
"processArchitecture": "x64"
76+
"processArchitecture": "x64",
77+
"managedEntryPointAssemblyName": "ConsoleApp1"
7778
}
7879
```
7980

documentation/configuration/default-process-configuration.md

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Default process configuration is used to determine which process is used for met
44

55
| Name | Type | Description |
66
|---|---|---|
7-
| Key | string | Specifies which criteria to match on the process. Can be `ProcessId`, `ProcessName`, `CommandLine`. |
7+
| Key | string | Specifies which criteria to match on the process. Can be `ProcessId`, `ProcessName`, `CommandLine`, `ManagedEntryPointAssemblyName`. |
88
| Value | string | The value to match against the process. |
99
| MatchType | string | The type of match to perform. Can be `Exact` or `Contains` for sub-string matching. Both are case-insensitive.|
1010

@@ -16,6 +16,7 @@ Optionally, a shorthand format allows you to omit the `Key` and `Value` terms an
1616
| ProcessId | string | Specifies that the corresponding value is the expected `ProcessId`. |
1717
| ProcessName | string | Specifies that the corresponding value is the expected `ProcessName`. |
1818
| CommandLine | string | Specifies that the corresponding value is the expected `CommandLine`.|
19+
| ManagedEntryPointAssemblyName | string | Specifies that the corresponding value is the expected `ManagedEntryPointAssemblyName`. |
1920

2021
## Examples
2122

@@ -158,3 +159,73 @@ Optionally, a shorthand format allows you to omit the `Key` and `Value` terms an
158159
value: "1"
159160
```
160161
</details>
162+
163+
### Match MyApp.dll Entry Point
164+
165+
<details>
166+
<summary>JSON</summary>
167+
168+
```json
169+
{
170+
"DefaultProcess": {
171+
"Filters": [{
172+
"Key": "ManagedEntryPointAssemblyName",
173+
"Value": "MyApp"
174+
}]
175+
},
176+
}
177+
```
178+
</details>
179+
180+
<details>
181+
<summary>Kubernetes ConfigMap</summary>
182+
183+
```yaml
184+
DefaultProcess__Filters__0__Key: "ManagedEntryPointAssemblyName"
185+
DefaultProcess__Filters__0__Value: "MyApp"
186+
```
187+
</details>
188+
189+
<details>
190+
<summary>Kubernetes Environment Variables</summary>
191+
192+
```yaml
193+
- name: DotnetMonitor_DefaultProcess__Filters__0__Key
194+
value: "ManagedEntryPointAssemblyName"
195+
- name: DotnetMonitor_DefaultProcess__Filters__0__Value
196+
value: "MyApp"
197+
```
198+
</details>
199+
200+
### Match MyApp.dll Entry Point (Shorthand)
201+
202+
<details>
203+
<summary>JSON</summary>
204+
205+
```json
206+
{
207+
"DefaultProcess": {
208+
"Filters": [{
209+
"ManagedEntryPointAssemblyName": "MyApp"
210+
}]
211+
},
212+
}
213+
```
214+
</details>
215+
216+
<details>
217+
<summary>Kubernetes ConfigMap</summary>
218+
219+
```yaml
220+
DefaultProcess__Filters__0__ManagedEntryPointAssemblyName: "MyApp"
221+
```
222+
</details>
223+
224+
<details>
225+
<summary>Kubernetes Environment Variables</summary>
226+
227+
```yaml
228+
- name: DotnetMonitor_DefaultProcess__Filters__0__ManagedEntryPointAssemblyName
229+
value: "MyApp"
230+
```
231+
</details>

documentation/openapi.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2219,6 +2219,10 @@
22192219
"processArchitecture": {
22202220
"type": "string",
22212221
"nullable": true
2222+
},
2223+
"managedEntryPointAssemblyName": {
2224+
"type": "string",
2225+
"nullable": true
22222226
}
22232227
},
22242228
"additionalProperties": false

documentation/schema.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,13 @@
594594
"string"
595595
],
596596
"description": "Performs a match based on the contents of the command passed to launch the process on the system; this typically includes the executable path and arguments to the process."
597+
},
598+
"ManagedEntryPointAssemblyName": {
599+
"type": [
600+
"null",
601+
"string"
602+
],
603+
"description": "Performs a match based on the name of the managed entry point assembly of the process."
597604
}
598605
}
599606
},
@@ -603,12 +610,14 @@
603610
"x-enumNames": [
604611
"ProcessId",
605612
"ProcessName",
606-
"CommandLine"
613+
"CommandLine",
614+
"ManagedEntryPointAssemblyName"
607615
],
608616
"enum": [
609617
"ProcessId",
610618
"ProcessName",
611-
"CommandLine"
619+
"CommandLine",
620+
"ManagedEntryPointAssemblyName"
612621
]
613622
},
614623
"ProcessFilterType": {

src/Microsoft.Diagnostics.Monitoring.Options/OptionsDisplayStrings.Designer.cs

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Microsoft.Diagnostics.Monitoring.Options/OptionsDisplayStrings.resx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,4 +776,8 @@
776776
<data name="DisplayAttributeDescription_CollectArtifactOptions_ArtifactName" xml:space="preserve">
777777
<value>The name of the generated artifact.</value>
778778
</data>
779+
<data name="DisplayAttributeDescription_ProcessFilterDescriptor_ManagedEntryPointAssemblyName" xml:space="preserve">
780+
<value>Performs a match based on the name of the managed entry point assembly of the process.</value>
781+
<comment>The description provided for the ManagedEntryPointAssemblyName parameter on ProcessFilterDescriptor.</comment>
782+
</data>
779783
</root>

src/Microsoft.Diagnostics.Monitoring.Options/ProcessFilterOptions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public enum ProcessFilterKey
2121
ResourceType = typeof(OptionsDisplayStrings),
2222
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_ProcessFilterKey_CommandLine))]
2323
CommandLine,
24+
ManagedEntryPointAssemblyName
2425
}
2526

2627
public enum ProcessFilterType
@@ -76,6 +77,11 @@ public sealed partial class ProcessFilterDescriptor
7677
ResourceType = typeof(OptionsDisplayStrings),
7778
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_ProcessFilterDescriptor_CommandLine))]
7879
public string? CommandLine { get; set; }
80+
81+
[Display(
82+
ResourceType = typeof(OptionsDisplayStrings),
83+
Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_ProcessFilterDescriptor_ManagedEntryPointAssemblyName))]
84+
public string? ManagedEntryPointAssemblyName { get; set; }
7985
}
8086

8187
partial class ProcessFilterDescriptor : IValidatableObject
@@ -84,7 +90,7 @@ IEnumerable<ValidationResult> IValidatableObject.Validate(ValidationContext vali
8490
{
8591
List<ValidationResult> results = new();
8692

87-
if (string.IsNullOrWhiteSpace(CommandLine) && string.IsNullOrWhiteSpace(ProcessId) && string.IsNullOrWhiteSpace(ProcessName))
93+
if (string.IsNullOrWhiteSpace(CommandLine) && string.IsNullOrWhiteSpace(ProcessId) && string.IsNullOrWhiteSpace(ProcessName) && string.IsNullOrWhiteSpace(ManagedEntryPointAssemblyName))
8894
{
8995
if (string.IsNullOrWhiteSpace(Value))
9096
{

src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/DiagController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ public Task<ActionResult<IEnumerable<ProcessIdentifier>>> GetProcesses()
140140
Name = processInfo.ProcessName,
141141
OperatingSystem = processInfo.OperatingSystem,
142142
ProcessArchitecture = processInfo.ProcessArchitecture,
143+
ManagedEntryPointAssemblyName = processInfo.ManagedEntryPointAssemblyName,
143144
Pid = processInfo.EndpointInfo.ProcessId,
144145
Uid = processInfo.EndpointInfo.RuntimeInstanceCookie
145146
};

src/Microsoft.Diagnostics.Monitoring.WebApi/DiagProcessFilter.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ private static DiagProcessFilterEntry TransformDescriptor(ProcessFilterDescripto
9999
Value = processFilterDescriptor.CommandLine
100100
};
101101
}
102+
else if (!string.IsNullOrWhiteSpace(processFilterDescriptor.ManagedEntryPointAssemblyName))
103+
{
104+
return new DiagProcessFilterEntry
105+
{
106+
Criteria = DiagProcessFilterCriteria.ManagedEntryPointAssemblyName,
107+
MatchType = (processFilterDescriptor.MatchType == ProcessFilterType.Exact) ? DiagProcessFilterMatchType.Exact : DiagProcessFilterMatchType.Contains,
108+
Value = processFilterDescriptor.ManagedEntryPointAssemblyName
109+
};
110+
}
102111

103112
string filterValue = processFilterDescriptor.Value!; // Guaranteed not to be null by ProcessFilterDescriptor.Validate.
104113
switch (processFilterDescriptor.Key)
@@ -119,6 +128,13 @@ private static DiagProcessFilterEntry TransformDescriptor(ProcessFilterDescripto
119128
MatchType = (processFilterDescriptor.MatchType == ProcessFilterType.Exact) ? DiagProcessFilterMatchType.Exact : DiagProcessFilterMatchType.Contains,
120129
Value = filterValue
121130
};
131+
case ProcessFilterKey.ManagedEntryPointAssemblyName:
132+
return new DiagProcessFilterEntry
133+
{
134+
Criteria = DiagProcessFilterCriteria.ManagedEntryPointAssemblyName,
135+
MatchType = (processFilterDescriptor.MatchType == ProcessFilterType.Exact) ? DiagProcessFilterMatchType.Exact : DiagProcessFilterMatchType.Contains,
136+
Value = filterValue
137+
};
122138
default:
123139
throw new ArgumentException(
124140
string.Format(
@@ -151,6 +167,8 @@ public bool MatchFilter(IProcessInfo processInfo)
151167
return Compare(processInfo.CommandLine);
152168
case DiagProcessFilterCriteria.ProcessName:
153169
return Compare(processInfo.ProcessName);
170+
case DiagProcessFilterCriteria.ManagedEntryPointAssemblyName:
171+
return Compare(processInfo.ManagedEntryPointAssemblyName);
154172
default:
155173
Debug.Fail($"Unexpected {nameof(DiagProcessFilterCriteria)}: {this.Criteria}");
156174
break;
@@ -190,7 +208,8 @@ internal enum DiagProcessFilterCriteria
190208
ProcessId,
191209
RuntimeId,
192210
CommandLine,
193-
ProcessName
211+
ProcessName,
212+
ManagedEntryPointAssemblyName
194213
}
195214

196215
internal enum DiagProcessFilterMatchType

0 commit comments

Comments
 (0)