Skip to content
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

Add F# example? ( ・ω・) #296

Merged
merged 8 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.inlayHints.enabled": "offUnlessPressed"
}
5 changes: 5 additions & 0 deletions examples/aspnetcore-fsharp/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"FSharp.inlayHints.enabled": false,
cartermp marked this conversation as resolved.
Show resolved Hide resolved
"FSharp.inlayHints.typeAnnotations": false,
"editor.inlayHints.enabled": "offUnlessPressed"
}
47 changes: 47 additions & 0 deletions examples/aspnetcore-fsharp/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
open System
open System.Diagnostics.Metrics

open Microsoft.AspNetCore
open Microsoft.AspNetCore.Builder
open Microsoft.Extensions.DependencyInjection
open Microsoft.Extensions.Hosting
open Microsoft.Extensions.Configuration

open Giraffe
open Giraffe.EndpointRouting
open OpenTelemetry.Trace
open OpenTelemetry.Metrics
open Honeycomb.OpenTelemetry

let configureServices (services: IServiceCollection) (honeycombOptions: HoneycombOptions) =
services
.AddRouting()
.AddGiraffe()
.AddOpenTelemetryTracing(fun otelBuilder ->
otelBuilder
.AddHoneycomb(honeycombOptions)
.AddAspNetCoreInstrumentationWithBaggage()
|> ignore)
.AddOpenTelemetryMetrics(fun otelBuilder ->
otelBuilder.AddHoneycomb(honeycombOptions)
|> ignore)
|> ignore

let configureApp (appBuilder: IApplicationBuilder) (honeycombOptions: HoneycombOptions) =
let tracer = TracerProvider.Default.GetTracer(honeycombOptions.ServiceName)
let meter = new Meter(honeycombOptions.MetricsDataset)
appBuilder
.UseRouting()
.UseGiraffe(Routing.endpoints tracer meter)
|> ignore

let args = Environment.GetCommandLineArgs()
let builder = WebApplication.CreateBuilder(args)
let honeycombOptions = builder.Configuration.GetHoneycombOptions();

configureServices builder.Services honeycombOptions

let app = builder.Build()
configureApp app honeycombOptions

app.Run()
60 changes: 60 additions & 0 deletions examples/aspnetcore-fsharp/Routing.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
module Routing

open System
open System.Diagnostics.Metrics

open Microsoft.AspNetCore.Http

open Giraffe
open Giraffe.EndpointRouting
open OpenTelemetry.Trace

type WeatherForecast =
{ Date: DateTime
TemperatureC: int
Summary: string }

let createForecast index (rng: Random) (weatherSummaries: string[]) =
{ Date = DateTime.Now.AddDays(index)
TemperatureC = rng.Next(-20,55)
Summary = weatherSummaries[rng.Next(weatherSummaries.Length)] }

let weatherSummaries =
[|
"Freezing"
"Bracing"
"Chilly"
"Cool"
"Mild"
"Warm"
"Balmy"
"Hot"
"Sweltering"
"Scorching"
|]

let weatherForecastHandler (tracer: Tracer) (sheepCounter: Counter<int>) =
fun (next : HttpFunc) (ctx : HttpContext) ->
use forecastSpan = tracer.StartActiveSpan("app.weatherForecast")

let rng = Random()
let forecast =
[|
for index in 0..4 ->
createForecast index rng weatherSummaries
|]

forecastSpan.SetAttribute("app.weatherForecast.days", forecast.Length) |> ignore

sheepCounter.Add(1)

json forecast next ctx

