Requests, traces and fields
Polylane reads some fields of each event as standard fields. Two of them connect your events:
- A request id groups all the events of one request. The Requests tab on the Telemetry page shows each request with its duration, its status and all its logs.
- A trace id connects a log to the spans of its trace. From a log, select View trace to open the trace. From a request, select Open trace.
Add both to every event. Then you can go from an error log to the request that caused it, and from the request to the slow call in its trace.
Group events by request
Give each request one id, and put that id on every event that the request makes. A request can be an HTTP request, a queue message, a scheduled job or a build.
JSON events
Add a requestId field to each event:
curl -X POST "https://events.polylane.com/v1/checkout-api" \
-H "Content-Type: application/json" \
-H "x-polylane-telemetry-token: <your-telemetry-token>" \
-H "x-polylane-service: checkout" \
-d '[
{ "message": "Checkout started", "level": "info", "requestId": "req_8f2c" },
{ "message": "Stripe declined the card", "level": "error", "requestId": "req_8f2c", "error": "card_declined" },
{ "message": "Checkout done", "level": "info", "requestId": "req_8f2c", "duration": 412 }
]'
Use the request id that your platform or load balancer gives you when there is one, such as the x-request-id header. Otherwise make one when the request starts. Add it to your logger once, so that each log line carries it:
import { randomUUID } from "node:crypto";
import express from "express";
import pino from "pino";
const logger = pino();
const app = express();
app.use((req, res, next) => {
const requestId = req.get("x-request-id") ?? randomUUID();
req.log = logger.child({ requestId });
res.set("x-request-id", requestId);
next();
});
app.post("/checkout", (req, res) => {
req.log.info("Checkout started");
res.sendStatus(201);
});
import logging
import uuid
from contextvars import ContextVar
from flask import Flask, g, request
request_id: ContextVar[str] = ContextVar("request_id", default="")
class RequestIdFilter(logging.Filter):
def filter(self, record):
record.requestId = request_id.get()
return True
app = Flask(__name__)
app.logger.addFilter(RequestIdFilter())
@app.before_request
def set_request_id():
request_id.set(request.headers.get("x-request-id") or str(uuid.uuid4()))
Use a JSON formatter, such as python-json-logger, so that requestId is a field of each log line.
func withRequestID(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
id := r.Header.Get("x-request-id")
if id == "" {
id = uuid.NewString()
}
logger := slog.Default().With("requestId", id)
ctx := context.WithValue(r.Context(), loggerKey{}, logger)
next.ServeHTTP(w, r.WithContext(ctx))
})
}
Polylane reads the request id from the first of these fields that has a value. A dot in a name is a nested field, so request.id is { "request": { "id": "..." } }.
requestId, requestID, requestid, request_id, request.id, reqId, @requestId, aws_request_id, function_request_id, integrationrequestid, integration_request_id, faas.invocation_id, faas.execution
OpenTelemetry
Set a requestId attribute (or request_id) on the spans and log records of the request. Polylane also uses faas.execution and cloudflare.invocation_id when your instrumentation sets them, so AWS Lambda and Cloudflare Workers spans get a request id with no change.
import { trace } from "@opentelemetry/api";
trace.getActiveSpan()?.setAttribute("requestId", requestId);
What the Requests tab shows
Each row is one request. Polylane takes:
- the service and the route from the first event that has them;
- the duration from the largest
durationof its events, or from the first and the last event; - the status from the first status code of its events;
- a failure when any event has an error, an error level or a status code of 500 or more.
Expand a row to see the logs of the request. Expand a log to see all its fields. The Trace tab shows the spans of the request on a timeline.
Connect logs to traces
A log with a trace id shows View trace. A log with a span id also shows under its span in the trace.
OpenTelemetry logs
When you send logs over OTLP, the trace id and the span id of each log record connect it to its trace. The OpenTelemetry instrumentations for common loggers, such as Pino, Winston, the Python logging module and Go slog, add them to each record when a span is active. You do not have to add fields.
JSON logs
Read the ids from the active span and add them as traceId and spanId:
import { trace } from "@opentelemetry/api";
const context = trace.getActiveSpan()?.spanContext();
logger.info({ traceId: context?.traceId, spanId: context?.spanId }, "Checkout started");
from opentelemetry import trace
context = trace.get_current_span().get_span_context()
logger.info("Checkout started", extra={
"traceId": format(context.trace_id, "032x"),
"spanId": format(context.span_id, "016x"),
})
context := trace.SpanContextFromContext(ctx)
logger.InfoContext(ctx, "Checkout started",
"traceId", context.TraceID().String(),
"spanId", context.SpanID().String(),
)
Polylane reads the trace id from traceId, traceID, trace_id, trace.id or xray_trace_id, and the span id from spanId, spanID, span_id or span.id.
Standard fields
Polylane reads these fields from JSON events. It takes the first name in each list that has a value. All other fields are attributes, and you can filter, group and calculate on each of them.
| Field | Names that Polylane reads | Notes |
|---|---|---|
| Message | message, Message, msg, log, Log, content, @message, data.message, data.msg | The text of the event. |
| Level | level, Level, lvl, logLevel, LogLevel, log_level, loglevel, log.level | error, err, fatal and critical make the event an error. |
| Error | error, error.message, error.name, error.code, err, err.message, e, e.message, data.errorMessage | An event with an error counts as a failure. Send a string, such as the message of the exception. |
| Duration | duration, durationMS, durationms, responseTime, @duration | Milliseconds. Put it on at least one event of each request. |
| Status code | statusCode, status_code, http.status_code | A code of 500 or more counts as a failure. |
| Timestamp | timestamp, @timestamp, time, ts, date, datetime | Milliseconds since the Unix epoch, or an ISO 8601 string. When it is not set, Polylane uses the time it received the event. |
| Service | service, or the x-polylane-service header, or the path /v1/<dataset>/<service> | Use the same service name on all the events of a service. |
| Request id | See Group events by request | |
| Trace id, span id | See Connect logs to traces |
OpenTelemetry data uses the OpenTelemetry fields: service.name for the service, the span and log record fields for the ids, times and status, and the severity for the level.
Scrubbing
Polylane scrubs the values of fields whose names show a secret, before it stores the event. It does this for JSON events and for OpenTelemetry spans, span events, logs and metrics.
Polylane splits each field name at its dots, and compares each part to the names below. Case does not matter, so clientSecret matches clientsecret. The part must be equal to a name in the list.
| Kind | Names |
|---|---|
| Passwords | password, passwd, pwd, passphrase |
| Secrets and keys | secret, client_secret, client-secret, clientsecret, secret_key, secret-key, secretkey, secret_access_key, secretaccesskey, aws_secret_access_key, private_key, private-key, privatekey, api_key, api-key, apikey, x-api-key, access_key, accesskey |
| Tokens | token, access_token, access-token, accesstoken, refresh_token, refresh-token, refreshtoken, id_token, idtoken, auth_token, auth-token, authtoken, x-auth-token, x-access-token, session_token, sessiontoken, bearer, jwt, csrf_token, csrftoken, x-csrf-token, x-xsrf-token |
| Authorization | auth, authorization, proxy-authorization, authorizer, credentials, creds |
| Cookies | cookie, cookies, set-cookie |
| Connection strings | connection_string, connectionstring, database_url, databaseurl, dsn |
| Payment and identity | card_number, cardnumber, credit_card, creditcard, cvv, cvc, ssn |
| Client addresses | sourceip, clientip |
For example, Polylane scrubs password, user.Password, headers.authorization, http.request.header.cookie and config.privateKey. It does not scrub userPassword or gen_ai.usage.input_tokens, because no part of these names is equal to a name in the list. It keeps session.id, requestId and traceId, because Polylane uses them to group your events.
Polylane replaces a scrubbed value with stars, one for each character, up to 16 stars. You can still see that the field was there, but not its value.
Polylane does not look inside values. A secret in a message, in an error text or in the query string of a URL stays as you send it. Remove secrets and personal data before you send an event, or put them in a field whose name is in the list.
Polylane does not store the headers of the requests that you send to it. It reads your telemetry token, the dataset and the service from them. For browser events from the Polylane React library, it also keeps the device, the browser and the country.
Limits
| Limit | Value |
|---|---|
| Event size | 16 KB for each event |
| Attribute value | 2,048 characters |
| Attribute name | 256 characters |
| Message and error | 3 KB each |
| Request id, trace id, span id, service and level | 256 bytes each |
| Span name, route and URL | 512 bytes each |
| Event time | Up to 2 days before or after the time Polylane receives it |
Polylane shortens a value that is longer than its limit. When an event is larger than 16 KB, Polylane keeps the standard fields and the first attributes, and drops the attributes that do not fit. Polylane marks a shortened event as truncated. Polylane does not store an event whose time is out of range.