Skip to main content

OpenTelemetry configuration utilities for GCP Cloud Trace and Cloud Logging

Project description

CroudTech Python GCP OpenTelemetry

OpenTelemetry configuration utilities for GCP Cloud Trace and Cloud Logging integration.

Installation

# Install from GitHub with pip
pip install git+https://github.com/CroudTech/croudtech-python-gcp-otel.git

# Install a specific version
pip install git+https://github.com/CroudTech/croudtech-python-gcp-otel.git@v0.1.0

# Install with Poetry
poetry add git+https://github.com/CroudTech/croudtech-python-gcp-otel.git

# Install a specific version with Poetry
poetry add git+https://github.com/CroudTech/croudtech-python-gcp-otel.git#v0.1.0

Optional Dependencies

Install with extras for auto-instrumentation:

# With pip
pip install "croudtech-python-gcp-otel[all] @ git+https://github.com/CroudTech/croudtech-python-gcp-otel.git"

# Or specific instrumentations
pip install "croudtech-python-gcp-otel[django,requests] @ git+https://github.com/CroudTech/croudtech-python-gcp-otel.git"

Available extras: django, requests, psycopg2, logging, all

Usage

Basic Setup

from croudtech_gcp_otel import configure_telemetry

# Configure using environment variables
configure_telemetry()

Configuration via Environment Variables

  • GCP_PROJECT_ID or GOOGLE_CLOUD_PROJECT - GCP project ID for Cloud Trace
  • GCP_REGION - GCP region (default: europe-west2)
  • SERVICE_NAME - Service name for tracing
  • SERVICE_VERSION - Service version
  • K_SERVICE - Cloud Run service name (auto-detected)
  • K_REVISION - Cloud Run revision (auto-detected)

Explicit Configuration

from croudtech_gcp_otel import configure_telemetry, TelemetryConfig

config = TelemetryConfig(
    service_name="my-service",
    service_namespace="my-namespace",
    project_id="my-gcp-project",
    region="europe-west2",
    instrument_django=True,
    instrument_requests=True,
    instrument_psycopg2=True,
    instrument_logging=True,
)
configure_telemetry(config)

JSON Logging for GCP Cloud Logging

from croudtech_gcp_otel import configure_logging

# Configure root logger with JSON formatting
configure_logging()

Or use the formatter directly:

import logging
from croudtech_gcp_otel import JSONFormatter

handler = logging.StreamHandler()
handler.setFormatter(JSONFormatter())
logging.getLogger().addHandler(handler)

Manual Span Creation

from croudtech_gcp_otel import get_tracer, create_span_with_attributes

tracer = get_tracer(__name__)

with create_span_with_attributes(tracer, "my_operation", {"custom.attr": "value"}):
    # your code here
    pass

Features

  • GCP Cloud Trace Integration: Automatic export of traces to Cloud Trace
  • W3C Trace Context Propagation: Standard distributed tracing headers
  • GCP Cloud Trace Propagation: Native GCP trace header support
  • Auto-instrumentation: Django, requests, psycopg2, and logging
  • JSON Logging: GCP Cloud Logging compatible structured logs with trace correlation
  • App Hub Topology: Resource attributes for service topology visualization

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

croudtech_python_gcp_otel-0.3.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

croudtech_python_gcp_otel-0.3.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file croudtech_python_gcp_otel-0.3.0.tar.gz.

File metadata

  • Download URL: croudtech_python_gcp_otel-0.3.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.0 CPython/3.11.14 Linux/6.11.0-1018-azure

File hashes

Hashes for croudtech_python_gcp_otel-0.3.0.tar.gz
Algorithm Hash digest
SHA256 0aa62523af204c282ed32bbe357744d4be0a3a2f462a257def382dc46ee99bfd
MD5 8da2776519e43d9c5cd3ec7585912429
BLAKE2b-256 78379180eade97eed21ee9583451768c72bf67ec5c1f4d606f35c1d5d3e3ad7e

See more details on using hashes here.

File details

Details for the file croudtech_python_gcp_otel-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for croudtech_python_gcp_otel-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3d8ce69af364d2eefc35a74be1a68be2e1b0540018d9290b6f3e3fce3d236cfb
MD5 130d311d3b8e0f9f382b5b8e1cb0beca
BLAKE2b-256 55a50677169595a6d0f8230614c651aff10ead24f70702a0587c420c2e6402ee

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