Tail Handler
The tail() handler is the handler you implement when writing a Tail Worker. Tail Workers can be used to process logs in real-time and send them to a logging or analytics service.
The tail() handler is called once each time the connected producer Worker is invoked.
To configure a Tail Worker, refer to Tail Workers documentation.
export default { async tail(events, env, ctx) { fetch("<YOUR_ENDPOINT>", { method: "POST", body: JSON.stringify(events), }) }}-
eventsarray- An array of
TailItems. OneTailItemis collected for each event that triggers a Worker. For Workers for Platforms customers with a Tail Worker installed on the dynamic dispatch Worker,eventswill contain two elements: one for the dynamic dispatch Worker and one for the User Worker.
- An array of
-
envobject- An object containing the bindings associated with your Worker using ES modules format, such as KV namespaces and Durable Objects.
-
ctxobject- An object containing the context associated with your Worker using ES modules format. Currently, this object just contains the
waitUntilfunction.
- An object containing the context associated with your Worker using ES modules format. Currently, this object just contains the
-
event.typestring- The type of event. This will always return
"tail".
- The type of event. This will always return
-
event.tracesarray- An array of
TailItems. OneTailItemis collected for each event that triggers a Worker. For Workers for Platforms customers with a Tail Worker installed on the dynamic dispatch Worker,eventswill contain two elements: one for the dynamic dispatch Worker and one for the user Worker.
- An array of
-
event.waitUntil(promisePromise): void- Refer to
waitUntil. Note that unlike fetch event handlers, tail handlers do not return a value, so this is the only way for trace Workers to do asynchronous work.
- Refer to
-
scriptNamestring- The name of the producer script.
-
eventobject- Contains information about the Worker’s triggering event.
- For fetch events: a
FetchEventInfoobject - For other event types:
null, currently.
- For fetch events: a
- Contains information about the Worker’s triggering event.
-
eventTimestampnumber- Measured in epoch time.
-
logsarray- An array of TailLogs.
-
exceptionsarray- An array of
TailExceptions. A single Worker invocation might result in multiple unhandled exceptions, since a Worker can register multiple asynchronous tasks.
- An array of
-
outcomestring- The outcome of the Worker invocation, one of:
unknown: outcome status was not set.ok: The worker invocation succeeded.exception: An unhandled exception was thrown. This can happen for many reasons, including:- An uncaught JavaScript exception.
- A fetch handler that does not result in a Response.
- An internal error.
exceededCpu: The Worker invocation exceeded either its CPU limits.exceededMemory: The Worker invocation exceeded memory limits.scriptNotFound: An internal error from difficulty retrieving the Worker script.canceled: The worker invocation was canceled before it completed. Commonly because the client disconnected before a response could be sent.responseStreamDisconnected: The response stream was disconnected during deferred proxying. Happens when either the client or server hangs up early.
- The outcome of the Worker invocation, one of:
-
requestobject -
responseobject
-
cfobject- Contains the data from
IncomingRequestCfProperties.
- Contains the data from
-
headersobject- Header name/value entries (redacted by default). Header names are lowercased, and the values associated with duplicate header names are concatenated, with the string
", "(comma space) interleaved, similar to the Fetch standard ↗.
- Header name/value entries (redacted by default). Header names are lowercased, and the values associated with duplicate header names are concatenated, with the string
-
methodstring- The HTTP request method.
-
urlstring- The HTTP request URL (redacted by default).
-
getUnredacted()object- Returns a TailRequest object with unredacted properties
Some of the properties of TailRequest are redacted by default to make it harder to accidentally record sensitive information, like user credentials or API tokens. The redactions use heuristic rules, so they are subject to false positives and negatives. Clients can call getUnredacted() to bypass redaction, but they should always be careful about what information is retained, whether using the redaction or not.
- Header redaction: The header value will be the string
“REDACTED”when the (case-insensitive) header name iscookie/set-cookieor contains a substring"auth”,“key”,“secret”,“token”, or"jwt". - URL redaction: For each greedily matched substring of ID characters (a-z, A-Z, 0-9, '+', '-', '_') in the URL, if it meets the following criteria for a hex or base-64 ID, the substring will be replaced with the string
“REDACTED”. - Hex ID: Contains 32 or more hex digits, and contains only hex digits and separators ('+', '-', '_')
- Base-64 ID: Contains 21 or more characters, and contains at least two uppercase, two lowercase, and two digits.
-
statusnumber- The HTTP status code.
Records information sent to console functions.
-
timestampnumber- Measured in epoch time.
-
levelstring- A string indicating the console function that was called. One of:
debug,info,log,warn,error.
- A string indicating the console function that was called. One of:
-
messageobject- The array of parameters passed to the console function.
Records an unhandled exception that occurred during the Worker invocation.
-
timestampnumber- Measured in epoch time.
-
namestring- The error type (For example,
Error,TypeError, etc.).
- The error type (For example,
-
messageobject- The error description (For example,
"x" is not a function).
- The error description (For example,
- Tail Workers - Configure a Tail Worker to receive information about the execution of other Workers.
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Directory
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark