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.traces.opentelemetry 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.traces.sentry 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.traces.opentelemetry import FastAPIConfig, OpenTelemetryConfig
from gl_observability.traces.sentry import 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.1.0-cp313-cp313-win_amd64.whl (290.3 kB view details)

Uploaded CPython 3.13Windows x86-64

gl_observability_binary-0.1.0-cp313-cp313-manylinux_2_31_x86_64.whl (447.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.31+ x86-64

gl_observability_binary-0.1.0-cp313-cp313-macosx_13_0_arm64.whl (242.8 kB view details)

Uploaded CPython 3.13macOS 13.0+ ARM64

gl_observability_binary-0.1.0-cp312-cp312-win_amd64.whl (292.9 kB view details)

Uploaded CPython 3.12Windows x86-64

gl_observability_binary-0.1.0-cp312-cp312-manylinux_2_31_x86_64.whl (449.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.31+ x86-64

gl_observability_binary-0.1.0-cp312-cp312-macosx_13_0_arm64.whl (243.7 kB view details)

Uploaded CPython 3.12macOS 13.0+ ARM64

gl_observability_binary-0.1.0-cp311-cp311-win_amd64.whl (295.9 kB view details)

Uploaded CPython 3.11Windows x86-64

gl_observability_binary-0.1.0-cp311-cp311-manylinux_2_31_x86_64.whl (409.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

gl_observability_binary-0.1.0-cp311-cp311-macosx_13_0_arm64.whl (241.0 kB view details)

Uploaded CPython 3.11macOS 13.0+ ARM64

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 40166d9e9871884d830f5f239968fa146efe9bff45e930055e6cdef7eb463766
MD5 2a0d8d9a420dad2e2318b42cd3be727f
BLAKE2b-256 eead766a2aba0bd40709d8d258b86149c15469e5d5760be885e89a03537593ae

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.0-cp313-cp313-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 64e050f50cddbb7a0be87469599b3f261ee5ba1dd4e3f7a075b46f9ed35d2b30
MD5 398e04de5ed508ad26482e78aaaf6a3b
BLAKE2b-256 0b79b2e06180ab6783bc040ebfb9833bd60353fcd7c16cda2f6550be24740f03

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.0-cp313-cp313-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 1f685af94ac5d89f05049ca14c72b7860c145c78f67b2965df85bc71630805c7
MD5 0fc56fdb329a9954f90e1a9bbc0c9d65
BLAKE2b-256 e03fda026d2aa63a7b49d2ceaa73afc56d90ee72f6a9d773db353615800173f5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 9265c019ca69875254b54db1e9a4961e133c0ac402e01645abce2fb87fb093c7
MD5 4b90b9d6e9db645a357a66dfe1233457
BLAKE2b-256 3064ca8cb63421d4f9a3340231914bdf66c47baed2c09fe2b185674b46052171

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.0-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 f72d9a2f311def6b8b24356ce86bc81151ca114579b53b2d77511892927e8677
MD5 7901b4849a9d5d13f57b4b119cf88b73
BLAKE2b-256 c5c4866b340e0d40f03ce307e77f5fdf0f50523febac6bbc429e7b75b6e474b7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.0-cp312-cp312-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 d70eec539c975d79035b7560ad48a99b7216ce3d9d130a9fb53c5c10b122e3fd
MD5 7bd3eff15af2ca0feb1adea4109ccc91
BLAKE2b-256 bff9e7c343cefca7a0514dc06d77016fc31adde890fac4a2a5b33a854939a71f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 618f0e9eeb4960f274ada172fd262361ac84f8ab90e7b605bfdd0ecd0c8602df
MD5 2a89e76d66cc43d2fc615ccded17ca9f
BLAKE2b-256 2480f310d1da0d9b42545df54d1beb36d1e9011670eb955d899215e2a1891bd2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.0-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 a4e054bc8acd2256c9684965aee4dd687b561f2ca95033554a89ed356a09336a
MD5 869550e5a251062653e10bca73f2ee27
BLAKE2b-256 20fc868b5b99f048e1a6a3bbca52b25c39187bf3a33b0e487c248f399da53ee6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.1.0-cp311-cp311-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 daf225e0e6ff8bf5bad7f6936e853060ae4a8985332b0d883ef0dc244fcfc0b0
MD5 24802d2762da4a594b54ae961ec6fba9
BLAKE2b-256 4638f43d7ee300cc2fbe4f5475480affea7a1d374b5f04354cb3fab4fed55a96

See more details on using hashes here.

Provenance

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