Skip to main content

OpenInference Instrumentation

PyPI Version

Utility functions for OpenInference instrumentation.

Installation

pip install openinference-instrumentation

Annotation and Evaluation Attributes

Use get_annotation_attributes and get_evaluation_attributes to turn typed Annotation objects into flattened OpenInference span attributes. Both helpers support "span" (the default), "trace", and "session" scopes and assign contiguous collection indices in input order.

from openinference.instrumentation import (
    Annotation,
    get_annotation_attributes,
    get_evaluation_attributes,
)

span_annotations = get_annotation_attributes(
    annotations=[
        Annotation(
            name="hallucination",
            label="factual",
            explanation="Every claim is supported by the retrieved documents.",
            annotator_kind="LLM",
            identifier="judge-v2",
            metadata={"rubric_version": 2},
        )
    ]
)

trace_evaluations = get_evaluation_attributes(
    evaluations=[Annotation(name="correctness", score=0.95)],
    scope="trace",
)

span.set_attributes({**span_annotations, **trace_evaluations})

Annotation has these fields:

  • name (required): criterion or metric name.
  • At least one of score, label, or explanation (required by the helpers).
  • annotator_kind: conventionally "HUMAN", "LLM", or "CODE"; custom values are allowed.
  • identifier: stable producer-assigned result identifier.
  • metadata: a dictionary to JSON-serialize, or an already serialized JSON object string.

The evaluation helper uses the same Annotation model because evaluation is an alternative attribute terminology for annotations. It emits evaluations.* instead of annotations.*. Trace and session scopes add the corresponding trace. or session. prefix. Session-scoped annotations also require the carrying span to have session.id; post-hoc span and trace annotations require the target Span Link described in the annotation specification.

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 user
  • using_user: to specify a user ID to track different conversations with a given user
  • using_metadata: to add custom metadata, that can provide extra information that supports a wide range of operational needs
  • using_tag: to add tags, to help filter on specific keywords
  • using_prompt_template: to reflect the prompt template used, with its version and variables. This is useful for prompt template management
  • using_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)

Download files

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

Source Distribution

openinference_instrumentation-0.1.58.tar.gz (41.2 kB view details)

Uploaded Source

Built Distribution

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

openinference_instrumentation-0.1.58-py3-none-any.whl (48.9 kB view details)

Uploaded Python 3

File details

Details for the file openinference_instrumentation-0.1.58.tar.gz.

File metadata

File hashes

Hashes for openinference_instrumentation-0.1.58.tar.gz
Algorithm Hash digest
SHA256 c50e5463d74991200f584a8250848f7f181ac878c936be16dd4c5d4be9e7aba1
MD5 fc72e79cd389110f49c648ef7ccb059b
BLAKE2b-256 7ad1560d9cef6a78d6a7c55793e73319056acc491dd349aa2d70479115f15d06

See more details on using hashes here.

Provenance

The following attestation bundles were made for openinference_instrumentation-0.1.58.tar.gz:

Publisher: publish.yaml on Arize-ai/openinference

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file openinference_instrumentation-0.1.58-py3-none-any.whl.

File metadata

File hashes

Hashes for openinference_instrumentation-0.1.58-py3-none-any.whl
Algorithm Hash digest
SHA256 cb51a4eeae6892fc060b9e9b7117533e6b860341a24a7d26846583c621b526f5
MD5 72bd7533670ae5effca9f2309c21960b
BLAKE2b-256 8d81d5927eb02af9e13f521c85c5d9db6f344fe7dfb8564d54f1baf92bccc2e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for openinference_instrumentation-0.1.58-py3-none-any.whl:

Publisher: publish.yaml on Arize-ai/openinference

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.58 This release

2 files

0.1.57

2 files

0.1.56

2 files

0.1.55

2 files

0.1.54

2 files

0.1.53

2 files

0.1.52

2 files

0.1.51

2 files

0.1.50

2 files

0.1.49

2 files

0.1.48

2 files

0.1.47

2 files

0.1.46

2 files

0.1.45

2 files

0.1.44

2 files

0.1.43

2 files

0.1.42

2 files

0.1.41

2 files

0.1.40

2 files

0.1.39

2 files

0.1.38

2 files

0.1.37

2 files

0.1.36

2 files

0.1.35

2 files

0.1.34

2 files

0.1.33

2 files

0.1.32

2 files

0.1.31

2 files

0.1.30

2 files

0.1.29

2 files

0.1.28

2 files

0.1.27

2 files

0.1.26

2 files

0.1.25

2 files

0.1.24

2 files

0.1.23

2 files

0.1.22

2 files

0.1.21

2 files

0.1.20

2 files

0.1.19

2 files

0.1.18

2 files

0.1.17

2 files

0.1.16

2 files

0.1.15

2 files

0.1.14

2 files

0.1.13

2 files

0.1.12

2 files

0.1.11

2 files

0.1.10

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page