Skip to main content

Respan instrumentation plugin for Portkey

Project description

respan-instrumentation-portkey

Respan instrumentation plugin for Portkey. Wraps OpenInference's Portkey instrumentor, translates spans into the Respan tracing shape, and strips off-contract helper aliases before export.

Configuration

1. Install

pip install respan-instrumentation-portkey

2. Set Environment Variables

Variable Required Description
RESPAN_API_KEY Yes Your Respan API key for trace export.
RESPAN_BASE_URL No Defaults to https://api.respan.ai/api.
PORTKEY_API_KEY Yes Your Portkey API key for Portkey Gateway calls.
PORTKEY_PROVIDER or PORTKEY_CONFIG Yes Portkey provider slug or config slug.

Quickstart

import os
from dotenv import load_dotenv

load_dotenv()

from portkey_ai import Portkey
from respan import Respan, workflow
from respan_instrumentation_portkey import PortkeyInstrumentor

respan = Respan(
    api_key=os.environ["RESPAN_API_KEY"],
    base_url=os.getenv("RESPAN_BASE_URL", "https://api.respan.ai/api"),
    instrumentations=[PortkeyInstrumentor()],
)

client = Portkey(
    api_key=os.environ["PORTKEY_API_KEY"],
    provider=os.getenv("PORTKEY_PROVIDER"),
    config=os.getenv("PORTKEY_CONFIG"),
)


@workflow(name="portkey_chat_completion")
def run_chat() -> str:
    response = client.chat.completions.create(
        model=os.getenv("PORTKEY_MODEL", "gpt-4o-mini"),
        messages=[{"role": "user", "content": "Say hello from Portkey."}],
    )
    return response.choices[0].message.content or ""


try:
    print(run_chat())
finally:
    respan.flush()
    respan.shutdown()

Further Reading

See the Respan example projects for runnable scripts.

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

respan_instrumentation_portkey-0.1.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file respan_instrumentation_portkey-0.1.0.tar.gz.

File metadata

File hashes

Hashes for respan_instrumentation_portkey-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4be14485a8ee23696b2e33ee577d6c537693207481b9a4804bcb0ae7c1130bc3
MD5 7cbff61eb83c9e9966d4aa0c0ffdacb4
BLAKE2b-256 85d1e2a846fbdae4b2967d812706a797747e1d2129f6548358d6f74b0e056664

See more details on using hashes here.

File details

Details for the file respan_instrumentation_portkey-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for respan_instrumentation_portkey-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dda4d4cf127a77c43fbe70a6e0369c06c3bbf06db10a1ec9974b6cfa1a462a15
MD5 513cc0db1de3e156507962ebcab6a3da
BLAKE2b-256 4408723fa64552ee6c9c4494df25d52c3e7c6735ef3ff109eac131c2909e0843

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