POC Monitoring & Reporting Tools 3 — Questions and Answers
Question 1: Which function in Python's `logging` module sets the root logger's level and adds a default `StreamHandler` if no handlers are configured?
- logging.setup()
- logging.basicConfig() (Correct answer)
- logging.configure()
- logging.init()
Correct answer: logging.basicConfig()
`logging.basicConfig()` performs one-call setup of the root logger with optional level, format, and handler arguments.
Question 2: In `pytest`, which command-line flag generates an XML report compatible with Jenkins and other CI tools?
- --report=xml
- --junitxml=report.xml (Correct answer)
- --output=junit.xml
- --ci-report=report.xml
Correct answer: --junitxml=report.xml
`--junitxml=<path>` tells pytest to write a JUnit-format XML file that CI servers can parse.
Question 3: Which `logging.Handler` subclass sends log records to a remote syslog server?
- SysLogHandler (Correct answer)
- RemoteHandler
- NetworkHandler
- UDPLogHandler
Correct answer: SysLogHandler
`logging.handlers.SysLogHandler` connects to a syslog daemon over UDP or TCP.
Question 4: In OpenTelemetry for Python, what term describes a named unit of work used to represent a single operation within a distributed trace?
- Metric
- Span (Correct answer)
- Log record
- Gauge
Correct answer: Span
A Span represents one named, timed operation within a trace and can be nested to form a trace tree.
Question 5: Which Python library provides `Counter`, `Gauge`, `Histogram`, and `Summary` metric types out of the box for Prometheus integration?
- statsd
- prometheus_client (Correct answer)
- influxdb-client
- grafana-sdk
Correct answer: prometheus_client
`prometheus_client` implements all four core Prometheus metric types and exposes them via an HTTP endpoint.
Question 6: What is the purpose of a `logging.Filter` object attached to a handler?
- To format the log record into a string
- To route records to multiple handlers
- To allow or block records based on custom criteria (Correct answer)
- To compress log files after rotation
Correct answer: To allow or block records based on custom criteria
A `Filter` provides fine-grained control by accepting or rejecting records before the handler emits them.
Question 7: Which method would you call on a `prometheus_client.Counter` object to increment it by a custom amount?
- .increment(n)
- .inc(n) (Correct answer)
- .add(n)
- .observe(n)
Correct answer: .inc(n)
`Counter.inc(amount)` increments the counter by the given value (default 1); `observe()` is for Histograms/Summaries.
Which function in Python's `logging` module sets the root logger's level and adds a default `StreamHandler` if no handlers are configured?