Skip to content

f/add traced op helper - #19

Open
danidomi wants to merge 4 commits into
masterfrom
f/add-traced-op-helper
Open

f/add traced op helper#19
danidomi wants to merge 4 commits into
masterfrom
f/add-traced-op-helper

Conversation

@danidomi

@danidomi danidomi commented May 18, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Chores

    • Updated logging dependency to a newer version.
  • New Features

    • Enhanced metrics and timing utilities: return an enriched execution context, support deferred error reporting, and attach distributed trace identifiers for clearer, trace-aware logs.

Review Change Stack

danidomi added 2 commits May 15, 2026 17:23
Returns the span-bearing ctx and an error-recording stop closure.
When a valid OTEL span is in ctx, forks the suplog/logctx logger so
field mutations are scoped to this op, and stamps it with this span's
trace_id and span_id. Subsequent log calls via logctx.Info(ctx, ...)
within the op are auto-tagged so traces and logs can be correlated.
When tracing is disabled (no valid span), still create a forked logger
in ctx so callers can accumulate per-op fields via log.WithField(ctx, ...)
without those calls silently no-op'ing.
@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c4d9da5f-1ff2-4097-a52d-ec7a0b31f085

📥 Commits

Reviewing files that changed from the base of the PR and between 2bd9419 and a03bfc7.

📒 Files selected for processing (1)
  • metrics.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • metrics.go

📝 Walkthrough

Walkthrough

Upgrades github.com/InjectiveLabs/suplog to v1.7.1, adds logctx usage to attach span-aware loggers and inject trace_id/span_id into contexts in reportTiming, and changes timing helpers to return the enriched context.Context alongside deferred error-reporting closures.

Changes

Metrics reporting with distributed tracing support

Layer / File(s) Summary
suplog dependency upgrade
go.mod
Updated github.com/InjectiveLabs/suplog from v1.3.3 to v1.7.1.
Attach logctx and inject trace/span into context
metrics.go
Added github.com/InjectiveLabs/suplog/logctx import and modified reportTiming to attach a logctx logger to the returned context and set trace_id/span_id when the OpenTelemetry span context is valid.
Timing helpers return enriched context and error closure
metrics.go
Changed ReportFuncCallAndTimingCtxWithErr and ReportNamedFuncCallAndTimingCtxWithErr signatures to return (context.Context, func(err *error, stopTags ...Tags)); closures now call the timing stop function with stopTags and call ReportClosureFuncError when err points to a non-nil error, using merged start+stop tags only for the error report.

Sequence Diagram

sequenceDiagram
  participant Caller
  participant ReportNamed as ReportNamedFuncCallAndTimingCtxWithErr
  participant reportTiming
  participant logctx as logctx.Attach
  participant Closure

  Caller->>ReportNamed: ctx, fn, startTags
  ReportNamed->>reportTiming: ctx, fn, startTags
  reportTiming->>logctx: attach logger to ctx
  reportTiming->>reportTiming: set trace_id, span_id if span valid
  reportTiming->>ReportNamed: return enriched ctx, stop
  ReportNamed->>Caller: enriched ctx, closure
  Caller->>Closure: deferred(errPtr, stopTags)
  Closure->>Closure: call stop(stopTags...)
  Closure->>Closure: ReportClosureFuncError if errPtr != nil && *errPtr != nil (merged tags)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through spans and tags today,
I tucked trace_id and span_id in play,
A logger snug within the ctx,
Timers stop and errors check,
Metrics hum — carrot snacks on the way!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'f/add traced op helper' is vague and uses non-descriptive branching convention prefixes that don't clearly convey what the changeset accomplishes. Clarify the title to describe the actual change, such as 'Add span-aware logging enrichment to timing metrics' or 'Enhance metrics reporting with trace context information'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch f/add-traced-op-helper

Comment @coderabbitai help to get the list of available commands and usage tips.

@danidomi danidomi changed the title F/add traced op helper f/add traced op helper May 18, 2026
@socket-security

socket-security Bot commented May 18, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedgithub.com/​InjectiveLabs/​suplog@​v1.3.3 ⏵ v1.7.199 +1100100100100

View full report

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@metrics.go`:
- Around line 84-86: The returned closure in reportTiming currently computes
finalTags by merging start tags with stopTags and then calls stop(finalTags),
which causes duplicate/contradictory keys; instead, keep computing finalTags
only for use with ReportClosureFuncError but invoke stop with the original
stopTags slice (i.e., call stop(stopTags...)); specifically, inside the closure
produced by reportTiming, leave finalTags = MergeTags(... ) for passing into
ReportClosureFuncError, but replace the stop(finalTags) call with
stop(stopTags...) so stop only receives the stop-time tags and does not re-emit
start tags.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 502a433f-77cf-4b71-8f43-ec701d56c865

📥 Commits

Reviewing files that changed from the base of the PR and between 0a91b85 and 2bd9419.

📒 Files selected for processing (1)
  • metrics.go

Comment thread metrics.go Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants