Fixing Loki line_too_long and label validation errors

A practical guide to why Loki rejects pushes for oversized lines and bad labels, how to fix the source before changing limits, and when truncation is the right trade-off.

On this page

Why Loki rejects lines and labels, and how to fix the cause

Start by reading the rejection reason, then fix the sender. When an agent reports failed pushes or dropped logs, Loki usually returns a validation reason with the rejection. Those reasons map to the push request validation checks in the Loki docs: line_too_long, invalid_labels, missing_labels, max_label_names_per_series, label_name_too_long, label_value_too_long and duplicate_label_names. Each one marks a stream or line that broke a limit or format rule. The checks exist to protect ingesters and query performance, because malformed labels and oversized lines are costly to index, store and search. In most cases the shipper is producing the bad data, so the first step is to inspect what the agent sends before changing anything on the Loki side.

Work through the reasons in a practical order. Check that every stream has at least one label (missing_labels), that label names follow Loki's naming rules (invalid_labels), that no label name appears twice in the same push (duplicate_label_names), and that the number of label names per series stays within the configured maximum (max_label_names_per_series). Then look at length: label names and values that are too long are rejected under label_name_too_long and label_value_too_long, which often come from putting raw request IDs, full URLs or message content into labels. Confirm the exact current defaults and limit keys for your Loki version in the troubleshooting and request validation docs before editing any configuration, because these settings are tuned per release.

Oversized lines need a deliberate decision. Loki recommends against raising max_line_size above 256kb, so the usual fix is to shorten or split the log line at the agent, or to drop fields that do not need to be stored. If you cannot change the source, max_line_size_truncate lets Loki ingest a truncated line, optionally with a marker showing that truncation happened. Before enabling it, decide who needs the full message and whether truncated entries still support your investigations. Track rejected pushes by reason after each change so you can confirm the fix worked and that no new validation errors appear.

Which fix fits each validation error

This table maps each Loki push validation error to its most likely cause, the change that fixes the sender or configuration, and when raising a limit or enabling truncation is a reasonable choice. Read it by finding the error name in your ingestion logs or discarded sample metrics, then working across the row to the first fix to try. The main takeaway is that most of these errors are fixed at the sender, and limits should move only after the payload is understood.

Validation errorLikely causeFix at the sender or configWhen raising a limit or truncating fits
line_too_longLog lines exceed max_line_size, often stack traces, embedded JSON or base64 payloadsSplit or shorten the emitting log statement, drop bulky fields at the agent, and confirm the agent does not merge multiple linesRaise max_line_size only for a known, bounded need. The rate limits docs advise not going above 256kb. Use max_line_size_truncate when losing the tail of a line is acceptable
invalid_labelsLabel names or values contain characters Loki rejects, or the agent attaches malformed label keysRelabel in Grafana Alloy or the shipper to sanitize keys and remove unsafe characters before the pushRarely a limit issue. Fix the relabel rules first, then confirm with a test push
missing_labelsA stream arrives with no labels, usually from a misconfigured source or an unset pod or host labelEnsure every pipeline sets at least one label, and add a default job or host label in the agent configNot a fit for limits. Labels must exist for the push to be accepted
max_label_names_per_seriesDynamic keys, such as request IDs or user fields, are promoted to labelsMove high-variance fields to structured metadata or drop them, and keep only stable identifiers as labelsRaising the limit usually raises cardinality cost. Consider it only after confirming the labels are intentional
label_name_too_longA generated or copied field name is longer than the configured maximumShorten the key at the source or rename it in the relabel stageAdjust the limit only if a legitimate, documented name is blocked. Confirm the key in your Loki version
label_value_too_longA label value carries free text, a URL, a query string or an error messageMove free text out of labels, extract only a bounded value, or drop the field before shippingRarely appropriate. Long values as labels inflate streams, so structured metadata is usually the better home
duplicate_label_namesThe same key appears twice in one stream, often from merging pipeline stages or from a parser adding a key already presentRemove the duplicate in the parser or relabel stage so each key is set onceNot a limit issue. Fix the pipeline so the key is unambiguous

How to triage a validation rejection in production

This sequence takes a push rejection from a single error message to a verified fix, so the team changes the sender or the labels first and only then considers raising a limit or enabling truncation.

  1. Read the rejection reason from logs and metrics

    Start by identifying which validation error Loki reported, such as line_too_long, invalid_labels, missing_labels, max_label_names_per_series, label_name_too_long, label_value_too_long or duplicate_label_names. Check the distributor or write path logs for the reason string, then confirm the same reason appears in the discarded sample metrics for the affected tenant. The step is done when you can name one reason and show a matching count over the failure window.

  2. Identify the sending agent and stream

    Use the rejection log entry to find the tenant ID from the X-Scope-OrgID header, the labels in the rejected stream and the host, container or pod that produced it. Match those labels against your shipper configuration, typically Grafana Alloy, to find the exact pipeline. Some rejections come from older agents such as Promtail, which has reached end of life, so note the shipper version too. The step is done when one sending agent and one stream selector are named as the source.

  3. Correct labels or shape logs at the shipper

    Fix the cause where it starts. For label errors, adjust the label set in the Alloy pipeline so names and values are valid, required labels are attached and duplicate keys are removed. For oversized lines, split or filter the source output, or move bulky fields into structured metadata where that fits your configuration. Make one change at a time and restart only the affected pipeline. The step is done when the agent's configuration diff is reviewed and reloaded without errors.

  4. Verify with a test push

    Send a small, known test line through the corrected pipeline, using a label set that matches the production stream but a clearly marked test value. Confirm the push returns success and that the discarded sample counter for that reason stops increasing. Keep the test line free of sensitive data. The step is done when the test push is accepted and the rejection counter stays flat for the agreed observation period set by your team.

  5. Confirm the logs are queryable in Grafana

    Accepted pushes are not enough. Open Grafana, select the Loki data source for the correct tenant, and run a LogQL query that filters on the test marker and the corrected labels. Check that the expected lines appear with the labels you intended, and that the production stream shows new entries after the fix. The step is done when the query returns the test line and the label names match your naming standard.

  6. Decide whether limits or truncation should change

    Only after the shipper fix is verified, decide whether a limit change is justified. Loki's documentation recommends not increasing max_line_size above 256kb. If lines are legitimately large, consider max_line_size_truncate, which ingests truncated lines with an optional marker, and record that the truncated data is incomplete. For label limits, document the naming change or limit change in your configuration repository and get sign-off from the owner of the tenant. The step is done when the decision, its reason and any configuration change are recorded.

  7. Record the fix and watch for recurrence

    Write down the rejection reason, the sending agent, the change made, the verification results and the owner of the stream. Add or confirm an alert on the discarded sample metric for that reason so a regression is noticed. Ask the team that owns the sender to review the same label pattern in other pipelines. The step is done when the alert exists, the runbook entry is saved and the owner has acknowledged the change.

When truncating long lines is the right trade-off

Truncation is the right trade-off only when the lost tail of a line is genuinely low value and the fields you search for sit near the start. Loki's max_line_size_truncate setting lets Loki accept a push with an oversized line by cutting it at the configured limit instead of rejecting the entry with line_too_long. You can also enable an optional marker so that truncated lines are visibly flagged in storage, which helps later when someone wonders why a stack trace stops mid-sentence. Before you switch it on, confirm the exact key names, marker behavior and default limits for your Loki version in the Loki rate limits and push request validation docs.

The cost of truncation is data loss that is easy to miss. Everything after the cut point is gone, so a JSON payload whose error or user_id field lands after the limit becomes unsearchable, and a multi-line exception may lose the frame that explains the failure. Sample a week of rejected lines from your line_too_long metrics or discarded-sample logs and check where your most-queried fields sit within them. If those fields are late in the line, truncation will hide the data your on-call engineers need most, and you should fix the source instead.

Prefer changing the producer when lines are large by design. Splitting a long message into several shorter entries keeps every byte searchable, dropping noisy fields such as full request bodies or base64 blobs removes data nobody queries, and moving bulky but filterable values into structured metadata keeps them out of the line body while still allowing filtering. Do not raise max_line_size above 256kb to avoid these changes: the documented guidance is not to increase it past that size, because very large lines raise memory and query cost for the whole cluster. Confirm which of these options your log shipper supports before you commit to a design.

Security and operational risks of loosening validation

Relaxing validation to stop rejected pushes moves the cost into label cardinality, retained evidence, data exposure and other teams' service. Each card below is a risk to check before changing a limit or enabling truncation in production.

Unbounded label creation

Every distinct label name and value creates new streams, and each stream adds index and storage work. If validation is loosened to accept unknown or high-variance labels, a single misbehaving client can multiply streams quickly. Before raising max_label_names_per_series or the label length limits, list the labels each source actually sends and confirm which ones belong in the index. Use structured metadata for high-variance values where your Loki version supports it.

