LOCAL QUICKSTART

Your first useful JSON event.

Choose Python or JavaScript, save the example, and run it locally. Both examples use the standard library, generate an event identifier, and write to standard output.

Before you start

You need Python 3.10 or later for the Python example, or Node.js 18 or later for the JavaScript example. No package installation, account, API key, or network connection is required by the example code. Use a supported runtime for your own deployment.

The status, duration, route, and service values below are synthetic. The timestamp and event identifier are generated when you run the script. Neither script reads application requests or sends data to this website.

Python: one event, one line

Save the file as log-example.py, then run python3 log-example.py. The function builds only an approved field set and rejects invalid numeric measurements.

Python · log-example.py
"""Print one safe structured event locally. Python 3.10+; standard library only."""
from datetime import datetime, timezone
import json
import sys
from uuid import uuid4


def request_completed(status_code: int, duration_ms: float) -> dict:
    if isinstance(status_code, bool) or not isinstance(status_code, int):
        raise TypeError("status_code must be an integer")
    if not 100 <= status_code <= 599:
        raise ValueError("status_code must be between 100 and 599")
    if isinstance(duration_ms, bool) or not isinstance(duration_ms, (int, float)):
        raise TypeError("duration_ms must be numeric")
    if not 0 <= duration_ms < float("inf"):
        raise ValueError("duration_ms must be finite and non-negative")
    return {
        "schema_version": "1.0",
        "event_id": str(uuid4()),
        "timestamp": datetime.now(timezone.utc).isoformat(),
        "event_name": "request.completed",
        "severity": "INFO",
        "service": "local-example",
        "attributes": {
            "route": "/orders/{id}",
            "status_code": status_code,
            "duration_ms": duration_ms,
        },
    }


if __name__ == "__main__":
    try:
        event = request_completed(200, 42.0)  # Synthetic measurements.
        print(json.dumps(event, allow_nan=False), flush=True)
    except (TypeError, ValueError, OSError) as exc:
        print(f"Could not emit example: {type(exc).__name__}", file=sys.stderr)
        sys.exit(1)
Download Python example

JavaScript: a small native object

Save the file as log-example.mjs, then run node log-example.mjs. Keep it as an ES module. The output is a JSON line you can inspect without a collector.

JavaScript · log-example.mjs
// Print one synthetic event locally. Node.js 18+; no packages or network calls.
import { randomUUID } from 'node:crypto';

export function requestCompleted(statusCode, durationMs) {
  if (!Number.isInteger(statusCode) || statusCode < 100 || statusCode > 599) {
    throw new TypeError('statusCode must be an HTTP status integer');
  }
  if (!Number.isFinite(durationMs) || durationMs < 0) {
    throw new TypeError('durationMs must be finite and non-negative');
  }
  return {
    schema_version: '1.0',
    event_id: randomUUID(),
    timestamp: new Date().toISOString(),
    event_name: 'request.completed',
    severity: 'INFO',
    service: 'local-example',
    attributes: {
      route: '/orders/{id}',
      status_code: statusCode,
      duration_ms: durationMs,
    },
  };
}

try {
  console.log(JSON.stringify(requestCompleted(200, 42)));
} catch (error) {
  // Do not copy an arbitrary event payload into the failure diagnostic.
  console.error('Could not construct the local example event');
  process.exitCode = 1;
}
Download JavaScript example

Inspect what you produced

Confirm that event_id is nonempty, the timestamp includes a timezone, and duration_ms remains a number. Check that the event describes a completed request rather than merely the start of a handler. The examples deliberately exclude real paths, headers, credentials, and request bodies.

The downloadable schema is a machine-readable reference for the envelope. Configure your chosen validator to enforce date-time formats; then test missing fields, extra top-level properties, and incorrect attribute types.

Before connecting production delivery

Replace synthetic measurements with values obtained at a documented boundary. Do not pass a complete request object into the attributes. Define event-specific allowlists and review any identifiers that could reveal people or secrets.

Writing to standard output is an emission boundary, not proof of durable storage. Choose a collector or hosting integration, test its configuration, and document how failure affects the application. Continue with delivery patterns and the full ingestion guide.