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 and metrics.
  • 🛡️ 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 for OpenTelemetry, Sentry, or both.

OpenTelemetry Configuration (External Exporter)

This setup sends traces to an external OTLP collector (e.g., Jaeger, Tempo).

from fastapi import FastAPI
from gl_observability.backend import FastAPIConfig, OpenTelemetryConfig
from gl_observability import TelemetryConfig, init_telemetry

# 1. Setup FastAPI Config (optional, if using FastAPI)
app = FastAPI()
fastapi_config = FastAPIConfig(app=app)

# 2. Configure OpenTelemetry
otel_config = OpenTelemetryConfig(
    endpoint="localhost:4317",  # OTLP endpoint
    use_grpc=False,             # Use gRPC or HTTP
    fastapi_config=fastapi_config,
    use_langchain=True,         # Enable Langchain instrumentation
    use_httpx=True,             # Enable HTTPX instrumentation
    use_requests=True,          # Enable Requests instrumentation
    attributes={"service.name": "my-service", "env": "production"}
)

# 3. Initialize Telemetry
init_telemetry(TelemetryConfig(otel_config=otel_config))

Sentry Configuration

This setup sends errors and traces to Sentry.

from gl_observability.backend import SentryConfig
from gl_observability import TelemetryConfig, init_telemetry

def traces_sampler(sampling_context: dict) -> float:
    """Custom trace sampler."""
    return 1.0

# 1. Configure Sentry
sentry_config = SentryConfig(
    dsn="your-sentry-dsn",
    environment="production",
    release="1.0.0",
    traces_sampler=traces_sampler,
    send_default_pii=True
)

# 2. Initialize Telemetry
init_telemetry(TelemetryConfig(sentry_config=sentry_config))

Sentry with OpenTelemetry

This setup combines Sentry with OpenTelemetry instrumentation, allowing Sentry to capture OTel spans.

from fastapi import FastAPI
from gl_observability.backend import FastAPIConfig, OpenTelemetryConfig, SentryConfig
from gl_observability import TelemetryConfig, init_telemetry

app = FastAPI()
fastapi_config = FastAPIConfig(app=app)

# 1. Configure OpenTelemetry (without endpoint, as Sentry handles export)
otel_config = OpenTelemetryConfig(
    attributes={"service.name": "my-service"},
    fastapi_config=fastapi_config,
    use_langchain=True
)

# 2. Configure Sentry with OTel config
sentry_config = SentryConfig(
    dsn="your-sentry-dsn",
    environment="production",
    open_telemetry_config=otel_config
)

# 3. Initialize Telemetry
init_telemetry(TelemetryConfig(sentry_config=sentry_config))

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.0.0b1-cp313-cp313-win_amd64.whl (292.6 kB view details)

Uploaded CPython 3.13Windows x86-64

gl_observability_binary-0.0.0b1-cp313-cp313-manylinux_2_31_x86_64.whl (449.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.31+ x86-64

gl_observability_binary-0.0.0b1-cp313-cp313-macosx_13_0_arm64.whl (246.1 kB view details)

Uploaded CPython 3.13macOS 13.0+ ARM64

gl_observability_binary-0.0.0b1-cp312-cp312-win_amd64.whl (294.8 kB view details)

Uploaded CPython 3.12Windows x86-64

gl_observability_binary-0.0.0b1-cp312-cp312-manylinux_2_31_x86_64.whl (451.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.31+ x86-64

gl_observability_binary-0.0.0b1-cp312-cp312-macosx_13_0_arm64.whl (246.8 kB view details)

Uploaded CPython 3.12macOS 13.0+ ARM64

gl_observability_binary-0.0.0b1-cp311-cp311-win_amd64.whl (298.6 kB view details)

Uploaded CPython 3.11Windows x86-64

gl_observability_binary-0.0.0b1-cp311-cp311-manylinux_2_31_x86_64.whl (411.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

gl_observability_binary-0.0.0b1-cp311-cp311-macosx_13_0_arm64.whl (244.0 kB view details)

Uploaded CPython 3.11macOS 13.0+ ARM64

File details

Details for the file gl_observability_binary-0.0.0b1-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for gl_observability_binary-0.0.0b1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 ceff8cfb75d10192d4e0dd9673c28311c5408e9021eab03990c610dd42d4ee82
MD5 9db93632a26ca45bb4947fc7642dd261
BLAKE2b-256 55662e45fadc95809b9420b595dd6537304a2baeff1cbc4a81ab57f5753712f3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.0.0b1-cp313-cp313-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 e8f716a827db1001f7a98edc0c580391c79322123aaa9099a38ef1ce75281fe1
MD5 237444c5fefe53a64231db4294372234
BLAKE2b-256 711ac26fa505a2bac0090bb27db4b3b3511d708fcde5bcc9d8d3e4c39a9d54cd

See more details on using hashes here.

File details

Details for the file gl_observability_binary-0.0.0b1-cp313-cp313-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for gl_observability_binary-0.0.0b1-cp313-cp313-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 00e57164b3be749b963fa0404caf7e1e0f32f16372070fde1113d25a5878787c
MD5 8dd541096ad3c63160d6a8debb82cd29
BLAKE2b-256 f31e83999a10f7c2ba97bb25abeba6ad748cd97da4111b05f83980242584205a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.0.0b1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 05f5e9c16aacf2d850d3063fa98ed29a1cd37828974faaea476b80d66a5b93c1
MD5 435455c20b8b8eedd9db726848ec494e
BLAKE2b-256 9764ad898bdbd4dbd86d40e63d7c58f43107c6763f58ffdcd4466cf689cd2ce1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.0.0b1-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 e1f2b7093002731e9973a3dea7b3c3d739ec32ac58a4322fff924db281e6ad06
MD5 60ddc205f302deb00290d91c238ad183
BLAKE2b-256 bb3fdf7504cc0c64b99445424e5b1890243501f641e3ed9b2be5c62b9fb79155

See more details on using hashes here.

File details

Details for the file gl_observability_binary-0.0.0b1-cp312-cp312-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for gl_observability_binary-0.0.0b1-cp312-cp312-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 7dab361d18b2faf713b039d7f8ec961f62b5f1bc59084d2a359e2d9ddc85800a
MD5 31927d250b38762307d3a0ce9dc01955
BLAKE2b-256 dcf8fd014bf10c3ba25099479439fb775456600e04b98111f983c0b691a9844b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.0.0b1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 8be812ceab2e4879a9b6cc170c44389f6b19452f02fe84ff2e9aacc3300cc787
MD5 ba521409e0c78bd9c490d6bec50d8dbf
BLAKE2b-256 11fbb05f3e4511105c8ac045c05c67a433c4304caa3602ed2a3f3a7162d2b666

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.0.0b1-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 a915ab20bbd9dcf7d605c14192bac56b8d44244720652fcea1a433a76034d786
MD5 fc2f2c4bfa8a3f6ece410fc40cdca82b
BLAKE2b-256 46cba32320aa3b4477ea5200fff6af220e109fe6e331dba177f07068acfeeb79

See more details on using hashes here.

File details

Details for the file gl_observability_binary-0.0.0b1-cp311-cp311-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for gl_observability_binary-0.0.0b1-cp311-cp311-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 520155449b8d4e8b1862c7d948f6424a98c6fe04be998c07db5e14c5c3831a0c
MD5 6ac34926e16f7c1aec62c24983c59248
BLAKE2b-256 61e545aa004259e23a62e2d858266579192663fec24bc15b57142a31ef146993

See more details on using hashes here.

Provenance

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