-- Only trace queries with sample flag SET pg_tracing.sample_rate = 0.0; SET pg_tracing.caller_sample_rate = 1.0; /*dddbs='postgres.db',traceparent='00-00000000000000000000000000000001-0000000000000001-01'*/ CREATE TABLE IF NOT EXISTS pg_tracing_test_table_with_constraint (a int, b char(20), CONSTRAINT PK_tracing_test PRIMARY KEY (a)); SELECT span_type, span_operation, lvl from peek_ordered_spans where trace_id='00000000000000000000000000000001'; span_type | span_operation | lvl -------------------+-----------------------------------------------------------------------------------------------------------------------------------+----- Utility query | CREATE TABLE IF NOT EXISTS pg_tracing_test_table_with_constraint (a int, b char(20), CONSTRAINT PK_tracing_test PRIMARY KEY (a)); | 0 ProcessUtility | ProcessUtility | 1 Utility query | CREATE TABLE IF NOT EXISTS pg_tracing_test_table_with_constraint (a int, b char(20), CONSTRAINT PK_tracing_test PRIMARY KEY (a)); | 2 ProcessUtility | ProcessUtility | 3 TransactionCommit | TransactionCommit | 0 (5 rows) -- Simple insertion /*dddbs='postgres.db',traceparent='00-00000000000000000000000000000002-0000000000000002-01'*/ INSERT INTO pg_tracing_test_table_with_constraint VALUES(1, 'aaa'); SELECT span_type, span_operation from peek_ordered_spans where trace_id='00000000000000000000000000000002'; span_type | span_operation -------------------+------------------------------------------------------------------ Insert query | INSERT INTO pg_tracing_test_table_with_constraint VALUES($1, $2) Planner | Planner ExecutorRun | ExecutorRun Insert | Insert on pg_tracing_test_table_with_constraint Result | Result TransactionCommit | TransactionCommit (6 rows) -- Trigger constraint violation /*dddbs='postgres.db',traceparent='00-00000000000000000000000000000003-0000000000000003-01'*/ INSERT INTO pg_tracing_test_table_with_constraint VALUES(1, 'aaa'); ERROR: duplicate key value violates unique constraint "pk_tracing_test" DETAIL: Key (a)=(1) already exists. SELECT span_type, span_operation, sql_error_code, lvl from peek_ordered_spans where trace_id='00000000000000000000000000000003'; span_type | span_operation | sql_error_code | lvl --------------+------------------------------------------------------------------+----------------+----- Insert query | INSERT INTO pg_tracing_test_table_with_constraint VALUES($1, $2) | 23505 | 0 Planner | Planner | 00000 | 1 ExecutorRun | ExecutorRun | 23505 | 1 Insert | Insert on pg_tracing_test_table_with_constraint | 23505 | 2 Result | Result | 23505 | 3 (5 rows) -- Trigger an error while calling pg_tracing_peek_spans which resets tracing, nothing should be generated CALL clean_spans(); /*dddbs='postgres.db',traceparent='00-00000000000000000000000000000004-0000000000000004-01'*/ INSERT INTO pg_tracing_test_table_with_constraint VALUES(length((select sql_error_code from public.pg_tracing_peek_spans)), 'aaa'); ERROR: null value in column "a" of relation "pg_tracing_test_table_with_constraint" violates not-null constraint DETAIL: Failing row contains (null, aaa ). SELECT span_type, span_operation, sql_error_code from peek_ordered_spans where trace_id='00000000000000000000000000000004'; span_type | span_operation | sql_error_code -----------+----------------+---------------- (0 rows) -- Cleanup CALL clean_spans();