OmniView provides real-time trace monitoring for Oracle databases through the OMNI_TRACER_API package. Once deployed, you can send trace messages from any PL/SQL code and view them instantly in your terminal.
BEGIN -- Your code here UPDATE orders SET status = 'SHIPPED' WHERE order_id = 12345; IF SQL%ROWCOUNT = 0 THEN OMNI_TRACER_API.Trace_Message( message_ => 'Order 12345 not found for shipping update', log_level_ => 'WARN' ); END IF;EXCEPTION WHEN OTHERS THEN OMNI_TRACER_API.Trace_Message( message_ => 'ERROR: ' || SQLERRM || ' at line ' || DBMS_UTILITY.FORMAT_ERROR_BACKTRACE, log_level_ => 'ERROR' ); RAISE;END;/
Source of the trace (package, procedure, or context)
OMNI_TRACER_API, ORDER_PKG
Message
The actual trace content
Processing order #12345
The Process Name is automatically detected from the calling context using SYS_CONTEXT('USERENV', 'MODULE'). You can set it explicitly with DBMS_APPLICATION_INFO.SET_MODULE().
# Filter by log level./omniview | grep "\[ERROR\]"# Filter by process name./omniview | grep "ORDER_PKG"# Search for specific text./omniview | grep "order #12345"
DECLARE v_debug_mode BOOLEAN := TRUE; -- Control debug output v_order_id NUMBER := 12345;BEGIN IF v_debug_mode THEN OMNI_TRACER_API.Trace_Message( message_ => 'Debug mode enabled for order ' || v_order_id, log_level_ => 'DEBUG' ); END IF; -- Your codeEND;/
DECLARE v_total_records NUMBER; v_processed NUMBER := 0; v_batch_size NUMBER := 1000;BEGIN SELECT COUNT(*) INTO v_total_records FROM orders WHERE status = 'PENDING'; FOR order_rec IN (SELECT * FROM orders WHERE status = 'PENDING') LOOP -- Process each order v_processed := v_processed + 1; -- Log progress every batch_size records IF MOD(v_processed, v_batch_size) = 0 THEN OMNI_TRACER_API.Trace_Message( message_ => 'Progress: ' || v_processed || '/' || v_total_records || ' (' || ROUND(v_processed/v_total_records*100, 2) || '%)', log_level_ => 'INFO' ); END IF; END LOOP; OMNI_TRACER_API.Trace_Message('Batch processing complete: ' || v_processed || ' records', 'INFO');END;/
Trace messages are enqueued with IMMEDIATE visibility, meaning they commit independently of your transaction. This ensures traces are delivered even if your transaction rolls back, but be aware of the performance implications.
Use appropriate log levels: Reserve DEBUG for development, use INFO sparingly in production
Avoid tracing in tight loops: Trace at batch boundaries instead
-- Bad: Tracing in loopFOR i IN 1..10000 LOOP OMNI_TRACER_API.Trace_Message('Processing ' || i, 'DEBUG');END LOOP;-- Good: Batch tracingFOR i IN 1..10000 LOOP IF MOD(i, 1000) = 0 THEN OMNI_TRACER_API.Trace_Message('Processed ' || i || ' records', 'INFO'); END IF;END LOOP;
Keep messages concise: While CLOB supports large messages, keep traces under 1KB for optimal performance
Handle exceptions gracefully: Wrap trace calls in exception handlers to prevent traces from breaking your application
BEGIN OMNI_TRACER_API.Trace_Message(v_message, 'INFO');EXCEPTION WHEN OTHERS THEN NULL; -- Silently ignore trace failuresEND;