Skip to main content

Empowering Developers with AI-First DevTools

Project description

Introduction

Welcome to the InfraStack AI Python SDK! This SDK is designed to help developers and development teams integrate advanced observability capabilities into their applications. InfraStack AI provides next-generation observability tools that allow you to ship high-quality code and gain actionable insights in milliseconds.

Capabilities

Currently, this SDK supports:

  1. Flask Instrumentation: Easily instrument your Flask applications to monitor and trace requests and performance.
  2. Logging: Send logs to InfraStack AI for centralized log management and analysis.
  3. Tracing: Create and manage traces to monitor the performance and behavior of your application.

We are actively working on adding support for Django FastAPI and LLM's, so stay tuned for more updates!

Installation

pip3 install infrastack

Integrations

Flask Instrument

To instrument your Flask application with InfraStack AI, use the following code snippet:

from infrastack import FlaskInstrument
from flask import Flask

app = Flask(__name__)

FlaskInstrument("your_service_name", app, infrastackai_api_key="your_infrastack_api_key")

@app.route('/')
def hello_world():
    return 'Hello, World!'

if __name__ == '__main__':
    app.run()

Logging

To send logs to InfraStack AI, use the following code snippet:

from infrastack import LogHandler
import logging

logger = logging.getLogger(__name__)
LogHandler("your_service_name", logger, infrastackai_api_key="your_infrastack_api_key")

logger.info("TEST")

Tracing

To create and use a tracer with InfraStack AI, use the following code snippet:

from infrastack import CreateTracer

my_tracer = CreateTracer("your_service_name", "trace_name", infrastackai_api_key="your_infrastack_api_key")

with my_tracer.start_span("scope-create-version") as span:
    span.set_attribute("version", "0.0.0")
    span.set_attribute("scope", "create-version")
    span.set_attribute("author", "Your Name")
    print("hi")

OpenAI Instrument

To instrument your OpenAI API calls with InfraStack AI, use the following code snippet:

from infrastack import OpenAIInstrument
from openai import OpenAI

# Initialize OpenAIInstrument
instrument = OpenAIInstrument("your_service_name", catch_content=False, infrastackai_api_key="your_infrastack_api_key")

# Example OpenAI API call
client = OpenAI(api_key="your_openai_api_key")

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "user", "content": [{"type": "text", "text": "Hi"}]}
    ]
)

print(response)

Note on API Key Configuration

The InfraStack AI SDK provides two methods for configuring your API key:

  1. Passing it as a Parameter: You can directly pass the infrastackai_api_key as a parameter when initializing the Flask instrument, log handler, or tracer.

  2. Environment Variable (.env): Alternatively, you can set the INFRASTACKAI_API_KEY as an environment variable. If this environment variable is set, the SDK will automatically use it, and you do not need to pass the API key as a parameter.

Contributing

We welcome contributions! Please submit a pull request or open an issue to get started.

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

infrastack-0.2.0.tar.gz (5.5 kB view details)

Uploaded Source

File details

Details for the file infrastack-0.2.0.tar.gz.

File metadata

  • Download URL: infrastack-0.2.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.8.18

File hashes

Hashes for infrastack-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4db1957bcef58019d4213530e5ef41294a1040d62adbaf5d91acfdb9b525ab3a
MD5 deaa8ead8e2bddfecb5f2e98a8e3c04e
BLAKE2b-256 f3ae8bdd8cfd90b9b525b464f6fb24dbdc8c44008f921dc305ed054a1db4b901

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