let endpoints (tracer: Tracer) (meter: Meter) =
let sheepCounter = meter.CreateCounter("app.sheep")
[
GET [
route "/" (text "Hello World")
route "/weatherforecast" (weatherForecastHandler tracer sheepCounter)
]
]
15 changes: 15 additions & 0 deletions examples/aspnetcore-fsharp/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"Honeycomb": {
cartermp marked this conversation as resolved.
Show resolved Hide resolved
"ServiceName": "aspnetcore-example",
"ApiKey": "{apikey}",
"MetricsDataset": "aspnetcore-example-metrics"
}
}
24 changes: 24 additions & 0 deletions examples/aspnetcore-fsharp/aspnetcore-fsharp.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<!-- <OutputType>Exe</OutputType> -->
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>aspnetcore_fsharp</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Honeycomb.OpenTelemetry\Honeycomb.OpenTelemetry.csproj" />
<ProjectReference Include="..\..\src\Honeycomb.OpenTelemetry.Instrumentation.AspNetCore\Honeycomb.OpenTelemetry.Instrumentation.AspNetCore.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Giraffe" Version="6.0.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.0.0-rc9.6" />
</ItemGroup>

<ItemGroup>
<Compile Include="Routing.fs" />
<Compile Include="Program.fs" />
</ItemGroup>

</Project>
15 changes: 15 additions & 0 deletions honeycomb-opentelemetry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Honeycomb.OpenTelemetry.Ins
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Honeycomb.OpenTelemetry.AutoInstrumentations", "src\Honeycomb.OpenTelemetry.AutoInstrumentations\Honeycomb.OpenTelemetry.AutoInstrumentations.csproj", "{CA34C8B5-6C46-41C5-8931-AAFAD732DF5F}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "aspnetcore-fsharp", "examples\aspnetcore-fsharp\aspnetcore-fsharp.fsproj", "{72DF2078-62A4-4529-B439-BFFF4AD4C6B9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -117,6 +119,18 @@ Global
{CA34C8B5-6C46-41C5-8931-AAFAD732DF5F}.Release|x64.Build.0 = Release|Any CPU
{CA34C8B5-6C46-41C5-8931-AAFAD732DF5F}.Release|x86.ActiveCfg = Release|Any CPU
{CA34C8B5-6C46-41C5-8931-AAFAD732DF5F}.Release|x86.Build.0 = Release|Any CPU
{72DF2078-62A4-4529-B439-BFFF4AD4C6B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{72DF2078-62A4-4529-B439-BFFF4AD4C6B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{72DF2078-62A4-4529-B439-BFFF4AD4C6B9}.Debug|x64.ActiveCfg = Debug|Any CPU
{72DF2078-62A4-4529-B439-BFFF4AD4C6B9}.Debug|x64.Build.0 = Debug|Any CPU
{72DF2078-62A4-4529-B439-BFFF4AD4C6B9}.Debug|x86.ActiveCfg = Debug|Any CPU
{72DF2078-62A4-4529-B439-BFFF4AD4C6B9}.Debug|x86.Build.0 = Debug|Any CPU
{72DF2078-62A4-4529-B439-BFFF4AD4C6B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{72DF2078-62A4-4529-B439-BFFF4AD4C6B9}.Release|Any CPU.Build.0 = Release|Any CPU
{72DF2078-62A4-4529-B439-BFFF4AD4C6B9}.Release|x64.ActiveCfg = Release|Any CPU
{72DF2078-62A4-4529-B439-BFFF4AD4C6B9}.Release|x64.Build.0 = Release|Any CPU
{72DF2078-62A4-4529-B439-BFFF4AD4C6B9}.Release|x86.ActiveCfg = Release|Any CPU
{72DF2078-62A4-4529-B439-BFFF4AD4C6B9}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -129,6 +143,7 @@ Global
{41B05546-CC58-4546-AC73-2497F7CD8FD8} = {B2B54384-A507-44F4-B611-039F7CC27AC0}
{DB772676-A314-44DC-8EBD-971FBE6953B9} = {3E7EDB35-637A-402C-ABA6-EF8E4C55C051}
{CA34C8B5-6C46-41C5-8931-AAFAD732DF5F} = {3E7EDB35-637A-402C-ABA6-EF8E4C55C051}
{72DF2078-62A4-4529-B439-BFFF4AD4C6B9} = {B2B54384-A507-44F4-B611-039F7CC27AC0}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AFD90899-B909-432A-BBAA-BBC662E19E7C}
Expand Down