Skip to content

Commit

Permalink
Add initial support for tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
cezarypiatek committed May 6, 2024
1 parent 31db4d6 commit 6a3f07d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/NScenario/NScenario.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="8.0.1" />
<PackageReference Include="System.Text.Json" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
Expand Down
33 changes: 33 additions & 0 deletions src/NScenario/StepExecutors/InstrumentationScenarioStepExecutor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Diagnostics;
using System.Threading.Tasks;

namespace NScenario.StepExecutors;

public static class NScenarioInstrumentation
{
public static ActivitySource DiagnosticSource = new ActivitySource("NScenario");
}

public class InstrumentationScenarioStepExecutor : IScenarioStepExecutor
{
private readonly IScenarioStepExecutor _scenarioStepExecutorImplementation;


public InstrumentationScenarioStepExecutor(IScenarioStepExecutor scenarioStepExecutorImplementation)
{
_scenarioStepExecutorImplementation = scenarioStepExecutorImplementation;
}

public async Task Step(string scenarioName, string stepDescription, Func<Task> action, StepContext stepContext)
{
using var activity = NScenarioInstrumentation.DiagnosticSource.StartActivity(name: stepDescription);
await _scenarioStepExecutorImplementation.Step(scenarioName, stepDescription, action, stepContext);
}

public async Task Step(string scenarioName, string stepDescription, Action action, StepContext stepContext)
{
using var activity = NScenarioInstrumentation.DiagnosticSource.StartActivity(name: stepDescription);
await _scenarioStepExecutorImplementation.Step(scenarioName, stepDescription, action, stepContext);
}
}
1 change: 1 addition & 0 deletions src/NScenario/TestScenarioFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ private static IScenarioStepExecutor BuildScenarioStepExecutor(IScenarioOutputWr
stepExecutorBuilder.WrapWith(u => new IndentionScenarioStepExecutor(u));
stepExecutorBuilder.WrapWith(u => new PrefixedScenarioStepExecutor(u, scenarioPrefix, stepPrefix));
stepExecutorBuilder.WrapWith(u => new OrderedScenarioStepExecutor(u));
stepExecutorBuilder.WrapWith(u => new InstrumentationScenarioStepExecutor (u));
var stepExecutor = stepExecutorBuilder.Build();
return stepExecutor;
}
Expand Down

0 comments on commit 6a3f07d

Please sign in to comment.