Skip to main content

SDK for Observability tools

Project description

GL Observability

gl-observability is a comprehensive SDK for implementing observability in Python applications. It provides easy-to-use wrappers for OpenTelemetry, Sentry, and custom logging handlers with PII redaction capabilities.

Key Features

  • 📊 OpenTelemetry Integration: simplified initialization for tracing.
  • 🛡️ Sentry Support: easy setup for error tracking and performance monitoring.
  • 🕵️ PII Redaction: custom logging handlers to redact PII using Regex or NER (Named Entity Recognition).
  • 🔌 Framework Support: built-in support for FastAPI, Langchain, HTTPX, and Requests instrumentation.

Installation

Prerequisites

1. Installation from Pypi

Choose one of the following methods to install the package:

Using pip

pip install gl-observability-binary

Using Poetry

poetry add gl-observability-binary

Using uv

uv add gl-observability-binary

2. Development Installation (Git)

For development purposes, you can install directly from the Git repository:

poetry add "git+ssh://git@github.com/GDP-ADMIN/gl-sdk.git#subdirectory=libs/gl-observability"

Usage

1. Telemetry Initialization

The library uses a unified init_telemetry function that takes a TelemetryConfig object. You can configure it to send traces to OpenTelemetry (OTLP) or Sentry backend. Multiple backend configuration is supported.

OpenTelemetry Configuration

This setup sends traces to an external OTLP collector (e.g., Jaeger, Tempo).

from fastapi import FastAPI
from gl_observability import init_telemetry, TelemetryConfig, OpenTelemetryBackendConfig, FastAPIConfig

# 1. Setup FastAPI Config (optional, if using FastAPI)
app = FastAPI()
fastapi_config = FastAPIConfig(app=app)

# 2. Configure OpenTelemetryBackendConfig
otel_backend_config = OpenTelemetryBackendConfig(
    endpoint="localhost:4318",                  # OTLP endpoint
    use_grpc=False,                             # Use gRPC or HTTP
    headers={"Authorization": "Bearer ..."},    # Optional headers
)

# 3. Configure TelemetryConfig
otel_config = TelemetryConfig(
    attributes={"service.name": "..."},         # Resource attributes
    backend_config=otel_backend_config,         # Backend configuration
    fastapi_config=fastapi_config,              # FastAPI Instrumentation
    use_langchain=True,                         # Enable Langchain instrumentation
    use_httpx=True,                             # Enable HTTPX instrumentation
    use_requests=True,                          # Enable Requests instrumentation
)

# 4. Initialize Telemetry
init_telemetry(otel_config)

Sentry Configuration

This setup sends errors and traces to Sentry.

from fastapi import FastAPI
from gl_observability import init_telemetry, TelemetryConfig, SentryBackendConfig, FastAPIConfig

# 1. Setup FastAPI Config (optional, if using FastAPI)
app = FastAPI()
fastapi_config = FastAPIConfig(app=app)

# 2. Configure SentryBackendConfig
sentry_backend_config = SentryBackendConfig(
    dsn="https://...",
    environment="...",
    release="...",
    send_default_pii=True,
    disable_sentry_distributed_tracing=False
)

# 3. Configure TelemetryConfig
otel_config = TelemetryConfig(
    attributes={"service.name": "..."},         # Resource attributes
    backend_config=sentry_backend_config,       # Backend configuration
    fastapi_config=fastapi_config,              # FastAPI Instrumentation
    use_langchain=True,                         # Enable Langchain instrumentation
    use_httpx=True,                             # Enable HTTPX instrumentation
    use_requests=True,                          # Enable Requests instrumentation
)

# 4. Initialize Telemetry
init_telemetry(otel_config)

Multiple Backend Configuration

This setup the OpenTelemetry SDK used for tracing.

from fastapi import FastAPI
from gl_observability import init_telemetry, TelemetryConfig, OpenTelemetryBackendConfig, SentryBackendConfig

jaeger_backend = OpenTelemetryBackendConfig(endpoint="jager...", ...)
init_telemetry(
    TelemetryConfig(
        attributes={"service.name": "..."},
        backend_config=jaeger_backend,
        fastapi_config=fastapi_config,
        use_langchain=True,
        use_httpx=True,
        use_requests=True,
    )
)

