-
-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Opentelemetry #497
base: main
Are you sure you want to change the base?
WIP: Opentelemetry #497
Conversation
This can demonstrate tests showing in OTel
Expecto/Expecto.Impl.fs
Outdated
@@ -9,6 +10,20 @@ open Expecto.Logging.Message | |||
open Helpers | |||
open Mono.Cecil | |||
|
|||
//! The other option is to use a dedicated activity source for Expecto instead of adding it to the config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One option is to have Expecto have a dedicate ActivitySource, the other is to add it the the Expecto config and allow a user to pass it along.
Expecto/Expecto.Impl.fs
Outdated
// only problem is the only way to update the config is by using the CLIArguments currently | ||
// we would have to add a new CLIArgument but that doesn't really work as it's not a reallyCLI option | ||
// or have another way of updating the config after it's been created | ||
activitySource : ActivitySource option |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned, we can have an activity source in the config but there's not really a function that lets people update the config.
It might be more tricky to do this option if people are using the dotnet test
integration so maybe a dedicated source is appropriate.
Expecto/Expecto.Impl.fs
Outdated
@@ -559,8 +580,63 @@ module Impl = | |||
} | |||
} | |||
|
|||
let inline internal setStatus (status : ActivityStatusCode) (span : Activity) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of helper functions. Don't have to live here, just here for the moment.
Expecto/Expecto.Impl.fs
Outdated
let span = | ||
config.activitySource | ||
|> createActivity (config.joinWith.format test.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the starting point for creating an span. Later we add additional information to it based on whether we pass/fail/ignore.
Expecto.Tests/Main.fs
Outdated
use traceProvider = | ||
Sdk | ||
.CreateTracerProviderBuilder() | ||
.AddSource(serviceName) | ||
.SetResourceBuilder(resourceBuilder ) | ||
.AddOtlpExporter() | ||
.Build() | ||
let tracer = traceProvider.GetTracer(serviceName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is adding the OpenTelemetry Exporter to the test project, mostly for demo purposes. Could create a separate project if desired.
Expecto.Tests/Main.fs
Outdated
let test = | ||
Impl.testFromThisAssembly() | ||
|> Option.orDefault (TestList ([], Normal)) | ||
|> Test.shuffle "." | ||
runTestsWithCLIArgs [NUnit_Summary "bin/Expecto.Tests.TestResults.xml"] args test | ||
runTestsWithCLIArgs [NUnit_Summary "bin/Expecto.Tests.TestResults.xml"; CLIArguments.ActivitySource activitySource] args test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here a consumer would pass in the ActivitySource. Otherwise they'd have to add the dedicated Expecto one to the .AddSource
call on line 29.
I'm still thinking over generalization approaches. I haven't found a clear nice answer yet. Have you considered how the current span approach would behave with stress testing? |
Demonstrate OpenTelemetry extension as a transform
Oh one of the things missing too is how to integrate with |
Good point. That's a problem for shuffle and filter too. Seems like exposing such a method would be desirable for library extension. |
Upon review, I think I got wrap up in my own line of thought and didn't interpret your statement correctly. I'm not sure I see the incompatibility with |
As far as I know, dotnet test doesn't care whats in your main/entrypoint. Yolodev uses Expecto.Impl.testFromAssembly to find tests. I suppose you can call Specifically the tricks that @baronfel has in https://github.com/baronfel/otel-startup-hook |
Interesting. I hadn't thought of such a limitation. Tests names can be listed via dotnet run, but that doesn't provide fully-hydrated Test records. |
So creating the TraceProvider statically: do
let provider = traceProvider()
AppDomain.CurrentDomain.ProcessExit.Add(fun _ -> provider.Dispose()) And After that, this does work for |
I used the Aspire dashboard. You can run it via docker:
Then you can run the
Expecto.Tests
project. It should export OpenTelemetry traces to Aspire.Example of traces for tests showing up:
Clicking View on one of them with a red dot (red dot indicates there were exceptions/errors):
Clicking on the top span, you can see details about its run.
Clicking on one of the child spans you can see details such as Exception data.
I didn't show it here but you can also export logs that are associated with a test trace.