Using OpenTelemetry in F#

Viewed 28

I have a collector running in a docker container with this config file:

receivers:
  otlp:    
    protocols:      
      grpc:      
      http:

processors:
  batch:

exporters:
  logging:
    loglevel: debug

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [batch]
      exporters: [logging]
    metrics:
      receivers: [otlp]
      processors: [batch]
      exporters: [logging]
    logs:
      receivers: [otlp]
      processors: [batch]
      exporters: [logging]

and using this command:

docker run -p 4317:4317 -v /path/to/yaml/file:/etc/otel-collector-config.yaml otel/opentelemetry-collector:latest --config=/etc/otel-collector-config.yaml

and a console app in F# re-written using the same configuration as the C# example here: https://opentelemetry.io/docs/instrumentation/net/getting-started/#console-application

open System
open System.Diagnostics
open OpenTelemetry.Exporter
open OpenTelemetry
open OpenTelemetry.Trace
open OpenTelemetry.Resources
open Trigger.Reports.Core

[<EntryPoint>]
let main args =
    let collectorEndpoint : string = ""
    let serviceName : string = "my-service"
    
    let tracerProvider : TracerProvider =
        Sdk.CreateTracerProviderBuilder()
            .AddOtlpExporter( fun opt ->
                opt.Endpoint <- Uri "http://localhost:4317"
                )
            .AddSource(serviceName)
            .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(serviceName))
            .AddConsoleExporter()                     
            .Build()
            
    let myActivitySource = new ActivitySource(serviceName)
    
    use activity = myActivitySource.StartActivity("SayHello")
    activity.SetTag("foo", 1)
    
    0

The traces go to the console exporter but not to the Docker container, from the what I can see I've set both the app and collector up correctly.

Any help would be much appreciated.

0 Answers
Related