Skip to main content

An asynchronous Sentry NodeStorage backend for OpenSearch.

Project description

Sentry OpenSearch NodeStore

License

An asynchronous Sentry NodeStorage backend designed for OpenSearch.

This package provides a Sentry-compatible NodeStorage implementation that uses the modern asynchronous client opensearch-py to store and retrieve event data. It is intended to be used within a Sentry environment as a custom backend plugin.

Features

  • Asynchronous: Built with asyncio and opensearch-py's AsyncOpenSearch client for high-performance, non-blocking I/O.
  • Highly Configurable: Index settings like shards, replicas, codec, and index patterns can be configured via environment variables.
  • Automatic Template Management: On startup, it creates a fully configured index template to ensure new daily indices have the correct mappings and settings.
  • Time-Based Cleanup: Includes a cleanup method to automatically delete old indices based on a configurable cutoff date.
  • Robust and Tested: Comes with a full suite of unit and integration tests to ensure reliability.

Installation

pip install sentry-opensearch-nodestore

Usage

Here is a basic example of how to instantiate and use the NodeStore. This code would typically be integrated into your Sentry configuration.

import asyncio
from datetime import datetime, timezone, timedelta
from opensearchpy import AsyncOpenSearch
from sentry_opensearch_nodestore import AsyncOpenSearchNodeStorage

async def main():
    # 1. Initialize the async OpenSearch client
    #    For a real application, configure hosts, SSL, and auth as needed.
    os_client = AsyncOpenSearch(
        hosts=[{'host': 'localhost', 'port': 9200}]
    )

    # 2. Instantiate the NodeStore
    nodestore = AsyncOpenSearchNodeStorage(os_client=os_client)

    # 3. Bootstrap the backend (creates the index template if it doesn't exist)
    print("--- Running Bootstrap ---")
    await nodestore.bootstrap()
    print("Bootstrap complete.")

    # 4. Use the nodestore methods
    node_id = "event_abc123"
    node_data = b'{"message": "hello from opensearch"}'

    await nodestore._set_bytes(node_id, node_data)
    retrieved_data = await nodestore._get_bytes(node_id)
    
    print(f"Retrieved: {retrieved_data.decode('utf-8')}")

    await nodestore.delete(node_id)
    print(f"Deleted node: {node_id}")

    # 5. Run cleanup for indices older than 10 days
    cutoff_date = datetime.now(timezone.utc) - timedelta(days=10)
    await nodestore.cleanup(cutoff_date)
    print("Cleanup complete.")

    # 6. Close the client connection when your application shuts down
    await os_client.close()

if __name__ == "__main__":
    asyncio.run(main())

Configuration

The backend is configured via environment variables, allowing for flexible deployment without code changes.

Environment Variable Description Default Value
SENTRY_NODESTORE_OPENSEARCH_NUMBER_OF_SHARDS The number of primary shards for new indices created by the template. 3
SENTRY_NODESTORE_OPENSEARCH_NUMBER_OF_REPLICAS The number of replica shards for new indices created by the template. 1
SENTRY_NODESTORE_OPENSEARCH_INDEX_PATTERN The index pattern that the template will apply to. sentry-*
SENTRY_NODESTORE_OPENSEARCH_INDEX_CODEC The compression codec used for storing data. zstd is a good balance. best_compression uses more CPU for smaller size. zstd

Development and Testing

This project uses Poetry for dependency management and testing.

1. Initial Setup

First, clone the repository and install the development dependencies using Poetry.

git clone https://github.com/your-username/sentry-opensearch-nodestore.git
cd sentry-opensearch-nodestore
poetry install

License

This project is licensed under the MIT License. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sentry_opensearch_nodestore-1.0.1.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sentry_opensearch_nodestore-1.0.1-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file sentry_opensearch_nodestore-1.0.1.tar.gz.

File metadata

  • Download URL: sentry_opensearch_nodestore-1.0.1.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.13.7 Darwin/24.2.0

File hashes

Hashes for sentry_opensearch_nodestore-1.0.1.tar.gz
Algorithm Hash digest
SHA256 51bdd3ef99fb45a740808a5b29d512b492e433193dc0ffda9782b55e4e8906dc
MD5 0773a1cc7a6f13ad0265768157687571
BLAKE2b-256 b64f899ce490c127d89292504068433556c55b26e4bf8588af1dea305ace603c

See more details on using hashes here.

File details

Details for the file sentry_opensearch_nodestore-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for sentry_opensearch_nodestore-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a7bb9c068e47ee050906c966dc27aeec5143ec9e76828fc13ae7d6280615c4ec
MD5 71d9347a99a66128604cd68c8dc0a03b
BLAKE2b-256 7362219c1cbbaf1677abc0b2bda8973b9e84eb0da87deddd4dfcfda985b3ffc4

See more details on using hashes here.

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