Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WC-2707 Only submit non-empty traces to trace workers #2946

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/workerd/api/trace.c++
Original file line number Diff line number Diff line change
Expand Up @@ -607,17 +607,24 @@ kj::Promise<void> sendTracesToExportedHandler(kj::Own<IoContext::IncomingRequest
t.setEventInfo(context.now(), Trace::TraceEventInfo(traces));
}

auto nonEmptyTraces = kj::Vector<kj::Own<Trace>>(kj::size(traces));
for (auto& trace: traces) {
if (trace->eventInfo != kj::none) {
nonEmptyTraces.add(kj::mv(trace));
}
}

// Add the actual JS as a wait until because the handler may be an event listener which can't
// wait around for async resolution. We're relying on `drain()` below to persist `incomingRequest`
// and its members until this task completes.
auto entrypointName = entrypointNamePtr.map([](auto s) { return kj::str(s); });
try {
co_await context.run([&context, traces = mapAddRef(traces),
co_await context.run([&context, nonEmptyTraces = kj::mv(nonEmptyTraces),
entrypointName = kj::mv(entrypointName)](Worker::Lock& lock) mutable {
jsg::AsyncContextFrame::StorageScope traceScope = context.makeAsyncTraceScope(lock);

auto handler = lock.getExportedHandler(entrypointName, context.getActor());
return lock.getGlobalScope().sendTraces(traces, lock, handler);
return lock.getGlobalScope().sendTraces(nonEmptyTraces.asPtr(), lock, handler);
});
} catch (kj::Exception e) {
// TODO(someday): We only report sendTraces() as failed for metrics/logging if the initial
Expand Down