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 keyPOSTHOG_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
381d20925879cbc181ba113eab8a205e601383c2e9fc5189c8dbf6d914320992
|
|
| MD5 |
4e17aff78a69382852d2da9d2a6bea86
|
|
| BLAKE2b-256 |
06567e6531921d101f2bc07d34feec0cc75492595a949f887a807ab3a19088df
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82488426b013e5588ede908093bcbe7b2a862bdf5f7c9cc406e49c6584fc5f1e
|
|
| MD5 |
b665755a89addabcb9b35523f3c71670
|
|
| BLAKE2b-256 |
d7d049cad5a49e060d9c53e43450ce0f3de8be76652cfd5368d7540146fe22f5
|