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 init, info, error, shutdown

init(
    org="your-org-id",
    api_key="your-api-key",
    service_name="orders-api",
    environment="prod",
    endpoint="https://collector.your-domain.tld/v1/logs",  # OTLP/HTTP endpoint
    protocol="http",  # default
)

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

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

Quick start (gRPC OTLP)

from logzai_otlp import init, info

init(
    org="your-org-id",
    api_key="your-api-key",
    # gRPC OTLP endpoints are host:port (no path)
    endpoint="collector.your-domain.tld:4317",
    protocol="grpc",
)

info("Started via gRPC", node="worker-1")

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 init

init(org="org", api_key="key")

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

API

init(
    org: str,
    api_key: str,
    *,
    service_name: str = "app",
    environment: str = "prod",
    endpoint: str = "http://localhost:4318/v1/logs",
    protocol: str = "http",  # "http" | "grpc"
) -> None
  • org: Your organization identifier; included in resource attributes
  • api_key: Sent as x-api-key header for OTLP/HTTP
  • service_name: OpenTelemetry service.name resource attribute
  • environment: OpenTelemetry deployment.environment resource attribute
  • endpoint: OTLP collector endpoint
    • HTTP example: https://collector.example.com/v1/logs
    • gRPC example: collector.example.com:4317
  • protocol: http (default) or grpc

Convenience logging helpers:

debug(message: str, **attrs) -> None
info(message: str, **attrs) -> None
warning(message: str, **attrs) -> None
warn(message: str, **attrs) -> None  # alias of warning
error(message: str, **attrs) -> None
critical(message: str, **attrs) -> None
shutdown() -> None  # flush and shutdown provider

All extra keyword arguments are sent as structured log attributes.

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-0.1.0.tar.gz (4.2 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-0.1.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for logzai_otlp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b0284fdcde192172b509a19f4b70bdde5f0fcff6002822c3274da830d7479b3b
MD5 72b725b473ca63d42581bb6a70d90dd6
BLAKE2b-256 b518bed0d6e67a8a00e1e13587a20eac67b93a4c8c8fc541a0de3492d4a91b4e

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for logzai_otlp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d42fcb96dde97f4e947729ec973e279c0600c0ab162fafe3b86280028122ac4a
MD5 e49f1e6fe6670a38407395abfc3dde6f
BLAKE2b-256 f159912c452f39e24e859d90cfbb3391473d7aa7904b9d93d15e640a3d4ee117

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