OpenTelemetry instrumentation for Microsoft Prompt flow
(promptflow-tracing, promptflow-core; import promptflow).
pip install traceAI-promptflowfrom fi_instrumentation import register
from traceai_promptflow import PromptflowInstrumentor
PromptflowInstrumentor().instrument(tracer_provider=register(project_name="my-project"))
# then run flows or call @trace functions as usualWith fi-instrumentation-otel auto-instrumentation the promptflow integration is enabled when
promptflow.tracing is imported (a promptflow-core / promptflow-tracing install is enough).
LLM spans come from Prompt flow's own OpenAI integration, which Prompt flow switches on with
start_trace() (or promptflow.tracing._integrations._openai_injector.inject_openai_api()). Without
it, only your @trace functions, nodes and flow runs are spans; calls to the OpenAI SDK are not.
Prompt flow ships with tracing off (PF_DISABLE_TRACING defaults to true). instrument() turns
it on unless the variable is already set, and uninstrument() puts it back. Setting
PF_DISABLE_TRACING=true yourself keeps Prompt flow tracing disabled.
Prompt flow already opens a span for each @trace function, DAG node or tool and flow run (flex
and DAG). This instrumentor routes those spans through traceAI instead of the global tracer
provider:
- the flow run, or an outermost
@tracefunction, is aCHAINspan; nodes and nested@tracefunctions are childTOOLspans (gen_ai.tool.nameis the function name). Calls made through Prompt flow's OpenAI integration areLLMspans with the response model and token usage; embedding vectors are never exported.gen_ai.provider.nameispromptflowon every span; - sync, async and generator results; a generator span ends on exhaustion, error,
close()or when the generator is dropped. An early end is markedpromptflow.stream.incomplete; - errors are re-raised unchanged and recorded as
ERRORwitherror.type(the class name); the message and traceback are never exported; - inputs and outputs are exported as
input.value/output.valueand follow theTraceConfighide settings. Prompt flow's owninputs,output,prompt.template,prompt.variablesandpromptflow.*events are never exported, whichever Prompt flow code path writes them (for example a Prompty call): the span drops them, so hiding works for them too. If an installed Prompt flow version lacks a content hook this package patches, one warning is logged and the content stays masked; if it lacksstart_as_current_span, nothing is instrumented; - LLM and embedding spans carry
gen_ai.request.modeland the request parameters (temperature, top_p, max tokens, penalties, seed, stop) when the call's inputs include them; - a failure inside the instrumentation never reaches your call.
PF_DISABLE_TRACING=false is set process-wide, so child processes inherit it, but the patches are
not: a worker process has to call instrument() itself.
Limits: the patches live in the instrumenting process. Prompt flow batch runs that execute lines in
worker processes, and the serving /feedback endpoint (which opens its own span on the global
tracer provider), are not covered, so their spans do not follow the TraceConfig hide rules.
Do not also instrument the OpenAI SDK for the calls Prompt flow already traces: you would get a second LLM span for each.
Supported SDK range: promptflow-tracing >= 1.12.0, < 2.