Skip to content

Comments

Add workflow spans for tagging the logs with step name#6088

Open
Caio-Nogueira wants to merge 1 commit intomainfrom
caio/workflows-tracing
Open

Add workflow spans for tagging the logs with step name#6088
Caio-Nogueira wants to merge 1 commit intomainfrom
caio/workflows-tracing

Conversation

@Caio-Nogueira
Copy link
Contributor

@Caio-Nogueira Caio-Nogueira commented Feb 16, 2026

This is a proposal to add arbitrary step-related tags on console logs emitted from within workflow instances (more specifically, steps).

  • Creates a new internal method on the WorkflowEntrypoint base class that the engine will call instead of run;
  • captures the do method from the original step (passed as an rpc property) and patches it;
  • patched do will wrap the original user-defined callback so that it emits user spans and stores current span key in async context
  • handleLog attaches to the workflow step span if it exists in current async context

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 16, 2026

Merging this PR will not alter performance

✅ 70 untouched benchmarks
⏩ 129 skipped benchmarks1


Comparing caio/workflows-tracing (4b6707a) with main (f6d3ef0)

Open in CodSpeed

Footnotes

  1. 129 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Caio-Nogueira Caio-Nogueira force-pushed the caio/workflows-tracing branch 2 times, most recently from 9184d97 to 5dad480 Compare February 23, 2026 11:56
@codecov-commenter
Copy link

codecov-commenter commented Feb 23, 2026

Codecov Report

❌ Patch coverage is 8.29016% with 177 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.47%. Comparing base (8496472) to head (4b6707a).
⚠️ Report is 79 commits behind head on main.

Files with missing lines Patch % Lines
src/workerd/api/workers-module.c++ 0.00% 118 Missing ⚠️
src/workerd/io/trace.c++ 0.00% 31 Missing ⚠️
src/workerd/io/worker.c++ 51.61% 14 Missing and 1 partial ⚠️
src/workerd/io/tracer.c++ 0.00% 13 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6088      +/-   ##
==========================================
- Coverage   70.55%   70.47%   -0.09%     
==========================================
  Files         409      409              
  Lines      109532   109863     +331     
  Branches    18038    18093      +55     
==========================================
+ Hits        77281    77422     +141     
- Misses      21441    21625     +184     
- Partials    10810    10816       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

cbRef = kj::mv(cbRef)),
(stepNameRef, cbRef),
(jsg::Lock& js,
const v8::FunctionCallbackInfo<v8::Value>& cbInfo)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Passing FunctionCallbackInfo is supported but not really idiomatic for the code base. Generally speaking we should try to pass jsg typemapped types (e.g. kj::String, etc)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FunctionCallbackInfo is part of the signature. I'm now deconstructing it so that we can extract the correctly typed values and use those instead

@ask-bonk
Copy link
Contributor

ask-bonk bot commented Feb 24, 2026

@Caio-Nogueira Bonk workflow was cancelled.

View workflow run · To retry, trigger Bonk again.

KJ_ASSERT(originalDo.isFunction(), "step object missing 'do' method");

// Capture references for the patched step.do closure.
auto selfRef = JSG_THIS;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unused?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ultimately selfRef lets us access the run method on the user's subclass

@Caio-Nogueira Caio-Nogueira marked this pull request as ready for review February 24, 2026 13:18
@Caio-Nogueira Caio-Nogueira requested review from a team as code owners February 24, 2026 13:18
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.

3 participants