OpenInference instrumentation utilities
Project description
OpenInference Instrumentation
Utility functions for OpenInference instrumentation.
Installation
pip install openinference-instrumentation
Customizing Spans
The openinference-instrumentation
package offers utilities to track important application metadata such as sessions and metadata using Python context managers:
using_session
: to specify a session ID to track and group a multi-turn conversation with a userusing_user
: to specify a user ID to track different conversations with a given userusing_metadata
: to add custom metadata, that can provide extra information that supports a wide range of operational needsusing_tag
: to add tags, to help filter on specific keywordsusing_prompt_template
: to reflect the prompt template used, with its version and variables. This is useful for prompt template managementusing_attributes
: it helps handling multiple of the previous options at once in a concise manner
For example:
from openinference.instrumentation import using_attributes
tags = ["business_critical", "simple", ...]
metadata = {
"country": "United States",
"topic":"weather",
...
}
prompt_template = "Please describe the weather forecast for {city} on {date}"
prompt_template_variables = {"city": "Johannesburg", "date":"July 11"}
prompt_template_version = "v1.0"
with using_attributes(
session_id="my-session-id",
user_id="my-user-id",
metadata=metadata,
tags=tags,
prompt_template=prompt_template,
prompt_template_version=prompt_template_version,
prompt_template_variables=prompt_template_variables,
):
# Calls within this block will generate spans with the attributes:
# "session.id" = "my-session-id"
# "user.id" = "my-user-id"
# "metadata" = "{\"key-1\": value_1, \"key-2\": value_2, ... }" # JSON serialized
# "tag.tags" = "["tag_1","tag_2",...]"
# "llm.prompt_template.template" = "Please describe the weather forecast for {city} on {date}"
# "llm.prompt_template.variables" = "{\"city\": \"Johannesburg\", \"date\": \"July 11\"}" # JSON serialized
# "llm.prompt_template.version " = "v1.0"
...
You can read more about this in our docs.
Tracing Configuration
This package contains the central TraceConfig
class, which lets you specify a tracing configuration that lets you control settings like data privacy and payload sizes. For instance, you may want to keep sensitive information from being logged for security reasons, or you may want to limit the size of the base64 encoded images logged to reduced payload size.
In addition, you an also use environment variables, read more here. The following is an example of using the TraceConfig
object:
from openinference.instrumentation import TraceConfig
config = TraceConfig(
hide_inputs=hide_inputs,
hide_outputs=hide_outputs,
hide_input_messages=hide_input_messages,
hide_output_messages=hide_output_messages,
hide_input_images=hide_input_images,
hide_input_text=hide_input_text,
hide_output_text=hide_output_text,
base64_image_max_length=base64_image_max_length,
)
tracer_provider=...
# This example uses the OpenAIInstrumentor, but it works with any of our auto instrumentors
OpenAIInstrumentor().instrument(tracer_provider=tracer_provider, config=config)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file openinference_instrumentation-0.1.18.tar.gz
.
File metadata
- Download URL: openinference_instrumentation-0.1.18.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d60b54a82173b31e551739c1ee04cbd9dfb33f7846c46568663bcc03e3a990f4 |
|
MD5 | 4475dbd61f212ba4e7b8d40256a71928 |
|
BLAKE2b-256 | 4600f356485412eec1f6cdc7e01fcbf1814e66ccb94e0c48bd9b4d0f0dacea6c |
File details
Details for the file openinference_instrumentation-0.1.18-py3-none-any.whl
.
File metadata
- Download URL: openinference_instrumentation-0.1.18-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 873d1851465588b01a3d568b8efb7c6630d7094e66f56415fbf47377c0ce8659 |
|
MD5 | f38b46cce30af51091ab5d76b11c5c7a |
|
BLAKE2b-256 | c06ccc3c1b0c85719a2729ae4ba4562c01e12dd20f744bcf0a1b3e3eb3da7a72 |