Skip to content

Commit

Permalink
fix duplicate metrics & external spans
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Feb 16, 2024
1 parent f9dcfee commit ef1feeb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/MetricsProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as Domain from "@effect/experimental/DevTools/Domain"
import * as ReadonlyArray from "effect/ReadonlyArray"
import * as Effect from "effect/Effect"
import * as Layer from "effect/Layer"
import * as Option from "effect/Option"
Expand Down Expand Up @@ -91,8 +92,16 @@ export const MetricsProviderLive = treeDataProvider<TreeNode>("effect-metrics")(
Effect.flatMap(snapshot =>
Effect.suspend(() => {
const metrics = snapshot.metrics as Array<Domain.Metric>
const names = new Set<string>()
metrics.sort(MetricOrder)
nodes = metrics.map(metric => new MetricNode(metric))
nodes = ReadonlyArray.filterMap(metrics, metric => {
const name = metric.name
if (names.has(name)) {
return Option.none()
}
names.add(name)
return Option.some(new MetricNode(metric))
})
return refresh(Option.none())
}),
),
Expand Down
5 changes: 5 additions & 0 deletions src/SpanProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ export const SpanProviderLive = treeDataProvider<TreeNode>("effect-tracer")(
refresh(Option.some(parent)),
refresh(Option.none()),
)
} else if (
parent !== undefined &&
parent.span._tag === "ExternalSpan"
) {
return refresh(Option.none())
}
return refresh(Option.fromNullable(parent))
})
Expand Down

0 comments on commit ef1feeb

Please sign in to comment.