Skip to main content

LaunchDarkly Observability SDK for Python

Actions Status Documentation

PyPI PyPI

Early Access Preview️

NB: APIs are subject to change until a 1.x version is released.

Install

# poetry
poetry add launchdarkly-observability

# pip
pip install launchdarkly-observability

Install the plugin when configuring your LaunchDarkly SDK.

from ldobserve import ObservabilityConfig, ObservabilityPlugin, observe
import ldclient
from ldclient.context import Context
from ldclient.config import Config

ldclient.set_config(Config("your-sdk-key", plugins=[
    ObservabilityPlugin(
        ObservabilityConfig(
            service_name="your-service-name",
            service_version="your-service-sha",
        ))]))

Global attributes

Use observe.set_attributes to add attributes to every span, log record, and metric data point recorded after the call, including spans and logs from automatic instrumentation and the standard logging module. Calls merge by key; use observe.remove_attributes to remove keys.

from ldobserve import observe

# Safe to call before the plugin is initialized.
observe.set_attributes({"tenant.id": "acme", "deployment.region": "us-east-1"})

# Attributes passed explicitly take precedence over global attributes.
observe.record_count("orders.placed", 1, {"tenant.id": "override"})

observe.remove_attributes(["deployment.region"])
  • Precedence: attributes set on the span, log, or metric > global attributes > resource attributes. Global attributes only fill in keys that are not already present.
  • A span gets the global attributes that are set when it starts.
  • Global attributes are stored in memory, shared by all threads in the process, and are not persisted.

Custom span and log processors

Pass OpenTelemetry processors with the span_processors and log_processors options. They run in the order given, after global attributes are applied and before data is exported, so changes they make are exported. An exception raised by a processor is logged and does not stop export.

import typing

from opentelemetry.context import Context
from opentelemetry.sdk._logs import LogData, LogRecordProcessor
from opentelemetry.sdk.trace import Span, SpanProcessor

from ldobserve import ObservabilityConfig, ObservabilityPlugin


class TeamSpanProcessor(SpanProcessor):
    def on_start(self, span: Span, parent_context: typing.Optional[Context] = None) -> None:
        span.set_attribute("team", "checkout")


class RedactingLogProcessor(LogRecordProcessor):
    def emit(self, log_data: LogData) -> None:
        if "user.email" in log_data.log_record.attributes:
            log_data.log_record.attributes["user.email"] = "[redacted]"

    def shutdown(self) -> None:
        pass

    def force_flush(self, timeout_millis: int = 30000) -> bool:
        return True


ObservabilityPlugin(
    ObservabilityConfig(
        service_name="your-service-name",
        span_processors=[TeamSpanProcessor()],
        log_processors=[RedactingLogProcessor()],
    )
)

LaunchDarkly overview

LaunchDarkly is a feature management platform that serves trillions of feature flags daily to help teams build better software, faster. Get started using LaunchDarkly today!

Twitter Follow

Contributing

We encourage pull requests and other contributions from the community. Check out our contributing guidelines for instructions on how to contribute to this SDK.

About LaunchDarkly

  • LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:
    • Roll out a new feature to a subset of your users (like a group of users who opt-in to a beta tester group), gathering feedback and bug reports from real-world use cases.
    • Gradually roll out a feature to an increasing percentage of users, and track the effect that the feature has on key metrics (for instance, how likely is a user to complete a purchase if they have feature A versus feature B?).
    • Turn off a feature that you realize is causing performance problems in production, without needing to re-deploy, or even restart the application with a changed configuration file.
    • Grant access to certain features based on user attributes, like payment plan (eg: users on the ‘gold’ plan get access to more features than users in the ‘silver’ plan). Disable parts of your application to facilitate maintenance, without taking everything offline.
  • LaunchDarkly provides feature flag SDKs for a wide variety of languages and technologies. Check out our documentation for a complete list.
  • Explore LaunchDarkly

Metadata

Release files for launchdarkly-observability 1.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for launchdarkly-observability 1.4.0
File Size Uploaded Provenance Actions
launchdarkly_observability-1.4.0.tar.gz 55.1 kB Without provenance Details for launchdarkly_observability-1.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for launchdarkly-observability 1.4.0
File Interpreter ABI Platform Actions
launchdarkly_observability-1.4.0-py3-none-any.whl Python 3 none any Details for launchdarkly_observability-1.4.0-py3-none-any.whl

Total release size: 125.2 kB

Release files / launchdarkly_observability-1.4.0.tar.gz

Download URL launchdarkly_observability-1.4.0.tar.gz
Size 55.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8367958dccdb443175b661eb522c4b5c6914cdfd49af12918f3d3a196b19d33d
BLAKE2b-256 checksum
How to use checksums
77fe698445774578af4a8753d92a204d0b23bac76a9a502ba76bae348052937d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.10.22 Linux/7.0.0-1019-azure

Release files / launchdarkly_observability-1.4.0-py3-none-any.whl

Download URL launchdarkly_observability-1.4.0-py3-none-any.whl
Size 70.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0d6ec90fbb4fd9d4d76d45b4fa1c25cc02542d6c5d04c7275543710c3cdacf35
BLAKE2b-256 checksum
How to use checksums
25149233620b81f0174a401175b065f5c1461b63fe57cc4257152d50e1aed5de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.10.22 Linux/7.0.0-1019-azure

Security for launchdarkly-observability 1.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page