Skip to content

Commit 5f997ce

Browse files
Allow to attach to out of process collector (#664)
Allow to attach to out of process collector
1 parent c27f039 commit 5f997ce

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Documentation/Troubleshooting.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,12 @@ You'll get this message during test run
235235
dotnet test -p:Include="[test_coverage.]" -p:Exclude="[*.Test.*]*" -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=coverage.cobertura.xml
236236
Coverlet msbuild instrumentation task debugging is enabled. Please attach debugger to process to continue
237237
Process Id: 29228 Name: dotnet
238-
```
238+
```
239+
240+
## Enable collector instrumentation debugging
241+
242+
You can live attach and debug collectors with `COVERLET_DATACOLLECTOR_OUTOFPROC_DEBUG` env variable
243+
```
244+
set COVERLET_DATACOLLECTOR_OUTOFPROC_DEBUG=1
245+
```
246+
You will be asket to attach a debugger through UI popup.

src/coverlet.collector/DataCollection/CoverletCoverageCollector.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ internal CoverletCoverageCollector(TestPlatformEqtTrace eqtTrace, ICoverageWrapp
3737
_countDownEventFactory = countDownEventFactory;
3838
}
3939

40+
private void AttachDebugger()
41+
{
42+
if (int.TryParse(Environment.GetEnvironmentVariable("COVERLET_DATACOLLECTOR_OUTOFPROC_DEBUG"), out int result) && result == 1)
43+
{
44+
Debugger.Launch();
45+
Debugger.Break();
46+
}
47+
}
48+
4049
/// <summary>
4150
/// Initializes data collector
4251
/// </summary>
@@ -52,6 +61,9 @@ public override void Initialize(
5261
DataCollectionLogger logger,
5362
DataCollectionEnvironmentContext environmentContext)
5463
{
64+
65+
AttachDebugger();
66+
5567
if (_eqtTrace.IsInfoEnabled)
5668
{
5769
_eqtTrace.Info("Initializing {0} with configuration: '{1}'", CoverletConstants.DataCollectorName, configurationElement?.OuterXml);

0 commit comments

Comments
 (0)