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

Uploaded CPython 3.13Windows x86-64

gl_observability_binary-0.1.3-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.3-cp313-cp313-macosx_13_0_arm64.whl (244.0 kB view details)

Uploaded CPython 3.13macOS 13.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

gl_observability_binary-0.1.3-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.3-cp312-cp312-macosx_13_0_arm64.whl (244.7 kB view details)

Uploaded CPython 3.12macOS 13.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

gl_observability_binary-0.1.3-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.3-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.3-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for gl_observability_binary-0.1.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 ae48357517eb801c35be984a8ff184605b49417feb28148c7fae652bc767995a
MD5 d814551e1065ff4fd853b2b87106bfc6
BLAKE2b-256 30b690a29a3517a44f8d5450bafd993eb9aaa6d6a2ec26553e21aa8657104e2a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.3-cp313-cp313-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 ac62d307717fa76231a5a2ebb161e6e233086364b71452cc09355d59588758e8
MD5 581dee0e5e5f3dc77b4f33bb18606232
BLAKE2b-256 b75ad7e622f6b27deba7e3236e11666560cab37878c795aa07918e25215b2e19

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.3-cp313-cp313-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 8fb4557500ad85e6de6a9b6eb1989c3c78e051d29e8b82151d9135f89ea095e0
MD5 23bf0775a22098880a7b16c779ab5b8e
BLAKE2b-256 9a005e806986b8054aa2807a5f0b3e852c9d6150228d1dd8324e692195fb041e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 8a4df3d1bca93201b4d4c208dd076bb4d9bcd4b6bd8414806003ca7a651d9092
MD5 b7314d05fbf4ac2b0578fb919bce3e08
BLAKE2b-256 ca638655ef16a017d5fb1f145342b591c6a36238a6889e45ec089867ab50d064

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.3-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 654423ce5fc1c61c4d6b9203c0a36c9682a60ecb413cec0a56cbd5e96d4898a5
MD5 80c191ca5998dfcd269732084d996d1d
BLAKE2b-256 cbe506db08c55cbc7898081813d4e22cf1839cb258a5404807a970be221af552

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.3-cp312-cp312-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 a85b57f4bb7f7b03965d25a42f3f8fa3821aeb63ad8fa0faf35f83c060d9a88f
MD5 b16223425751b13a7ef17071caccb9ea
BLAKE2b-256 13485fb972ffcce29a879ed081cb0d88a0b0561f04358dda45d24670cbb191a3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 6a98dcc2235209515e7ab59e7e59cfa70a8a6f3820d4c988b87937af13dd2600
MD5 7712e504727f723fa30f8aa30d1957b1
BLAKE2b-256 5654d508931b24dbd9335565e3f5d4f7680d3480ee57e55aca2a29d0a759d454

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.3-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 09ad98d33817f9dd2c12d38a38a442a25eec1a060ced72316600f39f39322696
MD5 3c0fb82e5e6a011aa69794d96eb3ccc8
BLAKE2b-256 64075734620f38e0470f412db1367c6c7e870ce8fa53d5cb7a544727d0ced27a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.3-cp311-cp311-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 c37a5388e8eedf2e46a788817dbc1b646b3520fc08e9edd14bc80e6f275090f1
MD5 1c2a9e696ca15a49c80ce7e14c469227
BLAKE2b-256 38048024bd599677c0864cffc8a2bebb4f26ca273df1e5e5583b45a4b1630ac0

See more details on using hashes here.

Provenance

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