Skip to content

Commit

Permalink
Add peek spans with level to extension sql script
Browse files Browse the repository at this point in the history
  • Loading branch information
bonnefoa committed Oct 16, 2024
1 parent c550b1a commit 0484fe4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 25 deletions.
1 change: 0 additions & 1 deletion expected/cleanup.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ DROP TABLE pg_tracing_test;
DROP function test_function_project_set;
DROP function test_function_result;
DROP VIEW peek_ordered_spans;
DROP VIEW peek_spans_with_level;
DROP VIEW peek_ordered_json_spans;
DROP VIEW peek_json_spans_with_level;
DROP VIEW peek_json_spans;
Expand Down
12 changes: 1 addition & 11 deletions expected/utility.out
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,6 @@ SET pg_tracing.sample_rate = 1.0;
DROP EXTENSION pg_tracing;
CREATE EXTENSION pg_tracing;
SET pg_tracing.sample_rate = 0.0;
-- View displaying spans with their nested level
CREATE VIEW peek_spans_with_level AS
WITH RECURSIVE list_trace_spans AS (
SELECT p.*, 1 as lvl
FROM pg_tracing_peek_spans p where not parent_id=ANY(SELECT span_id from pg_tracing_peek_spans)
UNION ALL
SELECT s.*, lvl + 1
FROM pg_tracing_peek_spans s, list_trace_spans st
WHERE s.parent_id = st.span_id
) SELECT * FROM list_trace_spans;
-- Create utility view to keep order stable
CREATE VIEW peek_ordered_spans AS
WITH oldest_start AS (
Expand All @@ -75,7 +65,7 @@ CREATE VIEW peek_ordered_spans AS
) select *,
extract(MICROSECONDS FROM age(span_start, oldest_start.min_start)) as us_start,
extract(MICROSECONDS FROM age(span_end, oldest_start.min_start)) as us_end
FROM peek_spans_with_level, oldest_start order by span_start, lvl, span_end, deparse_info;
FROM pg_tracing_peek_spans_with_level, oldest_start order by span_start, lvl, span_end, deparse_info;
-- Column type to convert json to record
create type span_json as ("traceId" text, "parentSpanId" text, "spanId" text, name text, "startTimeUnixNano" text, "endTimeUnixNano" text, attributes jsonb, kind int, status jsonb);
CREATE VIEW peek_json_spans AS
Expand Down
11 changes: 11 additions & 0 deletions pg_tracing--0.1.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ CREATE VIEW pg_tracing_info AS
CREATE VIEW pg_tracing_peek_spans AS
SELECT * FROM pg_tracing_spans(false);

-- Spans with their level
CREATE VIEW pg_tracing_peek_spans_with_level AS
WITH RECURSIVE list_trace_spans AS (
SELECT p.*, 1 as lvl
FROM pg_tracing_peek_spans p where not parent_id=ANY(SELECT span_id from pg_tracing_peek_spans)
UNION ALL
SELECT s.*, lvl + 1
FROM pg_tracing_peek_spans s, list_trace_spans st
WHERE s.parent_id = st.span_id
) SELECT * FROM list_trace_spans;

CREATE VIEW pg_tracing_consume_spans AS
SELECT * FROM pg_tracing_spans(true);

Expand Down
1 change: 0 additions & 1 deletion sql/cleanup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ DROP TABLE pg_tracing_test;
DROP function test_function_project_set;
DROP function test_function_result;
DROP VIEW peek_ordered_spans;
DROP VIEW peek_spans_with_level;
DROP VIEW peek_ordered_json_spans;
DROP VIEW peek_json_spans_with_level;
DROP VIEW peek_json_spans;
Expand Down
13 changes: 1 addition & 12 deletions sql/utility.sql
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,6 @@ DROP EXTENSION pg_tracing;
CREATE EXTENSION pg_tracing;
SET pg_tracing.sample_rate = 0.0;

-- View displaying spans with their nested level
CREATE VIEW peek_spans_with_level AS
WITH RECURSIVE list_trace_spans AS (
SELECT p.*, 1 as lvl
FROM pg_tracing_peek_spans p where not parent_id=ANY(SELECT span_id from pg_tracing_peek_spans)
UNION ALL
SELECT s.*, lvl + 1
FROM pg_tracing_peek_spans s, list_trace_spans st
WHERE s.parent_id = st.span_id
) SELECT * FROM list_trace_spans;

-- Create utility view to keep order stable
CREATE VIEW peek_ordered_spans AS
WITH oldest_start AS (
Expand All @@ -84,7 +73,7 @@ CREATE VIEW peek_ordered_spans AS
) select *,
extract(MICROSECONDS FROM age(span_start, oldest_start.min_start)) as us_start,
extract(MICROSECONDS FROM age(span_end, oldest_start.min_start)) as us_end
FROM peek_spans_with_level, oldest_start order by span_start, lvl, span_end, deparse_info;
FROM pg_tracing_peek_spans_with_level, oldest_start order by span_start, lvl, span_end, deparse_info;

-- Column type to convert json to record
create type span_json as ("traceId" text, "parentSpanId" text, "spanId" text, name text, "startTimeUnixNano" text, "endTimeUnixNano" text, attributes jsonb, kind int, status jsonb);
Expand Down

0 comments on commit 0484fe4

Please sign in to comment.