langfuse_backend = OpenTelemetryBackendConfig(endpoint="langfuse...", ...)
init_telemetry(
    TelemetryConfig(
        backend_config=langfuse_backend
    )
)

sentry_backend = SentryBackendConfig(dsn="https://...", ...)
init_telemetry(
    TelemetryConfig(
        backend_config=sentry_backend
    )
)

2. Logging Handlers

The library provides logging handlers to automatically redact Personally Identifiable Information (PII) from logs.

Regex-based PII Redaction

Uses regular expressions to mask common PII patterns like KTP, NPWP, Phone Numbers, and Email.

import logging
from gl_observability.logs.regex_pii_logger_handler import init_regex_pii_logging_handler

# Initialize the handler for a specific logger
init_regex_pii_logging_handler(
    logger_name="my_application_logger",
    pii_regex_process_enabled=True
)

logger = logging.getLogger("my_application_logger")
logger.info("User email is john.doe@example.com and phone is 08123456789")
# Output: User email is jo******om and phone is 0812******6789

NER-based PII Redaction (Named Entity Recognition)

Uses an external API to perform Named Entity Recognition for more advanced PII detection and redaction.

[!WARNING] The NER logging handler makes synchronous API calls for each log record, which may impact performance.

import logging
from gl_observability.logs.ner_pii_logger_handler import init_ner_pii_logging_handler

# Initialize the handler
init_ner_pii_logging_handler(
    logger_name="my_application_logger",
    api_url="https://your-ner-api.com/anonymize",
    api_field="text",  # The field name in API response containing the redacted text
    pii_ner_process_enabled=True
)

logger = logging.getLogger("my_application_logger")
logger.info("My KTP is 3525011212941001")
# Output will be redacted based on API response

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

gl_observability_binary-0.1.2-cp313-cp313-win_amd64.whl (291.5 kB view details)

Uploaded CPython 3.13Windows x86-64

