Skip to Content
Observability

Writer (tracing)

Writer  is an AI content platform with models for text, vision, translation, and knowledge graph workflows. Respan instruments Writer SDK calls and exports chat and text-generation spans for observability.

Set up Respan

Create an account at platform.respan.ai  and grab an API key .

Paste this into your coding agent:

Help me set up Respan tracing with the Writer integration. Follow https://www.respan.ai/docs/integrations/writer.md

Setup

Install packages

Terminal
pip install respan-ai respan-instrumentation-writer writerai

Set environment variables

Terminal
export RESPAN_API_KEY="YOUR_RESPAN_API_KEY" export WRITER_API_KEY="YOUR_WRITER_API_KEY"

Optional:

Terminal
export RESPAN_BASE_URL="https://api.respan.ai/api" export WRITER_MODEL="palmyra-x5"

Initialize and run

Python
import os from respan import Respan, workflow from respan_instrumentation_writer import WriterInstrumentor from writerai import Writer respan = Respan( api_key=os.environ["RESPAN_API_KEY"], base_url=os.getenv("RESPAN_BASE_URL", "https://api.respan.ai/api"), instrumentations=[WriterInstrumentor()], ) client = Writer(api_key=os.environ["WRITER_API_KEY"]) @workflow(name="writer_chat.workflow") def run_writer_chat() -> str: completion = client.chat.chat( model=os.getenv("WRITER_MODEL", "palmyra-x5"), messages=[{"role": "user", "content": "Write one line about tracing."}], max_tokens=64, ) return completion.choices[0].message.content print(run_writer_chat()) respan.shutdown()

View your trace

Open the Traces page  and search for workflow name writer_chat.workflow.

Configuration

ParameterTypeDefaultDescription
api_keystr | NoneNoneFalls back to RESPAN_API_KEY env var.
base_urlstr | NoneNoneFalls back to RESPAN_BASE_URL env var.
instrumentationslist[]Plugin instrumentations to activate, such as WriterInstrumentor() or new WriterInstrumentor().
sdkModuleobject | undefinedundefinedTypeScript only. Pass the imported writer-sdk module for runtimes that resolve multiple module instances.
customer_identifierstr | NoneNoneDefault customer identifier for all spans.
metadatadict | NoneNoneDefault metadata attached to all spans.
environmentstr | NoneNoneEnvironment tag, such as "production".

Supported calls

SDK callTraced
client.chat.chat(...)Chat completion spans, including streaming responses
client.chat.parse(...)Structured-output chat spans
client.chat.stream(...)Streaming chat spans after the stream is consumed
client.completions.create(...)Text completion spans, including streaming completions

Attributes

In Respan()

Python
from respan import Respan from respan_instrumentation_writer import WriterInstrumentor respan = Respan( instrumentations=[WriterInstrumentor()], customer_identifier="user_123", metadata={"service": "writer-api", "version": "1.0.0"}, )

With propagate_attributes

Python
import os from respan import Respan, propagate_attributes from respan_instrumentation_writer import WriterInstrumentor from writerai import Writer respan = Respan(instrumentations=[WriterInstrumentor()]) client = Writer(api_key=os.environ.get("WRITER_API_KEY", "local-mock-token")) def run_writer_with_attributes(user_id: str): with propagate_attributes( customer_identifier=user_id, session_identifier="writer_thread", metadata={"plan": "enterprise"}, ): completion = client.chat.chat( model=os.getenv("WRITER_MODEL", "palmyra-x5"), messages=[{"role": "user", "content": "Write one sentence for trace demos."}], max_tokens=32, ) print(completion.choices[0].message.content)
AttributeTypeDescription
customer_identifierstrIdentifies the end user in Respan analytics.
session_identifierstrGroups related messages into a conversation.
metadatadictCustom key-value pairs. Merged with default metadata.