Skip to content

[Examples] Add F# example#6875

Merged
rajkumar-rangaraj merged 3 commits into
open-telemetry:mainfrom
martincostello:fsharp-example
Feb 26, 2026
Merged

[Examples] Add F# example#6875
rajkumar-rangaraj merged 3 commits into
open-telemetry:mainfrom
martincostello:fsharp-example

Conversation

@martincostello
Copy link
Copy Markdown
Member

@martincostello martincostello commented Feb 5, 2026

Changes

Add an example for an ASP.NET Core application using F#.

This was inspired by a conversation @alanwest and myself had at OTel Unplugged with an end-user who wondered why there wasn't an F# SDK for OpenTelemetry.

The example here is based on the AspNetCore example, and then converted with the help of GitHub Copilot. I'm no F# developer, so it might not be as idiomatic as it could be.

While working on this I found some issues with the Docker Compose setup copied from the ASP.NET Core example so I'm going to park this for now while I fix that #6877.

Feedback welcome.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@github-actions github-actions Bot added infra Infra work - CI/CD, code coverage, linters dependencies Pull requests that update a dependency file documentation Documentation related labels Feb 5, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.45%. Comparing base (3487b5a) to head (7c72482).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6875      +/-   ##
==========================================
- Coverage   88.54%   88.45%   -0.09%     
==========================================
  Files         263      263              
  Lines       12383    12383              
==========================================
- Hits        10964    10953      -11     
- Misses       1419     1430      +11     
Flag Coverage Δ
unittests-Project-Experimental 88.29% <ø> (+0.01%) ⬆️
unittests-Project-Stable 88.40% <ø> (-0.09%) ⬇️
unittests-Solution 88.25% <ø> (-0.14%) ⬇️
unittests-UnstableCoreLibraries-Experimental 41.80% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.
see 5 files with indirect coverage changes

@martincostello
Copy link
Copy Markdown
Member Author

Paging some F# fans I know in case they have any opinions 😃

/cc @slang25 @MrBliz @baronfel

Copy link
Copy Markdown

@baronfel baronfel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good, but I have a couple tiny notes to clean it up a bit.

Comment thread examples/FSharp/InstrumentationSource.fs
Comment thread examples/FSharp/Controllers/WeatherForecastController.fs Outdated
@martincostello martincostello marked this pull request as ready for review February 10, 2026 11:05
@martincostello martincostello requested a review from a team as a code owner February 10, 2026 11:05
Copilot AI review requested due to automatic review settings February 10, 2026 11:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new F# ASP.NET Core Web API example demonstrating OpenTelemetry logging, metrics, and tracing, aligning with the existing C# AspNetCore example and wiring it into the repo solution/build.

Changes:

  • Introduces a new F# example app (project, program, controller, instrumentation helper, model) with OTLP/Console/Prometheus switching via configuration.
  • Adds supporting example assets (README, appsettings, docker-compose for grafana/otel-lgtm).
  • Wires the new example into the solution and central package versions.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
examples/FSharp/docker-compose.yaml Adds docker-compose to run grafana/otel-lgtm dependencies for the example.
examples/FSharp/appsettings.json Adds configuration for exporters, OTLP endpoint, and instrumentation options.
examples/FSharp/WeatherForecast.fs Adds the sample model used by the controller.
examples/FSharp/README.md Documents running the F# example and optional OTLP export + Docker deps.
examples/FSharp/Program.fs Configures OpenTelemetry logging/metrics/tracing and ASP.NET Core pipeline.
examples/FSharp/InstrumentationSource.fs Adds ActivitySource/Meter/counter holder for manual instrumentation.
examples/FSharp/Examples.FSharp.fsproj Adds the new F# example project and dependencies.
examples/FSharp/Controllers/WeatherForecastController.fs Adds the sample controller emitting telemetry and logs.
OpenTelemetry.slnx Adds the new F# example project to the solution.
Directory.Packages.props Adds central package version entry for FSharp.Core.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread examples/FSharp/Controllers/WeatherForecastController.fs
Comment thread examples/FSharp/Program.fs
Comment thread examples/FSharp/Examples.FSharp.fsproj
Add an example for an ASP.NET Core application using F#.
@rajkumar-rangaraj
Copy link
Copy Markdown
Member

Before approving though, I'd like a broader maintainer discussion on whether we want to commit to maintaining F# examples in this repo going forward. The concern isn't the code itself, but ensuring we have enough F# familiarity across the team to keep it healthy over time.

cc: @alanwest @Kielek

@martincostello
Copy link
Copy Markdown
Member Author

The intention here was just to have a F# example, rather than have an F# version of every C# example.

This was driven by conversation with a user at OTel unplugged that the .NET SDK was just for C#, so the F# example was intended to illustrate that's not the case.

@cijothomas
Copy link
Copy Markdown
Member

https://github.com/census-instrumentation/opencensus-csharp
https://github.com/opentracing/opentracing-csharp

All of our predecessors named the repo "csharp", but we named it "dotnet" 🤣 indicating it should work for c# or f# . (Don't think this was a conscious decision though. I was not involved in the repo at the creation time).

This was driven by conversation with a user at OTel unplugged that the .NET SDK was just for C#, so the F# example was intended to illustrate that's not the case.

Unless this is a more widespread feedback, I suggest to avoid F# example. But no strong objections if we want a single F# example, not for everything.

@martincostello
Copy link
Copy Markdown
Member Author

indicating it should work for c# or f#

I think the example is also good to help validate that it does indeed work with F#.

It's not the case here, but for example with Polly we had feedback from users that it was more difficult to use in F# and VB.NET compared to C# because of a lack of support for ValueTask (App-vNext/Polly#2045).

This lead to us adding documentation and samples to help such users. We didn't go further than that due to a lack of feedback/demand.

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

namespace Examples.AspNetCore.Controllers
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a sense of whether an AspNetCore app makes the most sense for the example? Not being very familiar with F#, I'm not sure if F# AspNetCore apps are common. Maybe F# is more commonly used in the context of a console app or something else?

@alanwest
Copy link
Copy Markdown
Member

I agree with the sentiments expressed that we do not want to maintain a bunch of different F# examples.

@martincostello had shared some feedback he had heard with me that using OpenTelemetry .NET with F# was awkward for F# developers. Not being an F# developer myself, I'm curious if anyone thinks this example either highlights the awkwardness or demonstrates that it is actually not awkward? Either way I think a single F# example may prove useful for folks especially if it dispels any awkwardness.

Copy link
Copy Markdown
Member

@alanwest alanwest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to approve this. I don't consider my comment blocking. If we learn in the future that pivoting to a different kind of app for F# make more sense then we can change it.

@rajkumar-rangaraj rajkumar-rangaraj added this pull request to the merge queue Feb 26, 2026
Merged via the queue into open-telemetry:main with commit 06f9384 Feb 26, 2026
85 checks passed
@martincostello martincostello deleted the fsharp-example branch February 28, 2026 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file documentation Documentation related infra Infra work - CI/CD, code coverage, linters ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants