Public
Edited
Oct 28, 2024
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
segment_tree
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
root_segments
Insert cell
Insert cell
Insert cell
selected_trace
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
width,
marginLeft: 500,
marks: [
Plot.tickX(perf, { x: "duration", y: "name", tip: true, stroke: "#0003" }),
Plot.ruleX([0])
]
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
db_refresh
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
db_refresh
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
mutable refresh_db = 0
Insert cell
traces_table = {
dropTables
return db.sql`CREATE OR REPLACE TABLE traces (
Id string,
Duration float,
PRIMARY KEY (Id)
)`;
}
Insert cell
new Date(JSON.parse(traces.Traces[0].Segments[0].Document).start_time * 1000)
Insert cell
traces
Insert cell
JSON.parse(traces.Traces[0].Segments[2].Document)
Insert cell
segments_table = traces_table &&
db.sql`CREATE OR REPLACE TABLE segments (
Id string,
name string,
start_time TIMESTAMP,
end_time TIMESTAMP,
parent string,
TraceId string,
pageId string,
method string,
url string,
status integer,
PRIMARY KEY (Id),
FOREIGN KEY (TraceId) REFERENCES traces(Id)
)`.then(() => mutable refresh_db++)
Insert cell
Insert cell
// The cell queries the first element of the last inserted batch, this is useful for iterating on the schema and ensuring data can do in and out without having to do a whole patch
insert_traces &&
db.query(`SELECT * FROM segments WHERE TraceId = '${traces.Traces[0].Id}'`)
Insert cell
insert_traces = {
segments_table;
return Promise.all(
traces.Traces.map(async (trace) =>
db.sql`INSERT INTO traces VALUES (${trace.Id}, ${trace.Duration})`
.then(() =>
Promise.all(
trace.Segments.map((segment) => {
const doc = JSON.parse(segment.Document);
const insert_doc = (doc, parent_id) => {
const parent_insert = db.sql`INSERT INTO segments VALUES (
${doc.id},
${doc.name},
${new Date(doc.start_time * 1000)},
${new Date(doc.end_time * 1000)},
${doc.parent_id || parent_id},
${trace.Id},
${doc?.metadata?.rum?.pageId},
${doc?.http?.request?.method?.toUpperCase()},
${doc?.http?.request?.url},
${doc?.http?.response?.status},
)`.catch((err) => {
//debugger;
console.error(err);
});

return parent_insert.then(
Promise.all(
(doc.subsegments || []).map((subsegment) =>
insert_doc(subsegment, segment.Id)
)
)
);
};
return insert_doc(doc);
})
)
)
.catch((err) => {
//debugger;
console.error(err);
})
)
);
}
Insert cell
insert_traces && mutable refresh_db++
Insert cell
Insert cell
Insert cell
trace_summaries = xray
.getTraceSummaries({
FilterExpression: filter.trim() !== "" ? filter.trim() : undefined,
StartTime: start_time.toISOString(),
EndTime: end_time.toISOString()
})
.promise()
Insert cell
enqueue_batches = {
if (fetch_traces == 0) return "Press fetch traces to commence slurping";
let batch = trace_summaries;
while (batch && run) {
viewof batch.send(batch);
if (batch.NextToken) {
batch = await xray
.getTraceSummaries({
FilterExpression: filter.trim() !== "" ? filter.trim() : undefined,
StartTime: start_time.toISOString(),
EndTime: end_time.toISOString(),
NextToken: batch.NextToken
})
.promise();
} else {
batch = null;
}
}
}
Insert cell
viewof batch = {
dropTables;
return flowQueue();
}
Insert cell
mutable counter = 0
Insert cell
minibatch = []
Insert cell
Insert cell
viewof trace_ids = {
dropTables;
return flowQueue();
}
Insert cell
Insert cell
traces && mutable batches_fetched++
Insert cell
viewof trace_ids.resolve(insert_traces)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more