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.1-cp313-cp313-win_amd64.whl (290.7 kB view details)

Uploaded CPython 3.13Windows x86-64

gl_observability_binary-0.1.1-cp313-cp313-manylinux_2_31_x86_64.whl (447.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.31+ x86-64

gl_observability_binary-0.1.1-cp313-cp313-macosx_13_0_arm64.whl (242.8 kB view details)

Uploaded CPython 3.13macOS 13.0+ ARM64

gl_observability_binary-0.1.1-cp312-cp312-win_amd64.whl (293.3 kB view details)

Uploaded CPython 3.12Windows x86-64

gl_observability_binary-0.1.1-cp312-cp312-manylinux_2_31_x86_64.whl (449.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.31+ x86-64

gl_observability_binary-0.1.1-cp312-cp312-macosx_13_0_arm64.whl (243.6 kB view details)

Uploaded CPython 3.12macOS 13.0+ ARM64

gl_observability_binary-0.1.1-cp311-cp311-win_amd64.whl (296.0 kB view details)

Uploaded CPython 3.11Windows x86-64

gl_observability_binary-0.1.1-cp311-cp311-manylinux_2_31_x86_64.whl (409.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

gl_observability_binary-0.1.1-cp311-cp311-macosx_13_0_arm64.whl (241.0 kB view details)

Uploaded CPython 3.11macOS 13.0+ ARM64

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 183c47774c1567dcf9743e6205c4406feb63bbbd0bb455f7b53970fd02b981f1
MD5 09e718c222b518e6c4c173b679577b99
BLAKE2b-256 2f7e75daf21ec50f8fbf2dd8a2efcea6a2dcb1829d8a9addac3eb164db741505

See more details on using hashes here.

Provenance

The following attestation bundles were made for gl_observability_binary-0.1.1-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.1-cp313-cp313-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for gl_observability_binary-0.1.1-cp313-cp313-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 5bbbec38ca8b9ecdc3f01d38c9f0a1389fe9cd1819e4a47f9f771d016786c2d4
MD5 2f6a5ef746d9b07dde7cd445f8d18488
BLAKE2b-256 0d128d972a97442c99ef2c6909bcf1a3ea414a210721feec692e515e44229146

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.1-cp313-cp313-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 d91ba23f19894c21632722e0779b496d6394d7b84218ce094b7fbf206f67148d
MD5 b3ad4bdae18422833c9d4bddfec5fdb2
BLAKE2b-256 f352615752d404f7c366f2871891626a81cca67a9f8839a2cbe884c367e69fa7

See more details on using hashes here.

Provenance

The following attestation bundles were made for gl_observability_binary-0.1.1-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.1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for gl_observability_binary-0.1.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 91f3bf26eccce24ebfd3635704464c00fe42333b9684b71999c142b201ee62e1
MD5 9a0f2a3a1c7e440937082549ec6808d2
BLAKE2b-256 11a3fee86d4d1f1fdeb3dd2c6989a8677d31a8a32cdb65495d762ad65f7fdc24

See more details on using hashes here.

Provenance

The following attestation bundles were made for gl_observability_binary-0.1.1-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.1-cp312-cp312-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for gl_observability_binary-0.1.1-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 7f7b63a468fd2d14413618ae32fccd13c9fe65b4e443da90e31c955cab598c56
MD5 65b25eac1580455ba8f0b25b72906565
BLAKE2b-256 9bacec5670e0038d17b3335097bb05bcda240e4e530c46f227fbf1a5e62ab0ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.1-cp312-cp312-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 2b8ef9d0c8c7a62b8b392381eeebd5d3fcd2043b5e3b16de9bf285c660400e91
MD5 942ba6f273529c5e94f5c061501799ae
BLAKE2b-256 97d0f9ffcc61331e353c8ee03a94d07c3612d7441e70d315a8463361959d202d

See more details on using hashes here.

Provenance

The following attestation bundles were made for gl_observability_binary-0.1.1-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.1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for gl_observability_binary-0.1.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 346017ebd56056780ca6c322fabb0339f400f9641c4b14a42b09ecefebd5a0b4
MD5 c45c14233b79293dd3eb93391ca5c9f0
BLAKE2b-256 d251a79e2a95afbf496c61f2c6a8587ff3585c23614a3e965313184f6d2ecc61

See more details on using hashes here.

Provenance

The following attestation bundles were made for gl_observability_binary-0.1.1-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.1-cp311-cp311-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for gl_observability_binary-0.1.1-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 486fa5fb85e19bf5828b25a566cfe05b0fdd057a4642e352888df9c38f921468
MD5 ad06b961f0af7ecc40a4a2c5da02ec05
BLAKE2b-256 650cac4d27c5bfe400b15bd149dc3e42dcf009545f503cb1cdd6cd6442cffd38

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.1-cp311-cp311-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 3f3a5566560a2263356a8dd443326cd4ff27c4af0a5e5460080aa1f08b049752
MD5 a0c49bb6252d7767cc35d5e0e586d08c
BLAKE2b-256 99d53498d7e96da560de6b09efc4c85e48c832ed11421c7c356c68fc9895e068

See more details on using hashes here.

Provenance

The following attestation bundles were made for gl_observability_binary-0.1.1-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