Skip to main content

Export OpenTelemetry-compatible events to PostHog.

Project description

posthog-otel-exporter

Overview

posthog-otel-exporter is an OpenTelemetry SpanExporter for Python that sends trace events to PostHog. This allows you to analyze and visualize your application's traces and events in PostHog.

Installation

pip install posthog-otel-exporter

Configuration

You need a PostHog project API key and endpoint. These can be provided as arguments or via environment variables:

  • POSTHOG_API_KEY: Your PostHog project API key
  • POSTHOG_ENDPOINT: Your PostHog instance endpoint (e.g., https://app.posthog.com)

Usage with OpenTelemetry

Below is an example of how to use PosthogSpanExporter with OpenTelemetry's tracing SDK:

from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from posthog_otel_exporter.exporter import PosthogSpanExporter

# Set up the tracer provider
trace.set_tracer_provider(TracerProvider())
tracer = trace.get_tracer(__name__)

# Configure the Posthog exporter (API key and endpoint can also be set via env vars)
exporter = PosthogSpanExporter(
    posthog_api_key="<your-posthog-api-key>",
    posthog_endpoint="<your-posthog-endpoint>"
)

# Add the exporter to the span processor
span_processor = BatchSpanProcessor(exporter)
trace.get_tracer_provider().add_span_processor(span_processor)

# Example span
with tracer.start_as_current_span("example-span") as span:
    span.add_event("event-name", {"key": "value"})

Environment Variables

Alternatively, set the following environment variables:

export POSTHOG_API_KEY="<your-posthog-api-key>"
export POSTHOG_ENDPOINT="<your-posthog-endpoint>"

Then initialize the exporter without arguments:

exporter = PosthogSpanExporter()

License and Contributions

This project is distributed under the MIT License.

Contributions are welcome and encouraged, and should follow the guidelines in CONTRIBUTING.md.

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

posthog_otel_exporter-0.1.0.tar.gz (38.1 kB view details)

Uploaded Source

Built Distribution

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

posthog_otel_exporter-0.1.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: posthog_otel_exporter-0.1.0.tar.gz
  • Upload date:
  • Size: 38.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for posthog_otel_exporter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 381d20925879cbc181ba113eab8a205e601383c2e9fc5189c8dbf6d914320992
MD5 4e17aff78a69382852d2da9d2a6bea86
BLAKE2b-256 06567e6531921d101f2bc07d34feec0cc75492595a949f887a807ab3a19088df

See more details on using hashes here.

File details

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

File metadata

  • Download URL: posthog_otel_exporter-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for posthog_otel_exporter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 82488426b013e5588ede908093bcbe7b2a862bdf5f7c9cc406e49c6584fc5f1e
MD5 b665755a89addabcb9b35523f3c71670
BLAKE2b-256 d7d049cad5a49e060d9c53e43450ce0f3de8be76652cfd5368d7540146fe22f5

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