Skip to main content

OpenTelemetry helpers for Vacasa Python services

Project description

@vacasa/open-telemetry-py

OpenTelemetry helpers for Vacasa Python services.

Installation

Using Poetry (Recommended)

poetry add vacasa-opentelemetry

Using pip

pip install vacasa-opentelemetry

Or add to your requirements.txt:

vacasa-opentelemetry>=1.0.0

Usage

Basic Initialization

from vacasa_opentelemetry import init_telemetry

# Initialize with defaults
init_telemetry()

Advanced Configuration

from vacasa_opentelemetry import init_telemetry, OtelInitOptions

# Initialize with custom options
init_telemetry(OtelInitOptions(
    service_name="my-python-service",
    debug=True,
    sampling_rate=0.5,
    tags={
        "environment": "production",
        "version": "1.0.0"
    },
    metric_export_interval_millis=10000,
    log_injection=True
))

Configuration

Environment Variables

Variable Description Required Default
OTEL_HOST_COLLECTOR OpenTelemetry collector endpoint Yes -
OTEL_SERVICE_NAME Service name for telemetry data No vacasa-python-service
OTEL_APM_ENABLED Enable full APM instrumentation No false

Options

  • service_name (str): Override the service name
  • metric_export_interval_millis (int): Metric export interval in milliseconds (default: 5000)
  • log_export_timeout_millis (int): Log export timeout in milliseconds (default: 3000)
  • tags (dict): Additional resource attributes/tags
  • debug (bool): Enable debug logging (default: False)
  • sampling_rate (float): Trace sampling rate 0.0-1.0 (default: 0.5 if APM enabled, else 0.0)
  • log_injection (bool): Enable log correlation with traces (default: True)

Example

import os
import logging
from vacasa_opentelemetry import init_telemetry, OtelInitOptions

# Set environment variable
os.environ["OTEL_HOST_COLLECTOR"] = "http://localhost:4318"
os.environ["OTEL_APM_ENABLED"] = "true"

# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

# Initialize OpenTelemetry
init_telemetry(OtelInitOptions(
    service_name="example-service",
    tags={"team": "platform"}
))

# Your application code
logger.info("Application started")

Features

  • Automatic Instrumentation: When OTEL_APM_ENABLED=true, automatically instruments common Python libraries
  • Log Injection: Correlates logs with traces automatically
  • Graceful Shutdown: Handles SIGTERM and SIGINT for proper telemetry flush
  • HTTP/OTLP Export: Uses OpenTelemetry Protocol over HTTP

Development

Setup with Poetry

# Install Poetry
curl -sSL https://install.python-poetry.org | python3 -

# Clone and navigate to the project
cd packages/open-telemetry-py

# Install dependencies
poetry install

# Activate virtual environment
poetry shell

Local Setup (Alternative)

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Install in development mode
pip install -e .

Testing

# With Poetry
poetry run pytest

# With coverage
poetry run pytest --cov=vacasa_opentelemetry

# Without Poetry
pytest

Code Quality

# Format code
poetry run black vacasa_opentelemetry/

# Sort imports
poetry run isort vacasa_opentelemetry/

# Lint
poetry run flake8 vacasa_opentelemetry/

# Type check
poetry run mypy vacasa_opentelemetry/

For more details on using Poetry, see POETRY.md.

License

MIT

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

vacasa_opentelemetry-1.0.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

vacasa_opentelemetry-1.0.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: vacasa_opentelemetry-1.0.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.10.14 Darwin/25.0.0

File hashes

Hashes for vacasa_opentelemetry-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0e3f8c9087e19b9fadd5dbe50f15b14d7131546c3b45456933eee38a762fa9a6
MD5 de3e5c21cf67e5d05315c1fbcb611737
BLAKE2b-256 85c9857ee8258c53edb27b9aba425d6bb0344866c3db9afa01239e48374fcd7e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for vacasa_opentelemetry-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5501d7c6180c34d9ad5d46433805a51d42cc730bfe024ed9240a9eb91adb52c5
MD5 4998517a1de7be94609c71c0bfa23f3a
BLAKE2b-256 b8995750bd63a6e1263e4a2a020519eddbc6ca298babd091e87aecf68e2d66e3

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