Skip to content

Commit

Permalink
enable otel in tests on demand
Browse files Browse the repository at this point in the history
  • Loading branch information
majocha committed Jan 29, 2025
1 parent d0c5ca2 commit d29a0a6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/FSharp.Test.Utilities/FSharp.Test.Utilities.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<!--Extra xUnit customizations, not required for the test suite to work, but can speed up local test runs and help with debugging.-->
<DefineConstants>XUNIT_EXTRAS</DefineConstants>
<!--Uncomment to enable OpenTelemetry instrumentation for the test suite.-->
<!--<DefineConstants>OTEL</DefineConstants>-->
</PropertyGroup>

<PropertyGroup Condition="'$(BUILDING_USING_DOTNET)' == 'true'">
Expand Down
5 changes: 5 additions & 0 deletions tests/FSharp.Test.Utilities/XunitHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,24 @@ type FSharpXunitFramework(sink: IMessageSink) =
AssemblyResolver.addResolver ()
#endif

// Uncomment definition in project file to enable OpenTelemetry tracing.
#if OTEL
let traceProvider =
Sdk.CreateTracerProviderBuilder()
.AddSource(ActivityNames.FscSourceName)
.SetResourceBuilder(
ResourceBuilder.CreateDefault().AddService(serviceName="F#", serviceVersion = "1.0.0"))
.AddOtlpExporter()
.Build()
#endif

interface IDisposable with
member _.Dispose() =
cleanUpTemporaryDirectoryOfThisTestRun ()
#if OTEL
traceProvider.ForceFlush() |> ignore
traceProvider.Dispose()
#endif
base.Dispose()

// Group test run under single activity, to make traces more readable.
Expand Down

0 comments on commit d29a0a6

Please sign in to comment.