Using Writer with OpenLLMetry - Writer AI Studio
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
This guide shows you how to integrate Writer with OpenLLMetry for monitoring and debugging your LLM applications. After completing these steps, you can trace and observe your Writer API calls alongside other LLM operations in your observability stack.
What is OpenLLMetry?
OpenLLMetry is an open source project that enables monitoring and debugging of LLM application execution. It provides non-intrusive tracing built on top of OpenTelemetry, allowing you to export traces to your existing observability stack. Since it’s built on OpenTelemetry, you can use any OpenTelemetry compatible backend (Jaeger, Zipkin, Datadog, New Relic, etc.) or the hosted Traceloop platform.
What you get with the Writer integration
The Writer integration with OpenLLMetry provides enhanced observability beyond standard OpenTelemetry traces. You’ll see detailed information about your Writer API calls as additional span attributes:
gen_ai.request.model: the model requested (for example,palmyra-x5)gen_ai.prompt: array of prompts sent to the Writer modelgen_ai.completion: array of completions returned from Writergen_ai.usage.total_tokens: total tokens usedgen_ai.usage.prompt_tokens: number of tokens used for promptsgen_ai.usage.completion_tokens: number of tokens used for completions
This gives you comprehensive visibility into your Writer API usage, including prompt engineering insights, token consumption patterns, and performance characteristics that aren’t available in standard OpenTelemetry traces.
For a complete list of supported attributes, see the full GenAI Semantic Conventions.
Prerequisites
Before you begin, make sure you have:
- Python 3.11 or higher installed
- A Writer AI Studio account
- A Traceloop account
- A Writer API key. See instructions in the API Quickstart
- Basic familiarity with Python and OpenLLMetry concepts
The example below uses Traceloop as the observability provider. See the connect to an external provider section to learn how to connect to other providers.
Configuration details
| Environment Variable | Required | Default | Description |
|---|---|---|---|
WRITER_API_KEY |
Required | None | Writer API key for authenticating API calls. Must be set for the application to function. |
TRACELOOP_API_KEY |
Conditional | None | Required for Traceloop Cloud: Create an API key in your Traceloop dashboard and set this environment variable. Optional for external providers: When connecting to other observability platforms (Datadog, New Relic, etc.), omit this variable and use TRACELOOP_HEADERS instead. |
TRACELOOP_BASE_URL |
Optional | https://api.traceloop.com |
OpenTelemetry endpoint to connect to. If prefixed with http/https, uses OTLP/HTTP protocol; otherwise uses OTLP/GRPC. The SDK appends /v1/traces. |
TRACELOOP_HEADERS |
Optional | None | Custom HTTP headers for authentication. If set, API key is ignored. |
TRACELOOP_TRACE_CONTENT |
Optional | true |
Enable/disable logging of prompts, completions, and embeddings to span attributes. |
TRACELOOP_TELEMETRY |
Optional | true |
Enable/disable anonymous telemetry data collection. |
For additional configuration option details, see the SDK initialization docs.
Integrate Writer with OpenLLMetry
1. Install the SDK
Install OpenLLMetry in your Python environment:
pip install traceloop-sdk
2. Initialize and configure
In your Writer application, initialize the Traceloop tracer. For local development, you may want to disable batch sending to see traces immediately.
import os
from traceloop.sdk import Traceloop
from writerai import Writer
# Initialize Traceloop for Writer monitoring
Traceloop.init(
app_name="YOUR_APP_NAME",
api_key=os.environ.get("TRACELOOP_API_KEY"),
# disable_batch=True # For local development, this disables batch sending so you can see Writer API traces immediately
)
# Initialize Writer client
client = Writer(api_key=os.environ.get("WRITER_API_KEY"))
3. (Optional) annotate your workflows
Workflow annotations help organize and group related operations for better trace visualization and debugging. When to use decorators:
- Complex processes: Group related API calls and business logic into logical workflows
- Custom naming: Override automatic span naming with business-context names
- Hierarchical tracing: Create parent-child relationships between workflows and tasks
Available decorators:
| Decorator | Purpose | Use case |
|---|---|---|
@workflow |
Multi-step processes or “chains” | Complete business workflows that can be traced as a single unit |
@task |
Individual operations within workflows | Specific actions or computations within a workflow |
@agent |
Autonomous agents | AI agents that can make decisions and use tools |
@tool |
Agent tools | Functions that agents can call to perform specific actions |
Workflow annotations are optional. OpenLLMetry traces Writer API calls automatically without needing any decorators or additional code.
from traceloop.sdk.decorators import workflow, task, agent, tool
# Workflow and task example
@workflow(name="content_creation")
def content_creation_pipeline(topic: str):
research = research_topic(topic)
content = generate_content(research)
return content
@task(name="research_topic")
def research_topic(topic: str):
completion = client.chat.completions.create(
model="palmyra-x5",
messages=[{"role": "user", "content": f"Provide a comprehensive overview of {topic}, including key concepts, benefits, and current trends."}],
max_tokens=300
)
return completion.choices[0].message.content
@task(name="generate_content")
def generate_content(research: str):
completion = client.chat.completions.create(
model="palmyra-x5",
messages=[{"role": "user", "content": f"Write an engaging article based on this research: {research}"}],
max_tokens=500
)
return completion.choices[0].message.content
# Agent and tool example
@agent(name="content_agent")
def content_agent(request: str):
return research_tool(request)
@tool(name="research_tool")
def research_tool(query: str):
completion = client.chat.completions.create(
model="palmyra-x5",
messages=[{"role": "user", "content": f"Find detailed information about {query} and provide key insights and data points."}],
max_tokens=300
)
return completion.choices[0].message.content
Connect to external providers
Because the Traceloop SDK is built on OpenTelemetry, the data it generates can be used in any observability platform that supports the OpenTelemetry standard. OpenLLMetry extends this by using the OTLP protocol to connect with external observability providers, letting you send traces directly to your existing stack without relying on Traceloop’s hosted platform.
Configure external provider connection
To connect to an external provider, configure the following environment variables:
| Environment Variable | Description |
|---|---|
TRACELOOP_BASE_URL |
The OTLP endpoint URL for your observability provider |
TRACELOOP_HEADERS |
Authentication headers (if required by your provider) |
Example configurations
Grafana Cloud
# Generate base64 encoded credentials
echo -n "<your stack id>:<your api key>" | base64
# Set environment variables
export TRACELOOP_BASE_URL=https://otlp-gateway-<zone>.grafana.net/otlp
export TRACELOOP_HEADERS="Authorization=Basic%20<base64 encoded stack id and api key>"
Datadog
# Connect to your Datadog Agent (requires OTLP HTTP collector enabled)
export TRACELOOP_BASE_URL="http://<datadog-agent-hostname>:4318"
New Relic
export TRACELOOP_BASE_URL=https://otlp.nr-data.net:443
export TRACELOOP_HEADERS="api-key=<YOUR_NEWRELIC_LICENSE_KEY>"
For a complete list of supported integrations, see the full OpenLLMetry integrations catalog.
Next steps
Now that you’ve set up Writer with OpenLLMetry, you can start monitoring your LLM applications. See the following resources to help you get the most out of your integration:
- Explore OpenLLMetry’s advanced features for more detailed tracing capabilities
- Learn about workflow annotations to better organize your traces
- Set up custom integrations with your existing observability stack
- Review the Writer OpenLLMetry integration for additional details and examples