Skip to content

Activities not started with tags #14776

@TheAngryByrd

Description

@TheAngryByrd

Please provide a succinct description of the issue.

👋 I'm trying to use the tracing information inside FSC for FSAC to provide feedback when something is being typechecked. I'm using an ActivityListener like so:

  let mutable inflightEvents = ConcurrentDictionary<_, ServerProgressReport>()

  let shouldListenTo (act : ActivitySource) =
    act.Name = "fsc"

  let activityStarted (act : Activity) =
    let progressReport = new ServerProgressReport(lspClient)
    if inflightEvents.TryAdd(act.Id, progressReport) then

      progressReport.Begin($"Dependent Typecheck {act.DisplayName}")
      |> Async.StartImmediate
    ()

  let activityStopped (act : Activity) =
    match inflightEvents.TryRemove(act.Id) with
    | true, v -> v.End() |> Async.StartImmediate
    | _ -> ()

  let listener = new ActivityListener(
    ShouldListenTo = shouldListenTo,
    Sample = (fun _ ->  ActivitySamplingResult.AllData),
    ActivityStarted  = activityStarted,
    ActivityStopped = activityStopped
  )
  do ActivitySource.AddActivityListener listener

The activityStarted does get messages for the name like BackgroundCompiler.CreateOneIncrementalBuilder. However, this request is missing the associated tags. Which means we can't tell the user which file is being type checked currently.

This is because the Activity is started and created before tags are added:

let start (name: string) (tags: (string * string) seq) : IDisposable =
let activity = activitySource.StartActivity(name)
match activity with
| null -> ()
| activity ->
for key, value in tags do
activity.AddTag(key, value) |> ignore
activity

I think the change would be rather straightforward:

    let start (name: string) (tags: (string * string) seq) : IDisposable =
        let activity = activitySource.CreateActivity(name, ActivityKind.Internal)

        match activity with
        | null -> ()
        | activity ->
            for key, value in tags do
                activity.AddTag(key, value) |> ignore

        activity.Start()

or possibly

    let start (name: string) (tags: (string * string) seq) : IDisposable =
        let tags = tags |> Seq.map (fun (k,v) -> KeyValuePair(k, box v))
        let activity = activitySource.StartActivity(ActivityKind.Internal, name = name, tags = tags)

        activity

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions