Skip to main content

Juntai Usage

juntai-usage is the only producer library for canonical Juntai usage events. It creates validated juntai.usage/v1 records, derives retry-stable identifiers, and emits dedicated OpenTelemetry log events through the application's configured local SDK and Collector sidecar.

The package contains no database driver, service runtime, ingestion endpoint, ledger, query, pricing, calculation, domain, or deployment code. Durable acceptance remains the responsibility of JuntaiUsageCostService; a successful local report means only that the configured OpenTelemetry SDK accepted the log record.

Producer example

from datetime import UTC, datetime
from decimal import Decimal

from juntai.usage import (
    UsageContext,
    UsageEvent,
    UsageReporter,
    stable_usage_event_id,
)

source_id = "axiom-execution:exec-42:attempt-1:completed"
event = UsageEvent(
    event_id=stable_usage_event_id(
        producer_id="axiom.driver",
        source_id=source_id,
        meter="axiom.execution.cpu_time",
        part="total",
    ),
    context=UsageContext(
        tenant_id="tenant-7",
        service_namespace="juntai.axiom",
        service_name="driver",
        application_id="app-9",
        workflow_id="workflow-3",
        execution_id="exec-42",
    ),
    meter="axiom.execution.cpu_time",
    quantity=Decimal("18.250"),
    unit="s",
    occurred_at=datetime.now(UTC),
    source_id=source_id,
)

result = UsageReporter.from_otel().report(event)
if not result.enqueued:
    service_health.record_usage_reporting_failure(result.error_code)

Configure the process OpenTelemetry LoggerProvider with matching service.namespace and service.name resource attributes and export OTLP over HTTP/protobuf only to the local Collector sidecar. Re-reporting the same event is safe because its identifier and encoded payload remain stable. Do not use a timestamp or random value as source_id.

Validation and meter definitions

UsageEvent accepts only Decimal quantities and normalizes them to a finite, non-negative canonical string without exponent notation. Timestamps are timezone-aware and normalized to UTC. UsageMeter can validate a locally known published definition's accepted units and required application, workflow, or execution attribution before emission. The service meter catalog remains the authority.

The canonical JSON contract is contracts/usage-event.v1.schema.json. Deterministic valid and invalid fixtures are under fixtures. Migration from the legacy Observability metric-window convention is documented in docs/migration-from-observability.md.

Local gates

uv sync --dev
uv run ruff format --check .
uv run ruff check .
uv run pytest
uv run python -m build

The integration suite uses the real OpenTelemetry SDK and in-memory exporter to verify emitted log records and resource attribution. It deliberately does not claim central Collector or ledger durability.

Download files

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

Source Distribution

juntai_usage-1.0.0.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

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

juntai_usage-1.0.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: juntai_usage-1.0.0.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for juntai_usage-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fb0bd52d46816853ef32e2aa28a93a326381bf3b41eb8338bba9aa290994e32f
MD5 5102083f9a736a93336b106b8464c9a3
BLAKE2b-256 86b22416d4d2903335cb48f7f393d693163d041b674a004f39af833ec648e065

See more details on using hashes here.

Provenance

The following attestation bundles were made for juntai_usage-1.0.0.tar.gz:

Publisher: publish-python.yml on zephytiju/JuntaiUsage

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: juntai_usage-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for juntai_usage-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0fd30957ab3a524a5bbf879f8c2a2e49753f8573d07d16e982861adc86df9f6
MD5 6d487020e0e84f7fe74ec169f15f8670
BLAKE2b-256 ec39cbc9c8ac7f193829681aab01fab69ab9beebeff1e21c4ca0edce25134794

See more details on using hashes here.

Provenance

The following attestation bundles were made for juntai_usage-1.0.0-py3-none-any.whl:

Publisher: publish-python.yml on zephytiju/JuntaiUsage

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page