Skip to main content

viktorbarzin-telemetry

The Python client for the viktorbarzin.me telemetry standard: Product events through Segment's segment-analytics-python to our Event pipeline, errors through sentry-sdk to GlitchTip, and logs as one OpenTelemetry-shaped JSON object per line on stdout.

pip install viktorbarzin-telemetry            # events and logs
pip install "viktorbarzin-telemetry[sentry]"  # plus Sentry
import logging
import viktorbarzin_telemetry as telemetry

telemetry.setup_logging(service_name="tv", service_version="1.4.0")
telemetry.configure(
    app="tv",
    write_key=settings.segment_write_key,
    release="1.4.0",
    environment="production",  # or set TELEMETRY_ENVIRONMENT=production
    host=settings.event_pipeline_url,  # or set TELEMETRY_HOST
    dsn=settings.sentry_dsn,  # https://<key>@tv.viktorbarzin.me/_t/x/<project id>
)

with telemetry.log_context(enduser_id=user.sub):
    logging.getLogger(__name__).info("recording started", extra={"channel_id": 4})
    telemetry.track("recording.started", {"channel_id": 4})

telemetry.flush()  # before exit
  • host is the Event pipeline's base URL, from the argument or TELEMETRY_HOST. Inside our cluster it is the event-pipeline Service's URL; elsewhere use telemetry.public_host("tv.viktorbarzin.me"). Production without a host raises ValueError.
  • Nothing is sent unless the environment is production. Invalid events are validated in every environment, dropped and logged as a warning.
  • RequestContextMiddleware(app, resolve_user=...) captures, per HTTP or WebSocket request, the X-Visitor-Id header (the browser's Rybbit visitor id), the client IP (X-Real-Ip, else the first X-Forwarded-For entry, else the peer) and the User-Agent. Events sent during the request use the visitor id as their default anonymousId and carry context.ip and context.userAgent. resolve_user is optional and works as in EnduserMiddleware. Outside ASGI, wrap the handler in with telemetry.request_context(request.headers, peer=remote_addr):.
  • track takes userId from log_context(enduser_id=...). anonymousId is the explicit argument, else log_context(anonymous_id=...), else the request's visitor id. Without any of those it is omitted when there is a userId, and otherwise server:<app>, or configure(..., default_anonymous_id=...). It is never a new random id per event.
  • EnduserMiddleware(app, resolve_user=...) sets enduser.id per request in any ASGI app. resolve_user gets the ASGI scope and returns the Person's Authentik sub or None, directly or as an awaitable.
  • trace_id and span_id come from the active OpenTelemetry span when opentelemetry-api is installed, else from log_context.
  • The JSON formatter masks the write key, values passed as secrets=, and bearer tokens, Basic credentials, JWTs and PEM blocks.
app.add_middleware(RequestContextMiddleware, resolve_user=person_from_scope)

Upgrading from 0.1.0: call sites keep working. A test double passed as client= must now accept anonymous_id: str | None, because an event with a Person and no visitor id sends none.

The standard itself is in the repository README.

Metadata

Release files for viktorbarzin-telemetry 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for viktorbarzin-telemetry 0.2.0
File Size Uploaded Provenance Actions
viktorbarzin_telemetry-0.2.0.tar.gz 20.0 kB With provenance Details for viktorbarzin_telemetry-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for viktorbarzin-telemetry 0.2.0
File Interpreter ABI Platform Actions
viktorbarzin_telemetry-0.2.0-py3-none-any.whl Python 3 none any Details for viktorbarzin_telemetry-0.2.0-py3-none-any.whl

Total release size: 36.8 kB

Release files / viktorbarzin_telemetry-0.2.0.tar.gz

Download URL viktorbarzin_telemetry-0.2.0.tar.gz
Size 20.0 kB
Tags Source
SHA-256 checksum
How to use checksums
728afc9036ff3532d7a6e314f25fb8f870fdc955aa2e1849aa19fe92b33bfa0d
BLAKE2b-256 checksum
How to use checksums
73ea1768861fdb88e428efce84a5d051cc4307207d2da4c6debd4deba2d9ae53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Release files / viktorbarzin_telemetry-0.2.0-py3-none-any.whl

Download URL viktorbarzin_telemetry-0.2.0-py3-none-any.whl
Size 16.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
50e2e74637f394c46034f20c4c57c04909bc718a91c2668dafba9ca0cf0aacad
BLAKE2b-256 checksum
How to use checksums
5b26dbe246d1dc3e9af9dc18213c5c859d902d38ad3cfedc2ccbc54f75808d1c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Security for viktorbarzin-telemetry 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for viktorbarzin_telemetry-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

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