Validation limits docs

Truncation hiding audit evidence

Enabling max_line_size_truncate stores a shortened version of a line, so the tail of an event may be gone for good. If the log is later needed for an audit, incident review or legal request, the stored record may not show what happened. Decide which log sources must keep complete lines, and confirm with your compliance owner whether a truncation marker is acceptable as evidence before turning truncation on.

Truncation settings docs

Sensitive data in oversized lines

Large lines often carry full request bodies, stack traces, tokens or customer records that were never meant to be logged. Raising max_line_size lets that content into storage, where retention and access rules then apply to it for the full retention period. Before raising the limit, sample rejected lines from the affected source, search them for secrets and personal data, and fix the logging code at the source where possible.

Tenant-wide limit changes

With auth_enabled set to true, each tenant is identified by the X-Scope-OrgID header, and limits can be set per tenant. Changing a default or a shared tenant's limit can alter ingestion for every team that writes to that tenant. Before applying a change, identify which tenants and sources it affects, and scope the change to the tenant that needs it rather than editing defaults for the whole cluster.

Dropped logs without alerts

Rejected pushes return errors to the shipper, but a rejected line never reaches the store, so nothing in Loki shows the gap unless someone watches for it. Relaxing a check can hide the drop entirely, and tightening it can silently lose new log types. Watch the discarded samples metrics per reason and per tenant, and alert when a validation reason rises, so a rejection becomes a visible event.

Changes made without a test push

A limit change that looks correct in a config file can behave differently under real traffic, especially when several limits interact. Apply the change in a non-production environment first, then push a representative sample from each affected source, including the longest lines and the most labels. Check the stored result in Grafana Explore before rolling the change to production and record the values you changed.

Questions teams ask before fixing validation errors

How long does it take to fix Loki line_too_long and label validation errors?

The duration depends mainly on how many agents, pipelines and tenants are sending rejected data, and on whether the root cause is a configuration problem or a logging pattern that the application team has to change. A single shipper with one misconfigured label is usually a short investigation. A fleet with mixed agents, several tenants and oversized application logs takes longer because each source needs its own check and fix. Ask any partner for a timeline only after they have reviewed your rejection counts, Loki configuration and sample pushes, and ask them to list which fixes sit with your teams and which sit with theirs.

Can our own team fix Loki validation errors without a partner?

Yes, many teams can. The work is mostly reading the validation reason in Loki's ingestion metrics and logs, finding which agent or pipeline produces the bad push, and correcting labels, line handling or shipper configuration. The harder parts are usually cross-team: agreeing label conventions, changing application logging, and deciding which limits to change per tenant. Teams without someone who owns the log shipper configuration or who can test pushes against a non-production cluster tend to benefit from outside help. Ask yourself who can change each sending source before you start.

What access and information does a partner need to start?

A partner typically needs read access to the Loki configuration, including the limits block and the authentication setup, and a list of the agents, Alloy or OpenTelemetry pipelines, Fluent Bit or Docker logging configurations that push data. Sample rejected log lines, with sensitive content removed, help confirm which validation reason is firing. A list of tenant IDs, the header used to identify them, and the expected label schema are also needed. Confirm with your security team how sample logs are shared and where they are stored before anything leaves your environment.

Is it safe to raise Loki's line size or label limits?

Raising limits is safe only when you understand what the limit protects and you have measured the impact. Loki's documentation recommends not increasing max_line_size above 256kb, so the first step is usually to find the source of oversized lines rather than enlarge the limit. Label limits such as the maximum number of label names per series exist to protect index size and query speed, so a higher value can increase memory and storage cost. Change limits per tenant where possible, test the change in a non-production cluster, and watch ingestion and query metrics after the change.

How do we tell truncated lines from actual data loss?

Truncation keeps the start of a line and discards the rest, so the event is stored but its tail is missing. Data loss means the push was rejected and the line is not stored at all. Loki's max_line_size_truncate option lets oversized lines be ingested in truncated form, with an optional marker, which makes truncated lines visible in queries. Check the discarded-samples metrics to see whether lines were rejected, then search for the truncation marker in stored data to see whether they were shortened. Decide with your compliance team whether truncated audit or security events are acceptable before enabling the option.

What does a quote for this work depend on?

