Skip to main content

Lightweight OpenTelemetry logging client for LogzAI

Project description

logzai-otlp

Lightweight OpenTelemetry logging client for LogzAI.

  • Transport: OTLP over HTTP or gRPC
  • Structured logs: pass arbitrary keyword args as attributes
  • Graceful shutdown: buffers flushed on process exit

Installation

pip install logzai-otlp

Quick start (HTTP OTLP)

from logzai_otlp import logzai

logzai.init(
    ingest_token="your-ingest-token",
    ingest_endpoint="https://ingest.logzai.com",  # Base OTLP endpoint
    service_name="orders-api",
    environment="prod",
    protocol="http",  # default
)

logzai.info("User logged in", user_id="123", method="oauth")
logzai.error("Payment failed", order_id="42", reason="card_declined")

# optional – logs are flushed automatically at process exit
logzai.shutdown()

Using standard logging

This client installs an OpenTelemetry handler on the logzai logger. You can use the standard library logging API if you prefer:

import logging
from logzai_otlp import logzai

logzai.init(ingest_token="your-token", ingest_endpoint="https://ingest.logzai.com")

logger = logging.getLogger("logzai")
logger.info("Inventory updated", extra={"sku": "A-42", "qty": 3})

API

logzai.init(
    ingest_token: str,
    ingest_endpoint: str = "http://ingest.logzai.com",
    min_level: int = logging.DEBUG,
    *,
    service_name: str = "app",
    service_namespace: str = "default",
    environment: str = "prod",
    protocol: str = "http",  # "http" | "grpc"
    mirror_to_console: bool = False,
) -> None
  • ingest_token: Your LogzAI ingest token; sent as x-ingest-token header
  • ingest_endpoint: Base OTLP collector endpoint (paths /logs and /traces are appended automatically)
    • HTTP example: https://ingest.logzai.com
    • gRPC example: ingest.logzai.com:4317
  • min_level: Minimum logging level (default: logging.DEBUG)
  • service_name: OpenTelemetry service.name resource attribute
  • service_namespace: OpenTelemetry service.namespace resource attribute
  • environment: OpenTelemetry deployment.environment resource attribute
  • protocol: http (default) or grpc
  • mirror_to_console: Also log to console/stdout (default: False)

Convenience logging helpers:

logzai.debug(message: str, exc_info: bool = False, **attrs) -> None
logzai.info(message: str, exc_info: bool = False, **attrs) -> None
logzai.warning(message: str, exc_info: bool = False, **attrs) -> None
logzai.warn(message: str, exc_info: bool = False, **attrs) -> None  # alias of warning
logzai.error(message: str, exc_info: bool = True, **attrs) -> None
logzai.critical(message: str, exc_info: bool = True, **attrs) -> None
logzai.exception(message: str, **attrs) -> None  # logs with full exception info
logzai.shutdown() -> None  # flush and shutdown provider

All extra keyword arguments are sent as structured log attributes. The exc_info parameter controls whether exception information is automatically captured when available.

Tracing

LogzAI now includes distributed tracing capabilities alongside logging:

from logzai_otlp import logzai

logzai.init(ingest_token="your-token", ingest_endpoint="https://ingest.logzai.com")

# Create spans manually
span = logzai.start_span("database_query")
span.set_attribute("table", "users")
span.end()

# Use context manager for automatic span lifecycle
with logzai.span("api_request") as span:
    logzai.info("Processing request", request_id="123")
    span.set_attribute("method", "GET")
    span.set_attribute("path", "/api/users")
    # span ends automatically, even on exceptions

Tracing methods:

logzai.start_span(name: str, **kwargs) -> Span
logzai.span(name: str, **kwargs)  # context manager
logzai.set_span_attribute(span: Span, key: str, value: Any) -> None

Requirements

  • Python >= 3.9
  • opentelemetry-sdk>=1.27.0
  • opentelemetry-exporter-otlp>=1.27.0

License

MIT – see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

logzai_otlp-1.0.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

logzai_otlp-1.0.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file logzai_otlp-1.0.0.tar.gz.

File metadata

  • Download URL: logzai_otlp-1.0.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for logzai_otlp-1.0.0.tar.gz
Algorithm Hash digest
SHA256 aeaef294b8783ce4f4b67f464dc0e7b36a0afbd024730557533d7c4c6ad1617a
MD5 46160d5a6c078501f32924ff48e5b1b6
BLAKE2b-256 388a28c3b964445ec44138a6f957eac2c9d47202d48a1ad2e1a16c6028a5c71a

See more details on using hashes here.

File details

Details for the file logzai_otlp-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: logzai_otlp-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for logzai_otlp-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 68f96a1a6141f66811c71aa1a65609f64796eee1209afe72fda929e6c97ff541
MD5 4076f4305a0a2205aa9c87f255fd77bb
BLAKE2b-256 d14dcb9a350f154916f6a8edad4e2e537976a2fd0f8b304955ed2142cf8547f6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page