ELK is Elasticsearch for storage and search, Logstash or Beats for collection and Kibana for the interface, and queries in Discover are written in KQL. A query always has a time range. Kibana shows time in the browser's zone while @timestamp is stored in UTC, so empty results often mean a wrong zone or index. Searching by trace id is the most reliable.
Logs · Kibana
A bug was reproduced at 09:14, and Kibana shows "nothing" for that time. Where did the logs go?
A tester reproduced a payment failure at 09:14, opened Kibana, set an absolute range of 09:10-09:20 and saw zero entries. The logs did not vanish: Kibana shows time in the browser’s zone, the reproduction happened in UTC, and on top of that the wrong index was selected. Such small things eat the first hour of an investigation. This lesson covers ELK/OpenSearch, the KQL query language and a short QA workflow in Discover.
How it works and why.ELK (Elastic Stack) is Elasticsearch (storage and search), Logstash or the lighter Beats and Elastic Agent (collection and processing) and Kibana (the interface). OpenSearch is a fork with its own Kibana counterpart, OpenSearch Dashboards. Logs are indexed by time (daily indices or data streams), so a query always has a time range: without it the search would go through the entire store. Hence two switches people forget: the time range and the data source (in classic Discover mode a data view that says which indices to read).
In Kibana Discover you pick a time range and, in classic mode, a data view (ES|QL mode needs no data view). In classic mode you write a query in KQL (Kibana Query Language) or Lucene. KQL examples:
log.level: "error" and service.name: "checkout"
http.response.status_code >= 500
event.action: "login" and not user.id: "svc-monitor"
error.message: *
trace.id: ("4bf92f35..." or "9a1c0d77...")
The rules: field: value; operators and, or, not; parentheses group; >, >= for numbers and dates; * as a wildcard, and field: * means "the field exists"; values with spaces go in quotes. Field names depend on the log schema: in Elastic Common Schema they are log.level, service.name, trace.id, while a "home-grown" format may have level, app. Autocomplete hints in Discover show the real fields.
Example: from "nothing there" to the root cause. A workflow in which each step narrows the result:
# 1. a window around the reproduction: 09:10-09:20 (in Kibana's zone!)
# 2. narrow by service and level
service.name: "checkout" and log.level: "error"
# 3. filter out healthcheck noise
service.name: "checkout" and log.level: "error"
and not message: "healthcheck"
# 4. or go straight by the request id from the response
trace.id: "4bf92f3577b34da6a3ce929d0e0e4736"
Step 1 is most often forgotten: Kibana shows time according to the zone setting (by default the browser’s zone), while in the documents themselves @timestamp is stored in UTC. So "09:14" from a test and "09:14" in Kibana can be different moments. Fix the zone in the test report and check Kibana’s setting. Then columns (@timestamp, service.name, message) are added to the table, sorted by time, and a document is opened to read the stack in the error.stack_trace field. If the search will be needed again, save it, and put the error count over time into a visualisation.
ES|QL. Besides KQL, Kibana has ES|QL, Elastic’s piped query language where steps are joined with the | character. It is convenient for counts and grouping:
FROM logs-*
| WHERE log.level == "error" AND service.name == "checkout"
| STATS errors = COUNT(*) BY error.code
| SORT errors DESC
| LIMIT 5
Two ways to ask the same thing
KQL
Find entries
A field filter in Discover: "show ERRORs of checkout". Fast, for finding a specific entry and reading the stack.
ES|QL
Count and group
A pipeline: filter, STATS, sort. For questions like "which error codes are the most frequent".
Figure 1. Both options are legitimate: finding entries and counting answer different questions.
Limits and alternatives. OpenSearch Dashboards has the similar DQL, and also PPL and SQL, so syntax differs in details. A search depends on how a field is indexed: a text field is split into words and searched by them, while an exact match requires the keyword type (in nonstandard schemas often message.keyword). Recent entries may appear with a delay of a few seconds because they are still being indexed, so an "empty result" a moment after a failure does not prove the logs are missing. For investigating through a command rather than the interface, see the lesson on the command line.
Typical mistakes.
A forgotten time range or zone: "empty" although the logs exist.
The wrong data view or index: the query is correct but searches in the wrong place.
An exact search on a text field: words match partially and the result is unexpected.
A filter only by level ERROR without a trace id: thousands of other people’s errors on a shared stand.
Check yourself
A test failed at 09:14 UTC and Kibana is set to a UTC+3 zone. How do you find the right window?
Answer
In Kibana this moment appears as 12:14. So either choose an absolute range 12:10-12:20 or change the zone in settings to UTC. The most reliable is to search by the trace id or request id from the test report, then time becomes secondary.
When is ES|QL more convenient than KQL?
Answer
When you need not to find entries but to count or group: for example the five most frequent error codes of a service per hour. A pipeline with STATS ... BY gives a table at once, while KQL only filters documents.
Related lessons: “Structured and plain-text logs”, “Grafana Loki, LogQL, Datadog and Sentry”, “The command line: docker logs, kubectl logs, grep, jq”.
In an interview.Junior: In Kibana I pick a time range, filter by service and level ERROR in KQL, and also search by the trace id or request id from the response. Middle/Senior: I keep in mind the time zone and the data view, that the field type affects search (text versus keyword), and the indexing delay. For counts I use ES|QL or visualisations, and I save findings as a saved search for the team.
Grafana Loki, LogQL, Datadog and Sentry
Loki quickly selects and counts entries by labels, Datadog links logs with metrics and traces, and Sentry groups exceptions by stack into issues. Loki indexes only stream labels, so speed depends on a precise selector, and labels must have low cardinality. A thousand identical exceptions in Sentry are one issue. Sentry does not replace backend logs.
Logs · Loki, Datadog, Sentry
One failure a thousand times or a thousand different failures? Which tool answers faster?
After a release the logs hold a thousand ERRORs. If it is one repeating exception, fixing one cause is enough. If they differ, it is more serious. Different tools help to tell: Loki quickly selects and counts entries with labels, Sentry groups exceptions by stack, Datadog links logs with metrics and traces in one place. This lesson covers how they differ and how to ask the first question in each.
Grafana Loki. This is a log system that indexes only the labels of a stream (service, environment, pod) and not the full text. This makes it cheaper than full-text indices: the rest is filtered at query time by scanning. Queries are written in LogQL in Grafana (Explore). A query starts with a stream selector in curly braces (at least one non-empty condition is required), followed by pipeline steps:
Figure 1. Only the selector uses the index: the more precise it is, the less data the rest of the pipeline scans.
|= contains a string, != does not contain, |~ matches a regex, !~ does not match.
| json (or | logfmt) parses the line and creates labels from fields, which are then filtered (level="error").
Metric queries (count_over_time, rate) turn logs into a series for a chart or an alert; the range is in square brackets.
Hence the main trap: only fields with a bounded number of values (service, environment, cluster) become labels. If a request or user id becomes a label, the number of streams explodes and Loki slows down. Such values stay in the text and are searched with |= "id" or a parser.
Datadog. This is a SaaS for logs, metrics and APM traces in one place. When set up correctly, logs are linked with traces (the dd.trace_id and dd.span_id fields are added by the tracer), so from a trace you go to its logs in one click. Search in the Log Explorer is written through facets and attributes:
Sentry. This is an error tracker: it collects exceptions from the frontend and backend, groups them into issues by stack and fingerprint, shows breadcrumbs (what happened before the error), the environment and the release version. For QA it is useful to see whether an error is new in this very release, how many users it affected, on which browsers or OSes. A thousand identical exceptions is one issue with a counter, and this answers the question from the intro.
Example: the error count grew after a release. In Sentry you open issues filtered by the new release: one new issue appears, "TypeError: undefined is not an object (evaluating 'cart.promo')" in CartPage, 4,200 events, all in Safari 17. That points to the frontend and a browser, and the breadcrumbs show that the error happens after clicking "Apply promo code". Meanwhile in Loki you check whether there is a parallel spike of server errors: sum by (app) (count_over_time({env="prod", app=~"checkout|cart|promo"} |= "error" [5m])) shows no change, so the backend is not involved. Two queries are enough to hand a developer a concrete scenario instead of "something broke".
Limits and alternatives. The choice of tool depends on the company, so the main thing is to state the sequence: time, service and environment, level, request identifier, root cause. Loki is cheap but slow on a broad scan without a precise selector. Datadog is convenient but billed by log volume. Sentry sees only what reached the SDK as an exception and does not replace backend logs: a failure without an exception (a slow response, wrong data) it will not show.
Typical mistakes.
A broad selector ({env="prod"}) and a text filter: the query is slow or aborted by a limit.
Making a request id a label: Loki does not like high cardinality.
Looking in Sentry for a failure that throws no exception: it will not be there.
Not checking the release: an old error seems new or the other way round.
Check yourself
The query {env="prod"} |= "timeout" runs very slowly. How do you speed it up without changing its meaning?
Answer
Narrow the stream selector by indexed labels: add a service or a cluster, for example {env="prod", app="checkout"}, and shorten the time range. Loki’s index works only on labels, while the |= "timeout" filter scans the text of all selected streams.
Why are 4,200 events in Sentry not 4,200 different bugs?
Answer
Sentry groups events by stack and fingerprint into issues. Identical exceptions merge into one issue with an event counter and a count of affected users. So look at issues: new ones, in the new release, with the widest reach.
Related lessons: “ELK / OpenSearch and Kibana: KQL”, “Logs, metrics and traces: three signals”, “The command line: docker logs, kubectl logs, grep, jq”.
In an interview.Junior: Loki indexes only labels and searches with LogQL, Datadog collects logs, metrics and traces, Sentry groups errors. In any tool I go from time and service to level and request id. Middle/Senior: I understand that a precise label selector decides speed in Loki and that labels must have low cardinality. In Sentry I look at new issues of a specific release and at breadcrumbs. I combine tools: Sentry shows what broke on the client, logs and metrics confirm or exclude the backend.
The command line: docker logs, kubectl logs, grep, jq
A container writes its log to stdout and stderr, and docker logs and kubectl logs read this stored stream. So a log written to a file inside the container is not shown. In Kubernetes a restart creates a new container with an empty log, so for CrashLoopBackOff the cause is found with kubectl logs --previous and kubectl describe. JSON logs are filtered with jq.
Logs · Terminal
A pod is in CrashLoopBackOff and kubectl logs is empty. Where is the cause of the crash?
A test environment comes up, the service crashes and restarts, and kubectl logs shows nothing or only the start. Kibana or Grafana is not yet configured for this stand, but cluster access exists. Logs of a local environment, a stand and CI are read in a terminal, and a few commands known by heart save a lot of time. This lesson covers Docker, Kubernetes, grep, jq and PowerShell, and why commands are sometimes silent.
How it works and why. A container writes its log to stdout and stderr, and the runtime (Docker, Kubernetes) captures these streams and stores them. docker logs and kubectl logs read exactly this stored container stream. This is a simple model from which the rest follows: if an application writes its log to a file inside the container, docker logs is empty; if a container restarted, the current instance starts with a clean stream; if a pod is deleted, its logs disappear with it, leaving only what an agent managed to ship to a central store.
Docker:
docker logs -f --tail 100 api # follow, last 100 lines
docker logs --since 10m api # for the last 10 minutes
docker compose logs -f --tail=50 api db # several compose services
docker compose logs --no-color --timestamps > compose.log
Kubernetes:
kubectl logs deploy/checkout --since=15m
kubectl logs -f pod/checkout-7d9f -c app # a specific container
kubectl logs pod/checkout-7d9f --previous # the container that crashed
kubectl logs -l app=checkout --tail=100 --prefix # by label, with pod names
Why docker logs is empty
Wrong
A log into a file inside the container
The runtime sees only stdout and stderr. docker logs is empty, and the file has to be read through docker exec.
Right
A log to stdout
The stream is collected by the runtime and an agent into a central store and read with docker logs and kubectl logs.
Figure 1. Console output in a container is a contract: everything that must be visible from outside goes to stdout.
Example: CrashLoopBackOff. A service starts, crashes within a second, Kubernetes restarts it, the status is CrashLoopBackOff. The current container has just been created and its log is empty or cut off. The cause of the crash is in the previous instance, and --previous shows it:
kubectl get pods -l app=checkout # status and restart count
kubectl logs pod/checkout-7d9f --previous # the log of the crashed container
kubectl describe pod checkout-7d9f # events: OOMKilled, probe failed
If --previous shows an exception with a configuration error text, the bug is in environment variables or secrets of the stand. If there is no log at all and describe says OOMKilled, the container was killed for memory before it wrote anything. Two commands thus tell an application error from environment limits. For a deployment with several pods the kubectl logs deploy/… command takes only one pod, so use a label (-l) for the full picture.
Files and text.
tail -f app.log | grep --line-buffered ERROR # a live error stream
grep -n -C 3 "orderId=8841" app.log # 3 lines of context
grep -c "ERROR" app.log # a count
zgrep "timeout" app.log.2026-10-11.gz # in a compressed archive
Limits and alternatives. A terminal is good for quick pinpoint checks but not for history: Kubernetes keeps only what lies on the node, and log rotation trims old data. For several pods at once a terminal is inconvenient, while a central store gives search across all services. Commands with -f and tail -f hold the connection and can hang in a CI script, so scripts use --tail or --since without -f.
Typical mistakes.
Looking at the current container’s log after a restart: the cause of the crash is in --previous.
grep in a pipeline with tail -f without --line-buffered: output arrives late in batches.
jq on a file with mixed lines without -R and fromjson?: a parse error at the first non-JSON line.
Pasting the result into a bug report without checking for secrets.
Check yourself
A pod is in CrashLoopBackOff and kubectl logs is empty. Two commands that will show the cause.
Answer
kubectl logs pod/… --previous shows the log of the previous, crashed container. kubectl describe pod/… shows events and the termination reason (OOMKilled, readiness probe failures, ImagePull). Together they tell an application error from an environment limit.
jq -c 'select(.level=="error")' app.log ends with a parse error. The file has lines that are not JSON. How do you fix it?
Answer
Read lines as text and parse only those that are JSON: jq -R 'fromjson? | select(.level=="error")' app.log. The -R flag feeds each line as a string, and fromjson? silently skips those that do not parse.
Related lessons: “Where to find logs and how to localise a bug with them”, “Structured and plain-text logs”, “ELK / OpenSearch and Kibana: KQL”.
In an interview.Junior: For Docker I use docker logs with -f, --tail and --since, for Kubernetes kubectl logs, I search with grep and parse JSON with jq. Middle/Senior: I understand the model: the runtime keeps a container’s stdout and stderr, so a log in a file is invisible, and after a restart I look for the cause through --previous and describe. For several pods I use a label, and in CI scripts I do not leave -f. For history and search across all services I switch to a central store.