Skip to main content

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, Requests, OpenAI, Anthropic, Bedrock, and Google Generative AI 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, Requests, OpenAI, Anthropic, Bedrock, and Google Generative AI are bundled in core. HTTPX, Requests, and all LLM providers (OpenAI, Anthropic, Bedrock, Google Generative AI) are enabled by default — use_httpx and use_requests default to True, and use_llm (which covers all four LLM providers together) defaults to True. Set any flag to False to disable that integration. Langchain and FastAPI follow the same use_* pattern (use_langchain defaults to False; FastAPI runs when fastapi_config is set).

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
llm openai, anthropic, boto3, google-generativeai at compatible versions
all All 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 (default: False)
    # use_httpx, use_requests, and use_llm default to True; set to False to disable.
)

# 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 (default: False)
    # use_httpx, use_requests, and use_llm default to True; set to False to disable.
)

# 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,
        use_llm=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

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

Uploaded CPython 3.13Windows x86-64

gl_observability_binary-0.2.3-cp313-cp313-manylinux_2_31_x86_64.whl (492.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.31+ x86-64

gl_observability_binary-0.2.3-cp313-cp313-macosx_13_0_arm64.whl (289.9 kB view details)

Uploaded CPython 3.13macOS 13.0+ ARM64

gl_observability_binary-0.2.3-cp312-cp312-win_amd64.whl (262.1 kB view details)

Uploaded CPython 3.12Windows x86-64

gl_observability_binary-0.2.3-cp312-cp312-manylinux_2_31_x86_64.whl (493.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.31+ x86-64

gl_observability_binary-0.2.3-cp312-cp312-macosx_13_0_arm64.whl (289.4 kB view details)

Uploaded CPython 3.12macOS 13.0+ ARM64

gl_observability_binary-0.2.3-cp311-cp311-win_amd64.whl (268.7 kB view details)

Uploaded CPython 3.11Windows x86-64

gl_observability_binary-0.2.3-cp311-cp311-manylinux_2_31_x86_64.whl (448.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

gl_observability_binary-0.2.3-cp311-cp311-macosx_13_0_arm64.whl (285.4 kB view details)

Uploaded CPython 3.11macOS 13.0+ ARM64

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.2.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 f172a2300fc649aadc0dd93d69326bc9fa2ee8a32c1fbf5a87eb00c4f8705c40
MD5 7bd155cd7054c815c8574ee255afd509
BLAKE2b-256 ca5d8b9cf5bd98d3dff7d92269f60f47d0aff3cfd3f3d1887668d9cf5d8e1d0c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.2.3-cp313-cp313-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 827c835c2a5617fdd092966830a171a09be02c5f02613baec5f073ba0ced87eb
MD5 439735e5eef09b4fe405cba5b5c22d52
BLAKE2b-256 02f268ec954f1d29261d2646ebb00a6161e1c07cc7474a1a74ca4ed813a45f39

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.2.3-cp313-cp313-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 acf60be20711cce05182448ad829ae134d06ac148577d9b4a07d1a4048015da8
MD5 8dbdcad64694450e113863985dac6ec1
BLAKE2b-256 5442b1779c762be36d088846d087ac720253d0d34fc59bc531a6282db37f652b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.2.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c13520a0a12e69d4ccc8aa8a52681a4ed9bb55a8f1b2c94b9beaa0c71f89a008
MD5 d1dc6db5b9032ca5db2e0501af19845f
BLAKE2b-256 e618dba22239ee41ed868b58d1d5691924bf1c22205f165bc608870efe882887

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.2.3-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 7b8b1842d027682d88abcd574e679cfe2fdff2dd3a68f95a95e3f98cad653280
MD5 7fa89d4dd2820a16be96b2c3ee50f025
BLAKE2b-256 988385f2b9064c8a1514652d84527c5963cc6434951cddefb7a2cbfc35ac89ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.2.3-cp312-cp312-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 d9af1487d0a5e7a597bec98e74b7c1006a7c9d6d7d6e20e21b5ad33410c78e77
MD5 ea5135a10165e9e11026dcc4a7cf2d9c
BLAKE2b-256 ee3a366a2b1323013e77833da3b508bc32c7e6fe01c0e9e089ea3cf0135c957a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.2.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 e139c45fa6c1439f7ec12fa6dfd7c8bcbe7447c6242ceaec65de6a9f5f8813ba
MD5 c36e566f3f83d1011733ab4f0ff1d809
BLAKE2b-256 b21de9f19432c98e4ec2ca80c93b3061bef570f0a8692ade9f3a771338f3f4ba

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.2.3-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 1cde60469e6c0deeee66b2ca30f5a2a19ba37e85b5b9719402105da870d2fe1f
MD5 360c43096a35ebbdb0ca7e40f5d26352
BLAKE2b-256 6c33b80d80f7a562996bf50a705391aa85c7a45fe06f9af85d91f79f1d417a93

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.2.3-cp311-cp311-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 de5b9b15137215a7cf2cb747ef0e012468ad1e563bb77c6c99efaa4262c5d3b6
MD5 dbc384f3320ec64c64c89336bca54b2e
BLAKE2b-256 2ac60d0ebeaafc6a2e182df9754c0d0ca5198d20d13bf5e3078538e227aec5f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for gl_observability_binary-0.2.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 Sentry Error logging StatusPage Status page