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, 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

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

Uploaded CPython 3.13Windows x86-64

gl_observability_binary-0.2.1-cp313-cp313-manylinux_2_31_x86_64.whl (466.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.31+ x86-64

gl_observability_binary-0.2.1-cp313-cp313-macosx_13_0_arm64.whl (269.8 kB view details)

Uploaded CPython 3.13macOS 13.0+ ARM64

gl_observability_binary-0.2.1-cp312-cp312-win_amd64.whl (241.1 kB view details)

Uploaded CPython 3.12Windows x86-64

gl_observability_binary-0.2.1-cp312-cp312-manylinux_2_31_x86_64.whl (468.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.31+ x86-64

gl_observability_binary-0.2.1-cp312-cp312-macosx_13_0_arm64.whl (269.4 kB view details)

Uploaded CPython 3.12macOS 13.0+ ARM64

gl_observability_binary-0.2.1-cp311-cp311-win_amd64.whl (245.5 kB view details)

Uploaded CPython 3.11Windows x86-64

gl_observability_binary-0.2.1-cp311-cp311-manylinux_2_31_x86_64.whl (425.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

gl_observability_binary-0.2.1-cp311-cp311-macosx_13_0_arm64.whl (266.4 kB view details)

Uploaded CPython 3.11macOS 13.0+ ARM64

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.2.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6ffc2235b4593cb78cc1f4f044bb33320437b058e94b9a1accb46b23005a1f68
MD5 29bdce28074d429160e924da46e7939a
BLAKE2b-256 97428619d77229d261ef48b70a84bd947415a8282ac108121548bc8cd3b43763

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.2.1-cp313-cp313-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 c40a6e0adb53634311a7934620814507381d2afcfe2d593693d52e094acc23dc
MD5 f395727404dd61666feb294522530d72
BLAKE2b-256 90bcc40b70ca15a0873dd2c49e0ada724abd72e6f963bee3ef939961e1abb226

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.2.1-cp313-cp313-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 c0b25c0319c1f59422d9ed407a30e0a0ccf6f51434d15e9f91dc36e025c43e02
MD5 6bb7ae74ab85e158fd86a7446383095f
BLAKE2b-256 19dc18fe415f66cd14afbd451caeeb19c5e754d1d45c895b27c8aacd56a292ec

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.2.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 46630cf837c9e94a3d33ec19b837dd6007a93f3c34c71de3ce48e49d371f5c74
MD5 58af09b918858fa546d1b431329747a1
BLAKE2b-256 4bd51885dfa4b98359dd0d38772b62f08bd11d3c50f982ee2eb9e8eca4e80705

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.2.1-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 ae4a6c028ce8414ae9befcd8ce7229b9b15b416165c14512a9dba58123367b31
MD5 4b9bca81bff3d4808fd65e38cf0885e7
BLAKE2b-256 00d6b7df1e212a224ef7d1ff88e8754cd9257c637af447a07c978aeba2607b9e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.2.1-cp312-cp312-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 3e634524b2e3d3102f685b970e3ebad64846f59dd3f8289d8a54b6196824d59d
MD5 580f2ceb23242b1737f243bd4075fb13
BLAKE2b-256 68f3f6cb568a0f77261dc2f6d0ab5b9c854d80c3baadacd46fe278a2cf26c0a1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.2.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 17ac787d76cc84ab3580849b2b1ac978a0b87d21aaaccc0e7f6c640165bd6934
MD5 10475a98481ca1028816e349edfe04cc
BLAKE2b-256 667f28d3df57a00d9ccbbb29ef339dad282048ad2194155478e3e3f2cef5b249

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gl_observability_binary-0.2.1-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 d8ade1fb720563f70c9f207c6b380844d4acd15eda2f134fc99332ff27bdbcff
MD5 0a4d6840faec369a5007729fe98998ed
BLAKE2b-256 b76ba70530ee2e0c739243adc699cd20195a61d1babaffa4cd6eb1c2c8423bb2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gl_observability_binary-0.2.1-cp311-cp311-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 077fc7c52ac51a8678190a5ea07a89cb90dee549a351c675259c6a4845021175
MD5 53c749921c54ae24ebad9608ea9d9a52
BLAKE2b-256 9a760982a436fde0b4ebb930996b9bb29284fad90d98f6e9f58cc02b0cec4434

See more details on using hashes here.

Provenance

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