openinference-instrumentation 0.1.83


pip install openinference-instrumentation

  Latest version

Released: Nov 21, 2026

Project Links

Meta
Author: OpenInference Authors
Requires Python: <3.16,>=3.10

Classifiers

Development Status
  • 5 - Production/Stable

Intended Audience
  • Developers

License
  • OSI Approved :: Apache Software License

Programming Language
  • Python
  • Python :: 3
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13
  • Python :: 3.14
  • Python :: 3.15

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"
    ...

Each helper also works as a decorator. The attributes stay attached for the whole call, including across await suspension points of async def functions and while the body of a generator or async def generator runs (without leaking into the code that consumes it):

from openinference.instrumentation import using_session, using_user

@using_session("my-session-id")
@using_user("my-user-id")
async def answer(question: str) -> str:
    # Spans created here, and by any awaited instrumented call, carry
    # "session.id" = "my-session-id" and "user.id" = "my-user-id"
    ...

When combining them with span-creating decorators such as tracer.agent or tracer.tool, put the using_* decorators on top: the attributes are copied onto a span when it starts, so they have to be attached before the span-creating decorator runs.

See examples/async_context_attribute_decorators.py for a runnable example that exports to a local Phoenix server.

You can read more about this in our docs.

Suppressing Tracing

suppress_tracing turns off span creation for everything inside its block. It works as a regular context manager and as an async one:

from openinference.instrumentation import suppress_tracing

with suppress_tracing():
    ...  # no spans are created here

async with suppress_tracing():
    ...  # nor here, including across awaits

See examples/suppress_tracing_sync_async.py for a runnable example that exports to a local Phoenix server and shows both forms.

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)
0.1.83 Nov 21, 2026
0.1.82 Nov 20, 2026
0.1.81 Nov 19, 2026
0.1.80 Nov 19, 2026
0.1.79 Nov 16, 2026
0.1.77 Nov 12, 2026
0.1.76 Nov 11, 2026
0.1.75 Oct 31, 2026
0.1.74 Oct 29, 2026
0.1.73 Oct 29, 2026
0.1.72 Oct 23, 2026
0.1.71 Oct 07, 2026
0.1.70 Oct 01, 2026
0.1.69 Oct 01, 2026
0.1.68 Oct 01, 2026
0.1.67 Oct 01, 2026
0.1.66 Sep 24, 2026
0.1.65 Sep 15, 2026
0.1.64 Sep 15, 2026
0.1.63 Sep 10, 2026
0.1.62 Sep 09, 2026
0.1.61 Sep 04, 2026
0.1.60 Sep 01, 2026
0.1.59 Aug 25, 2026
0.1.58 Aug 25, 2026
0.1.57 Aug 07, 2026
0.1.56 Jul 31, 2026
0.1.55 Jul 30, 2026
0.1.54 Jun 30, 2026
0.1.53 Jun 02, 2026
0.1.52 May 22, 2026
0.1.51 May 14, 2026
0.1.50 May 11, 2026
0.1.49 May 07, 2026
0.1.48 Apr 29, 2026
0.1.47 Apr 22, 2026
0.1.46 Mar 04, 2026
0.1.45 Feb 24, 2026
0.1.44 Feb 01, 2026
0.1.43 Jan 26, 2026
0.1.42 Nov 05, 2025
0.1.41 Oct 20, 2025
0.1.40 Oct 10, 2025
0.1.39 Oct 07, 2025
0.1.38 Sep 02, 2025
0.1.37 Aug 06, 2025
0.1.36 Jul 29, 2025
0.1.35 Jul 16, 2025
0.1.34 Jun 17, 2025
0.1.33 Jun 10, 2025
0.1.32 May 28, 2025
0.1.31 May 23, 2025
0.1.30 May 20, 2025
0.1.29 May 12, 2025
0.1.28 Apr 28, 2025
0.1.27 Apr 10, 2025
0.1.26 Mar 28, 2025
0.1.25 Mar 24, 2025
0.1.24 Mar 14, 2025
0.1.23 Feb 27, 2025
0.1.22 Feb 04, 2025
0.1.21 Jan 23, 2025
0.1.20 Dec 13, 2024
0.1.19 Dec 02, 2024
0.1.18 Sep 11, 2024
0.1.17 Sep 10, 2024
0.1.16 Sep 05, 2024
0.1.15 Aug 16, 2024
0.1.14 Aug 15, 2024
0.1.13 Aug 10, 2024
0.1.12 Aug 01, 2024
0.1.11 Jul 31, 2024
0.1.10 Jul 31, 2024
0.1.9 Jul 29, 2024
0.1.8 Jul 09, 2024
0.1.7 May 21, 2024
0.1.6 May 14, 2024
0.1.5 May 06, 2024
0.1.4 May 06, 2024
0.1.3 May 03, 2024
0.1.2 May 02, 2024
0.1.1 Mar 26, 2024
0.1.0 Mar 26, 2024
Extras:
Dependencies:
openinference-semantic-conventions (>=0.1.46)
opentelemetry-api
opentelemetry-sdk
wrapt (<3,>=1.14.0)