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[all]

Using Poetry

poetry add gl-observability-binary[all]

Using uv

uv add gl-observability-binary[all]

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" --extras all

Optional Dependencies

The OTel instrumentor packages for FastAPI, Langchain, HTTPX, and Requests are bundled in core — no extra flags needed to enable tracing for them. However, each instrumentor must run against a compatible version of the library it traces. If you hit a DependencyConflictError at startup, it means your installed library version falls outside the range the bundled instrumentor supports.

The optional extras solve this by pulling in the instrumented library at a version that is known to be compatible with the bundled instrumentor. Use them as a version resolver, not as a feature flag.

Extra Installs
fastapi fastapi at a compatible version
langchain langchain at a compatible version
httpx httpx at a compatible version
requests requests at a compatible version
all All four libraries above

Install a specific extra via gl-observability-binary:

# pip
pip install "gl-observability-binary[langchain]"

# Poetry
poetry add "gl-observability-binary[langchain]"

# uv
uv add "gl-observability-binary[langchain]"

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

Uploaded CPython 3.13Windows x86-64

gl_observability_binary-0.2.0-cp313-cp313-manylinux_2_31_x86_64.whl (461.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.31+ x86-64

gl_observability_binary-0.2.0-cp313-cp313-macosx_13_0_arm64.whl (264.5 kB view details)

Uploaded CPython 3.13macOS 13.0+ ARM64

gl_observability_binary-0.2.0-cp312-cp312-win_amd64.whl (236.9 kB view details)

Uploaded CPython 3.12Windows x86-64

gl_observability_binary-0.2.0-cp312-cp312-manylinux_2_31_x86_64.whl (462.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.31+ x86-64

gl_observability_binary-0.2.0-cp312-cp312-macosx_13_0_arm64.whl (264.4 kB view details)

Uploaded CPython 3.12macOS 13.0+ ARM64

gl_observability_binary-0.2.0-cp311-cp311-win_amd64.whl (240.0 kB view details)

Uploaded CPython 3.11Windows x86-64

gl_observability_binary-0.2.0-cp311-cp311-manylinux_2_31_x86_64.whl (419.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

gl_observability_binary-0.2.0-cp311-cp311-macosx_13_0_arm64.whl (262.0 kB view details)

Uploaded CPython 3.11macOS 13.0+ ARM64

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.2.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 9a0f3cd5c383e09018502c1dbf8b6b7821a472811f4710283614faef1156a9e2
MD5 d7e57659e425fb51082d25f0ff009784
BLAKE2b-256 7ef822b08bc43e222f0cc7c53ad0719fa12e58e599aab681fb4d096f5aac57a0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.2.0-cp313-cp313-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 3838ee629bb052052fe5caf4035b652c4089ee889d050c57382c259758b0642e
MD5 f4d78a3bdedf46c18620276e3bd9daa5
BLAKE2b-256 2c569cbb6bcb902d85d09054cb3f988926fbce835f5d2cb2f65e7d7a177cfbb1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.2.0-cp313-cp313-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 c4de369870d70ddb59a94d81d3cc62e420c2a5660444ab340147a947d204b01a
MD5 a51f0f1044bb7ccab5ba811e456d49d4
BLAKE2b-256 5c5d689a4cdc1012c0a486dead89b2d9b8ad00fbeb9112816f62702ac88ec817

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ec0e2c1b93f7c8d17b19383ae084d60ef6f989e9136a7239ba25db90cfacbaba
MD5 802ae20bfdb242afdece6fa509dcd7f9
BLAKE2b-256 d80e1b4b89246c58a353090295b38cc6c9d133337176d26690e2f39f25fde6e6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.2.0-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 30a8bc274b4eac3df3f28a89f73c28e1aa472cd75b30a0d60d263b64bec6683d
MD5 0dd98b9e25b5ef97ca9e402fdff2f17b
BLAKE2b-256 a7c58b2033d59a734be066e8f7df088979eaad13a604e0027eaa34841dd89bf7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.2.0-cp312-cp312-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 ea56067c21366e69e76602700f51e0c1c2b8c6eaed418d566284bab7718e91b4
MD5 f2de2aac5b4a5d792e79e9655e124b9b
BLAKE2b-256 27cc33e5f4c0a58bd5b37e9858af82be1517172f75f3cb331b0b7a8464b731d3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3ac3c0f76d80f6d28f41c3bc5afff9254b9db2417a07661620387b3b3031578b
MD5 1192b2818807b7422862388bdca6aef9
BLAKE2b-256 fbfb0c6122538ab4e966ca67e443c51bef13c7b9aa60ad6438e50a7daac68209

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.2.0-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 8b34ccddd756981835cb7c09e5d8a856f29f2ce72916ac4cdbb00eca7cf7b55e
MD5 58f4df6481341f82e72d3d531d6b50b6
BLAKE2b-256 6a98efc4532d757d529bcf5d215d210122d9439254f4e45cc268595716b654f4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.2.0-cp311-cp311-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 bb35dff8379fcc8b56eecc1f83817077bade0df7ea5bcc9f3291f6136e5e247d
MD5 6a914b5f8dd3afe2c925b14a4bd89fe4
BLAKE2b-256 900c599e85c72e4f2e4e792ada224ea0b5c9a5261b396218c76c18135b137d47

See more details on using hashes here.

Provenance

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