gl_observability_binary-0.1.2-cp313-cp313-manylinux_2_31_x86_64.whl (448.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.31+ x86-64

gl_observability_binary-0.1.2-cp313-cp313-macosx_13_0_arm64.whl (244.0 kB view details)

Uploaded CPython 3.13macOS 13.0+ ARM64

gl_observability_binary-0.1.2-cp312-cp312-win_amd64.whl (294.0 kB view details)

Uploaded CPython 3.12Windows x86-64

gl_observability_binary-0.1.2-cp312-cp312-manylinux_2_31_x86_64.whl (450.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.31+ x86-64

gl_observability_binary-0.1.2-cp312-cp312-macosx_13_0_arm64.whl (244.7 kB view details)

Uploaded CPython 3.12macOS 13.0+ ARM64

gl_observability_binary-0.1.2-cp311-cp311-win_amd64.whl (296.8 kB view details)

Uploaded CPython 3.11Windows x86-64

gl_observability_binary-0.1.2-cp311-cp311-manylinux_2_31_x86_64.whl (410.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

gl_observability_binary-0.1.2-cp311-cp311-macosx_13_0_arm64.whl (241.9 kB view details)

Uploaded CPython 3.11macOS 13.0+ ARM64

File details

Details for the file gl_observability_binary-0.1.2-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for gl_observability_binary-0.1.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 82f372ff5146589e0d868d2572eb000a6b6f8fa6f842565b4eed90ecf6d5884c
MD5 fe3bca80e71ee4a081098bafdcd48560
BLAKE2b-256 e409cd920610b87a72b7b648ae576fc8de003140e70e9eae84bb11e1940bb2a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for gl_observability_binary-0.1.2-cp313-cp313-win_amd64.whl:

Publisher: build-binary.yml on GDP-ADMIN/gl-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gl_observability_binary-0.1.2-cp313-cp313-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for gl_observability_binary-0.1.2-cp313-cp313-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 fcd82b0566764b36eaeeb50255a815e73b81320cc941aa6712827ff060b97a13
MD5 f7bc0dd7930b1f9536866edb89fdecd0
BLAKE2b-256 014d9ba0534c992af334a33aa55e1c96b57f5cd0a593e15604962e7b45914d9f

See more details on using hashes here.

File details

Details for the file gl_observability_binary-0.1.2-cp313-cp313-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for gl_observability_binary-0.1.2-cp313-cp313-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 4c1471e3af8e6e109c886443e73cd42c7cd002aff1d086d8cd03f4709427c8d7
MD5 b2e216533c5ad5d9d58d884192f92d98
BLAKE2b-256 8aff978f7ed79a87b4852b735ee71193a4a3fd2ff2536b9e38c1912d18db5b3a

See more details on using hashes here.

Provenance

The following attestation bundles were made for gl_observability_binary-0.1.2-cp313-cp313-macosx_13_0_arm64.whl:

Publisher: build-binary.yml on GDP-ADMIN/gl-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gl_observability_binary-0.1.2-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for gl_observability_binary-0.1.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 bd1bd5623b735c0b1123b9374489d629329f95b0c2d4d390ddea11bd3d014f04
MD5 08f0883089e3329064794a820c0d48a0
BLAKE2b-256 24639463435c10f4c459c27466d90c50d875257532d05b4e472ea06ab703fe0f

See more details on using hashes here.

Provenance

The following attestation bundles were made for gl_observability_binary-0.1.2-cp312-cp312-win_amd64.whl:

Publisher: build-binary.yml on GDP-ADMIN/gl-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gl_observability_binary-0.1.2-cp312-cp312-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for gl_observability_binary-0.1.2-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 307923969c94f47a5649e6d4f85fce65be3b295bdcdf4973ea620c3f2451d1be
MD5 6f461c8a866ba26a5c0bba8d8691f47c
BLAKE2b-256 bcca886e02ee37a46f2001212b7996d726e442a828a348e96b04b8498166fe03

See more details on using hashes here.

File details

Details for the file gl_observability_binary-0.1.2-cp312-cp312-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for gl_observability_binary-0.1.2-cp312-cp312-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 d70b644c996d34ab9429f32b7fc1214a7be840609644e8efb31eb63347a1d8eb
MD5 907c014f607f6e9637bdb0e990050edd
BLAKE2b-256 5ed3dccac402bbcade52bd6cc93bce1e2db3a5256a7381599242643a8a5ec4c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for gl_observability_binary-0.1.2-cp312-cp312-macosx_13_0_arm64.whl:

Publisher: build-binary.yml on GDP-ADMIN/gl-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gl_observability_binary-0.1.2-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for gl_observability_binary-0.1.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 54f553a622de6f9f60f063e47732ee166ce5b650733e52cb0edddbc8c20e4042
MD5 54610a31742f04f8b194c102c050a7a0
BLAKE2b-256 b69bff28aef77c7055c47a1e319cfe718357a71b1a82898f53911b01e03fbf0f

See more details on using hashes here.

Provenance

The following attestation bundles were made for gl_observability_binary-0.1.2-cp311-cp311-win_amd64.whl:

Publisher: build-binary.yml on GDP-ADMIN/gl-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gl_observability_binary-0.1.2-cp311-cp311-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for gl_observability_binary-0.1.2-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 41802bad65eda06d6add54cb310584459bf0323b1ed3e059f99cbb0b5fde2e78
MD5 804a2e9389f6b3be8361de42a81315ce
BLAKE2b-256 416359bd8f660c377294872ceae19e0015eea9d9d67013e9a6692f70a5923da4

See more details on using hashes here.

File details

Details for the file gl_observability_binary-0.1.2-cp311-cp311-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for gl_observability_binary-0.1.2-cp311-cp311-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 f8c6560f688bd4e0a39d27b95289dee3d27c76feb363804a34c53d83662a251f
MD5 643b45ab5a445a72ceafe853e2d60d6c
BLAKE2b-256 35ae0c733f3befc3a15957fb0aa593d1ed4fbf453eccdd0c280b46fbf7f11bb6

See more details on using hashes here.

Provenance

The following attestation bundles were made for gl_observability_binary-0.1.2-cp311-cp311-macosx_13_0_arm64.whl:

Publisher: build-binary.yml on GDP-ADMIN/gl-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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