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

Uploaded CPython 3.13Windows x86-64

gl_observability_binary-0.1.4-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.4-cp313-cp313-macosx_13_0_arm64.whl (246.5 kB view details)

Uploaded CPython 3.13macOS 13.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

gl_observability_binary-0.1.4-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.4-cp312-cp312-macosx_13_0_arm64.whl (247.0 kB view details)

Uploaded CPython 3.12macOS 13.0+ ARM64

gl_observability_binary-0.1.4-cp311-cp311-win_amd64.whl (298.1 kB view details)

Uploaded CPython 3.11Windows x86-64

gl_observability_binary-0.1.4-cp311-cp311-manylinux_2_31_x86_64.whl (412.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

gl_observability_binary-0.1.4-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.4-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for gl_observability_binary-0.1.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 232eacc32d904748f29270718e5c4475e311a8b0aa53460d43d17e45b0091e65
MD5 f74998af1183d21aa5e3148773a387dc
BLAKE2b-256 79bac3120a1d4d80a6446b65f4b954a201b58bab92c1f47a8119116d9ef56996

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.4-cp313-cp313-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 5029667c9a284f06477261050e06f9f0b5aa3fdcb6c6edb71a33abbca20c65e6
MD5 5e4ceb0d6f038b4dd16b294f83e550bb
BLAKE2b-256 3ac47f37f37d24d5de53a001f334bee03bc40d02a9c51520d7c41c9973db136f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.4-cp313-cp313-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 b3d78e6754d448948acd1c43a004355f06f251d854654642e52902adf37596a5
MD5 2c72d2dc6fe314b753fc603feb59b34a
BLAKE2b-256 826323e6ec41affde42785feba02676c16ba17b856ef25f5ac7fcd00d87e1f7a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 dd0e5dd77ff755ed9b3c8010926f229ad950fcd039537ff87fdc451cc14400f7
MD5 e352eab2c1295701fdde56129b4f7410
BLAKE2b-256 5b2a2eb9512817dbe438f21dbc8f789046d2f230497fed861e139c524dc612c3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.4-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 2adf5e1ce4bba28b48c08b2799701d52e120646c27988692a69a3abe4c570a35
MD5 89719f98e9c5b8c03b6636153b09f78f
BLAKE2b-256 0b09062df4c4c86e1e0901f7da37f3f0aafe62a39bfb788bcb0e8594134fbe7a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.4-cp312-cp312-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 357135cefd9e40c86a79014ba6572f5691e9e1115c22d30c416a639f9a050029
MD5 a84a8a0c081e5921fa1766cc15420f86
BLAKE2b-256 e9a13842fefa0b4ace70fe4eb6d46d45a3a488a22fe19b998329a006f285b57b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 dbe2deeb65fca38bfba4dc3d24e5b9159a250229c4a108f86b07cede5f0af225
MD5 d2085d23b149756fabc09eb35b49b791
BLAKE2b-256 ec1d2a086178b956e76b064fc90111eebc4fefc3232123faf9386eeeca0a13de

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.4-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 757aec1bbf5c82095db2ce40acfe47bd46219bd5901ba76e461066f22321d7e4
MD5 51797114557d1c41c981c9f4a1b1f979
BLAKE2b-256 778991c9572a3a716755d1a15bd715225861b493839fc6cd2dbf084246f98556

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.4-cp311-cp311-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 466155a63e66de451385a938dce64e00234df3361eed3c15dbb24ce532af830e
MD5 7a07a1e884a6b99adc8e220705ea2cc2
BLAKE2b-256 8da1d0d7c1e990fe8664d499b18240c46dca4d6776942e6e74a2b7a0d5725279

See more details on using hashes here.

Provenance

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