Skip to content

Commit

Permalink
Pass scriptId in Trace
Browse files Browse the repository at this point in the history
  • Loading branch information
zebp committed Apr 10, 2024
1 parent 15f471b commit 250b51c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
18 changes: 13 additions & 5 deletions src/workerd/io/trace.c++
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,13 @@ Trace::Exception::Exception(kj::Date timestamp, kj::String name, kj::String mess

Trace::Trace(kj::Maybe<kj::String> stableId, kj::Maybe<kj::String> scriptName,
kj::Maybe<kj::Own<ScriptVersion::Reader>> scriptVersion,
kj::Maybe<kj::String> dispatchNamespace, kj::Array<kj::String> scriptTags,
kj::Maybe<kj::String> entrypoint)
kj::Maybe<kj::String> dispatchNamespace, kj::Maybe<kj::String> scriptId,
kj::Array<kj::String> scriptTags, kj::Maybe<kj::String> entrypoint)
: stableId(kj::mv(stableId)),
scriptName(kj::mv(scriptName)),
scriptVersion(kj::mv(scriptVersion)),
dispatchNamespace(kj::mv(dispatchNamespace)),
scriptId(kj::mv(scriptId)),
scriptTags(kj::mv(scriptTags)),
entrypoint(kj::mv(entrypoint)) {}
Trace::Trace(rpc::Trace::Reader reader) {
Expand Down Expand Up @@ -281,6 +282,9 @@ void Trace::copyTo(rpc::Trace::Builder builder) {
KJ_IF_SOME(version, scriptVersion) {
builder.setScriptVersion(*version);
}
KJ_IF_SOME(id, scriptId) {
builder.setScriptId(id);
}
KJ_IF_SOME(ns, dispatchNamespace) {
builder.setDispatchNamespace(ns);
}
Expand Down Expand Up @@ -388,6 +392,10 @@ void Trace::mergeFrom(rpc::Trace::Reader reader, PipelineLogLevel pipelineLogLev
scriptVersion = capnp::clone(reader.getScriptVersion());
}

if (reader.hasScriptId()) {
scriptId = kj::str(reader.getScriptId());
}

if (reader.hasDispatchNamespace()) {
dispatchNamespace = kj::str(reader.getDispatchNamespace());
}
Expand Down Expand Up @@ -536,12 +544,12 @@ kj::Promise<kj::Array<kj::Own<Trace>>> PipelineTracer::onComplete() {
}

kj::Own<WorkerTracer> PipelineTracer::makeWorkerTracer(
PipelineLogLevel pipelineLogLevel, kj::Maybe<kj::String> stableId,
PipelineLogLevel pipelineLogLevel, kj::Maybe<kj::String> scriptId, kj::Maybe<kj::String> stableId,
kj::Maybe<kj::String> scriptName, kj::Maybe<kj::Own<ScriptVersion::Reader>> scriptVersion,
kj::Maybe<kj::String> dispatchNamespace, kj::Array<kj::String> scriptTags,
kj::Maybe<kj::String> entrypoint) {
auto trace = kj::refcounted<Trace>(kj::mv(stableId), kj::mv(scriptName), kj::mv(scriptVersion),
kj::mv(dispatchNamespace), kj::mv(scriptTags), kj::mv(entrypoint));
kj::mv(dispatchNamespace), kj::mv(scriptId), kj::mv(scriptTags), kj::mv(entrypoint));
traces.add(kj::addRef(*trace));
return kj::refcounted<WorkerTracer>(kj::addRef(*this), kj::mv(trace), pipelineLogLevel);
}
Expand All @@ -552,7 +560,7 @@ WorkerTracer::WorkerTracer(kj::Own<PipelineTracer> parentPipeline,
parentPipeline(kj::mv(parentPipeline)) {}
WorkerTracer::WorkerTracer(PipelineLogLevel pipelineLogLevel)
: pipelineLogLevel(pipelineLogLevel),
trace(kj::refcounted<Trace>(kj::none, kj::none, kj::none, kj::none, nullptr, kj::none)) {}
trace(kj::refcounted<Trace>(kj::none, kj::none, kj::none, kj::none, kj::none, nullptr, kj::none)) {}

void WorkerTracer::log(kj::Date timestamp, LogLevel logLevel, kj::String message) {
if (trace->exceededLogLimit) {
Expand Down
6 changes: 4 additions & 2 deletions src/workerd/io/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class Trace final : public kj::Refcounted {
public:
explicit Trace(kj::Maybe<kj::String> stableId, kj::Maybe<kj::String> scriptName,
kj::Maybe<kj::Own<ScriptVersion::Reader>> scriptVersion,
kj::Maybe<kj::String> dispatchNamespace, kj::Array<kj::String> scriptTags,
kj::Maybe<kj::String> entrypoint);
kj::Maybe<kj::String> dispatchNamespace, kj::Maybe<kj::String> scriptId,
kj::Array<kj::String> scriptTags, kj::Maybe<kj::String> entrypoint);
Trace(rpc::Trace::Reader reader);
~Trace() noexcept(false);
KJ_DISALLOW_COPY_AND_MOVE(Trace);
Expand Down Expand Up @@ -275,6 +275,7 @@ class Trace final : public kj::Refcounted {
kj::Maybe<kj::String> scriptName;
kj::Maybe<kj::Own<ScriptVersion::Reader>> scriptVersion;
kj::Maybe<kj::String> dispatchNamespace;
kj::Maybe<kj::String> scriptId;
kj::Array<kj::String> scriptTags;
kj::Maybe<kj::String> entrypoint;

Expand Down Expand Up @@ -334,6 +335,7 @@ class PipelineTracer final : public kj::Refcounted {
}

kj::Own<WorkerTracer> makeWorkerTracer(PipelineLogLevel pipelineLogLevel,
kj::Maybe<kj::String> scriptId,
kj::Maybe<kj::String> stableId,
kj::Maybe<kj::String> scriptName,
kj::Maybe<kj::Own<ScriptVersion::Reader>> scriptVersion,
Expand Down
1 change: 1 addition & 0 deletions src/workerd/io/worker-interface.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct Trace @0x8e8d911203762d34 {
outcome @2 :EventOutcome;
scriptName @4 :Text;
scriptVersion @19 :ScriptVersion;
scriptId @23 :Text;

eventTimestampNs @5 :Int64;

Expand Down

0 comments on commit 250b51c

Please sign in to comment.