Skip to main content

Respan Dify instrumentation

Trace the official dify-client Python package with Respan.

Requires Python 3.11 through 3.13 and dify-client>=0.1.10,<0.2.0.

This package patches Dify's Service API client methods and emits canonical Respan spans for chat, completion, workflow, file, feedback, application, and conversation requests. Streaming responses are traced when the returned stream is consumed, closed early, or raises. It supports the released sync-only dify-client 0.1.10 package and the refreshed 0.1.12 source API, including its sync and async Chat, Completion, Workflow, Knowledge Base, and Workspace clients. Current-source extended async clients share the same request boundary. Source coverage is pinned to langgenius/dify-python-sdk revision a3ce501021906e23535c268f0b60fea3864864a6 (version 0.1.12); this is not a PyPI release. Published SDK validation uses 0.1.10.

Install

pip install respan-ai respan-instrumentation-dify dify-client

Usage

import os

from dify_client import ChatClient
from respan import Respan
from respan_instrumentation_dify import DifyInstrumentor

respan = Respan(
    api_key=os.environ["RESPAN_API_KEY"],
    instrumentations=[DifyInstrumentor()],
)

client = ChatClient(os.environ["DIFY_CHAT_API_KEY"])
response = client.create_chat_message(
    inputs={},
    query="Reply with one concise sentence about tracing.",
    user="respan-example-user",
    response_mode="blocking",
)
response.raise_for_status()
print(response.json()["answer"])

respan.flush()
respan.shutdown()

Async clients

When the installed Dify SDK exposes its async clients, the same instrumentor patches them automatically:

from dify_client import AsyncChatClient

async with AsyncChatClient(
    os.environ["DIFY_CHAT_API_KEY"],
    base_url=os.getenv("DIFY_BASE_URL", "https://api.dify.ai/v1"),
) as client:
    response = await client.create_chat_message(
        inputs={},
        query="Stream one concise sentence about tracing.",
        user="respan-example-user",
        response_mode="streaming",
    )
    async for line in response.aiter_lines():
        print(line)

The span stays open until a streaming response is exhausted, explicitly closed, leaves its context manager, or fails. Blocking responses emit when the SDK request resolves. include_content=False keeps request/response bodies and prompt/completion content off spans while retaining operation, status, and usage attributes. Credential-like fields are always recursively redacted, including Workspace credential-validation requests and echoed responses. When multiple instrumentor instances overlap, the first active instance's content policy remains in effect until the last instance is deactivated; conflicting instances log a warning instead of changing it. Deactivation restores only wrappers still owned by this instrumentor, so a later patch from another library is left intact.

Use Respan.propagate_attributes(...) to attach customer, thread, trace group, metadata, or prompt context to Dify spans.

Content policy also honors TRACELOOP_TRACE_CONTENT and the runtime context flag. Streams retain the policy captured when the request starts. Model and provider-reported usage stay available with content disabled. Dify SSE error events, failed workflow results, and async cancellation set ERROR status; returned SDK responses and cancellation behavior are preserved.

Metadata

Release files for respan-instrumentation-dify 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for respan-instrumentation-dify 0.2.0
File Size Uploaded
respan_instrumentation_dify-0.2.0.tar.gz 14.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for respan-instrumentation-dify 0.2.0
File Interpreter ABI Platform
respan_instrumentation_dify-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 30.8 kB

Release files / respan_instrumentation_dify-0.2.0.tar.gz

Download URL respan_instrumentation_dify-0.2.0.tar.gz
Size 14.6 kB
Tags Source
SHA-256 checksum
How to use checksums
1e96252d60f520f7a74a05feb119da0c5ecde2c94a952014147ec0815c00950b
BLAKE2b-256 checksum
How to use checksums
a67131997930b0f7b5813b4aa5e56b0a31dff6c0bb15e76e9ac13db6b6c27017
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Release files / respan_instrumentation_dify-0.2.0-py3-none-any.whl

Download URL respan_instrumentation_dify-0.2.0-py3-none-any.whl
Size 16.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fd14a6b7a1b585fb2168e4634f2f810095017af9e69296ce902e63b70099ec3e
BLAKE2b-256 checksum
How to use checksums
e075c536ab3184ac609b6a08884123237847cf2c61d7dcfefa6b2a37e665290a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page