3
3
// https://opensource.org/licenses/Apache-2.0
4
4
5
5
#include < workerd/io/tracer.h>
6
+ #include < workerd/util/sentry.h>
6
7
#include < workerd/util/thread-scopes.h>
7
8
8
9
#include < capnp/message.h> // for capnp::clone()
@@ -167,6 +168,10 @@ void WorkerTracer::addLog(const tracing::InvocationSpanContext& context,
167
168
// available. If the given worker stage is only tailed by a streaming tail worker, adding the log
168
169
// to the legacy trace object is not needed; this will be addressed in a future refactor.
169
170
KJ_IF_SOME (writer, maybeTailStreamWriter) {
171
+ // TODO(felix): Used for debug logging, remove after a few days.
172
+ if (topLevelInvocationSpanContext == kj::none) {
173
+ LOG_NOSENTRY (WARNING, " tried to send log before onset event" , trace->entrypoint , isJsRpc);
174
+ }
170
175
// If message is too big on its own, truncate it.
171
176
writer->report (context,
172
177
{(tracing::Log (timestamp, logLevel,
@@ -220,7 +225,8 @@ void WorkerTracer::addSpan(CompleteSpan&& span) {
220
225
// TODO(o11y): Provide correct nested spans
221
226
// TODO(o11y): Propagate span context when context entropy is not available for RPC-based worker
222
227
// invocations as indicated by isTrigger
223
- auto & topLevelContext = KJ_ASSERT_NONNULL (topLevelInvocationSpanContext, span);
228
+ auto & topLevelContext =
229
+ KJ_ASSERT_NONNULL (topLevelInvocationSpanContext, span, trace->entrypoint , isJsRpc);
224
230
tracing::InvocationSpanContext context = [&]() {
225
231
if (topLevelContext.isTrigger ()) {
226
232
return topLevelContext.clone ();
@@ -419,6 +425,12 @@ void WorkerTracer::setOutcome(EventOutcome outcome, kj::Duration cpuTime, kj::Du
419
425
// fixed size.
420
426
}
421
427
428
+ void WorkerTracer::recordTimestamp (kj::Date timestamp) {
429
+ if (completeTime == kj::UNIX_EPOCH) {
430
+ completeTime = timestamp;
431
+ }
432
+ }
433
+
422
434
void WorkerTracer::setFetchResponseInfo (tracing::FetchResponseInfo&& info) {
423
435
// Match the behavior of setEventInfo(). Any resolution of the TODO comments
424
436
// in setEventInfo() that are related to this check while probably also affect
@@ -434,6 +446,7 @@ void WorkerTracer::setFetchResponseInfo(tracing::FetchResponseInfo&& info) {
434
446
}
435
447
436
448
void WorkerTracer::setUserRequestSpan (SpanParent&& span) {
449
+ KJ_ASSERT (span.isObserved (), " span argument must be observed" );
437
450
KJ_ASSERT (!userRequestSpan.isObserved (), " setUserRequestSpan can only be called once" );
438
451
userRequestSpan = kj::mv (span);
439
452
}
@@ -446,4 +459,8 @@ SpanParent WorkerTracer::getUserRequestSpan() {
446
459
return userRequestSpan.addRef ();
447
460
}
448
461
462
+ void BaseTracer::setIsJsRpc () {
463
+ isJsRpc = true ;
464
+ }
465
+
449
466
} // namespace workerd
0 commit comments