A quote follows from a written scope, so it depends on the number of Loki clusters and tenants involved, the number and type of log shippers that need correction, whether application logging must change, and how much testing and verification your change process requires. It also depends on whether you want a one-time remediation, a documented runbook for your team, or an ongoing retainer for monitoring rejections. DeployOpen does not publish a price list. Ask for a scope that lists each source, each deliverable and each item your team must provide.

Do validation fixes need to be re-tested after application or agent upgrades?

Yes. Validation rules and the behavior of shippers can change between versions, and a new application release can introduce longer messages or new label values without any configuration change. Build a check that watches the validation reason counters after each deploy, and repeat test pushes after upgrades to Loki or to your log agent. Ongoing monitoring and periodic testing can be scoped as a retainer, while the initial fix is usually a one-time piece of work. Ask any partner how they would detect regressions in your environment.

How a push passes validation before it is stored

A log line leaves the application or host through a shipper such as Grafana Alloy, reaches the Loki distributor, and is checked against the per-line and per-label limits before any chunk is written. A line that passes goes on to the ingesters. A line over max_line_size is either truncated, when max_line_size_truncate is enabled, or rejected. Any rejection increments a discarded-sample metric and writes a log entry, so check those two signals first when a push fails.

Validation checks a push runs through before Loki stores it.

Confirming the fix holds after the change

The first check is whether rejections have actually stopped. After the fix is deployed, watch the discarded sample counts broken down by reason and confirm that line_too_long, invalid_labels, missing_labels, max_label_names_per_series, label_name_too_long, label_value_too_long and duplicate_label_names have dropped to the level you expect for the affected tenant or stream. Compare the counts against a window from before the change so you can see the difference, not just the current number. If a reason is still climbing, the fix covered one source of bad pushes but not all of them, and the troubleshooting steps for that reason still apply. Confirm which metric and dashboard your team uses for discarded samples, since the exact names come from your Loki version and the mixin you run.

Next, run a test push with one known-good line and one known-bad line from the same agent path that production uses. The good line should be accepted and queryable in Grafana, and the bad line should be rejected with the validation reason you expect. If you chose truncation with max_line_size_truncate, confirm that the oversized line arrives shortened and carries the marker you configured, and check that the truncated content is still useful for the investigations your team runs. Test with the same tenant header, through the same authenticating reverse proxy and the same shipper version that production uses, because a test sent directly to Loki can pass while the real path still fails. Record the result so the next change has a baseline. The Loki troubleshoot ingestion guide lists the reasons to check if the test fails.

The last check is a standing alert on validation rejections. Set an alert on the rate of discarded samples for these reasons, scoped per tenant if you run multi-tenant, so a new agent version, a changed log format or a new service with long labels is caught within the first hours rather than in a later incident review. Decide who receives the alert and what they do first, and review it after every shipper or Alloy upgrade and every change to log formats in applications. Confirm the alert threshold against your normal baseline so it does not fire on expected low-level noise. Write the alert and the test push into your change checklist so the verification repeats whenever the pipeline changes.

How DeployOpen works on this

DeployOpen plans and fixes Loki ingestion validation errors inside your own infrastructure, starting from the rejected pushes and the limits your tenants actually need. Each engagement begins with a written scope that names the validation errors, the clients and tenants involved and the decisions your team must approve.

How we scope

  • Collect the rejected push responses and the validation error names your ingestion path is returning today
  • Map which shippers, label sets and tenants produce each rejected line or label
  • Agree in writing whether lines are split, truncated with a marker, or the source is changed
  • Record which label naming rules and per-tenant limits your organization will approve before changes start

How we build

  • Correct label extraction in Grafana Alloy or the shipper configuration that produces invalid or duplicate labels
  • Adjust tenant limits, including max_line_size_truncate, only after reviewing the 256kb guidance in the docs
  • Test changed pipelines with representative log samples in a non-production Loki before any production rollout
  • Document each validation error, its cause and the configuration change that resolved it

How we hand over

  • Deliver the written configuration, limit settings and a list of changed shipper pipelines for your team to review
  • Provide a runbook that explains each validation error and the first checks to run when it reappears
  • Walk your operators through reading ingestion rejection metrics so they can confirm fixes after handover
  • Confirm with your team which owners approve future label and limit changes

How we support

  • Fixed-scope engagements are agreed in writing before work starts, with deliverables and timelines stated in the scope
  • Ongoing support, upgrades and continuous testing are available as a retainer if your Loki cluster keeps changing
  • Retainer scope for validation errors is set in writing, so you can confirm response expectations before signing
  • Request a quote based on the written scope, which is the basis on which DeployOpen prices any engagement

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.