otel: extract batchSpanAttrs helper to dedupe processList/processMessages#415
Conversation
…ages Both root-span sites built the same attribute list inline. Pulled it into System.Tracing.batchSpanAttrs so the two callers reduce to a single helper call. Uses toList over Maybe to drop the ce.type attribute entirely when the CloudEvents header is absent (instead of emitting an empty string). Follow-up from PR #414 review — the dedupe landed on the branch a few seconds after the squash merge, so it didn't make the merge.
Code ReviewOverall: Clean, focused deduplication — the extracted helper is well-named, correctly placed, and the two call sites collapse as intended. A few small notes below.
|
| Correctness | ✓ Behavior identical to the inlined original |
| Deduplication | ✓ Both call sites simplified |
| Export + docs | ✓ Section header and Haddock comment |
| Import cleanup | ✓ Unused OA import dropped from ProcessMessage.hs |
| Suggestions | maybeToList over toList for clarity; fix rmAckId → _ |
LGTM with the nits above being optional.
Code ReviewSummary: Clean deduplication PR. The extraction is well-scoped and the Nits / possible improvements1. In -- current
: maybeToList (("ce.type",) . OA.toAttribute @Text <$> HM.lookup "ce-type" attrs)
-- @Text is redundant; can drop it
: maybeToList (("ce.type",) . OA.toAttribute <$> HM.lookup "ce-type" attrs)If you want to keep it for documentation/resilience, that's fine — but it's noise given the inferred type. 2. CloudEvents concern in the abstraction boundary The Haddock says "queue consumers, gRPC handlers", but Consider splitting the signature to make the optional attribute explicit at the call site: -- option A: separate the optional CE attr
batchSpanAttrs :: Int -> [(Text, Attribute)]
batchSpanAttrs n = [("messaging.batch.message_count", OA.toAttribute n)]
-- call sites pass the optional attrs themselves:
withSpan_ "pubsub.process_messages"
(batchSpanAttrs (length msgs) <> ceTypeAttr attrs) ...
ceTypeAttr :: HM.HashMap Text Text -> [(Text, Attribute)]
ceTypeAttr attrs = maybeToList (("ce.type",) . OA.toAttribute <$> HM.lookup "ce-type" attrs)Or keep the current signature but rename/document it as 3. Renaming OverallLGTM modulo the nits above. The |
Code ReviewClean, well-scoped refactor. The extraction is correct and the call sites are noticeably more readable. A few notes: Positives
Suggestion:
|
Code ReviewOverview: Clean deduplication — extracts the repeated
|
Code ReviewClean, well-scoped refactor. No correctness issues. What's good
One suggestion: prefer
|
Follow-up to #414. Both root-span entry points (
processList,processMessages) build the same attribute list inline:Pulled into
System.Tracing.batchSpanAttrs. The two call sites collapse to:toList (f <$> mx)overMaybereads more clearly than thefoldMap-with-singleton-list pattern. Also drops a now-unusedOpenTelemetry.Attributesqualified import fromProcessMessage.hs.This was the last actionable nit from #414's review; the dedupe was pushed to the branch a few seconds after the squash merge, so it missed the train.
Test plan
otlp.process_list/pubsub.process_messagesspans;ce.typeis omitted (not empty-string) when the header is absent