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

Uploaded CPython 3.13Windows x86-64

gl_observability_binary-0.1.5-cp313-cp313-manylinux_2_31_x86_64.whl (451.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.31+ x86-64

gl_observability_binary-0.1.5-cp313-cp313-macosx_13_0_arm64.whl (246.5 kB view details)

Uploaded CPython 3.13macOS 13.0+ ARM64

gl_observability_binary-0.1.5-cp312-cp312-win_amd64.whl (295.2 kB view details)

Uploaded CPython 3.12Windows x86-64

gl_observability_binary-0.1.5-cp312-cp312-manylinux_2_31_x86_64.whl (453.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.31+ x86-64

gl_observability_binary-0.1.5-cp312-cp312-macosx_13_0_arm64.whl (246.9 kB view details)

Uploaded CPython 3.12macOS 13.0+ ARM64

gl_observability_binary-0.1.5-cp311-cp311-win_amd64.whl (298.4 kB view details)

Uploaded CPython 3.11Windows x86-64

gl_observability_binary-0.1.5-cp311-cp311-manylinux_2_31_x86_64.whl (412.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

gl_observability_binary-0.1.5-cp311-cp311-macosx_13_0_arm64.whl (243.4 kB view details)

Uploaded CPython 3.11macOS 13.0+ ARM64

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 03f1344bf4bc767eb2d5b471b0864bb2a0670f55e411c1492ad10c8f32e81954
MD5 1f718cb29138680e074e181f771dd653
BLAKE2b-256 982570a617180fe0195d584ce67232023c0e1556cc7d9be2f69ab832333d2936

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.5-cp313-cp313-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 7a8df86d90fec352b092fc007bc135f4579294f499b9950bb6eac9183dc83868
MD5 1390311aefccb369d51e6d76cdc6d02b
BLAKE2b-256 29ff6cd1233d442f9f1ad03435e0a19f037bd2e7dd5620c0484528802752e7e7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.5-cp313-cp313-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 ef97494e120863f1ab3a1b85c7344f7158ddfa5acafc5aba560afd94276164f1
MD5 a8796c56034f99a3f2db0f6a47f1e99c
BLAKE2b-256 6fcea9045288a195fe8ed619dcc9ac840e5937d7f57b6539f9b3e84df02c6fae

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 10d5238c7a9fdd59805649289df7a032421f123e99fa28d5ff9911ac3a18750f
MD5 89f750c63bd37488e98118af23de6a5e
BLAKE2b-256 64f32dd3574d45bce7e18f031c5a54f4e6b0376f34eff1c75f09a2c2fb29cbf2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.5-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 3a0cd2a2b7d48284d39f92e5ab13d107f0ac8f13434e1e01eb70018075fae71d
MD5 287e2b34511f7b3f9dc5d11901c7731a
BLAKE2b-256 520a9a9b16ef87ae8ce7a5ede1e8b9c2b2a00cd0567ebefe69b307c2bbfd5b6a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.5-cp312-cp312-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 21073ade3471a744a952eeb3abe34d52b65a6a4c54be56126ebc3f4bb9593cb5
MD5 538e6ba7dd2bb5717f406a698ac85b9f
BLAKE2b-256 0e53b5898b782505829179c3130c0460ebe1312b4f9d46c21dd2feea681ce891

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 e07f22fc0f246d31c53c3ca9123f35c8df52ce1282974ea07f3275d2b9a127f5
MD5 4f9ca79d56255d9ffac88865151b943c
BLAKE2b-256 1597a1d4e5a5a4dc8cf141bf71b825dfe22510431f0928549fba46c5d88532d7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.5-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 0fbb57ea799c13b94c6227d6cf6dd610a6caaa8e41d57bd848b1c668e132ff98
MD5 688938d8cf9137ee42049005845382f6
BLAKE2b-256 251dc7eaab216f8d02732feb73ad2a66899f48a1d092a581f89c16a47dd2b950

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.5-cp311-cp311-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 9f8c293c7c5ce8c35173311d7be741f417a1e1fad09ce1a0c4757db837888840
MD5 d3b4dab5fccc4b3b34f068f2c256be12
BLAKE2b-256 1c35b671f963717b5e69bc42a98e194efda927e235100e5c9f5260b8da3854f4

See more details on using hashes here.

Provenance

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