OpenAI Integration
Updated on Aug 14, 2026
Use this integration when your app is implemented in Python, TypeScript, or .NET.
Setup
- Install SDK
bash
pip install progress-observability
- Instrument your app
python
Observability.instrument(
app_name=os.getenv("OBSERVABILITY_APP_NAME"),
api_key=os.getenv("OBSERVABILITY_API_KEY")
)
- Complete example
python
import os
from dotenv import load_dotenv
from openai import OpenAI
from progress.observability import Observability
load_dotenv()
# LLM INSTRUMENTATION
Observability.instrument(
app_name=os.getenv("OBSERVABILITY_APP_NAME"),
api_key=os.getenv("OBSERVABILITY_API_KEY"),
)
def main() -> None:
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
model = os.getenv("OPENAI_MODEL", "gpt-4o-mini")
response = client.chat.completions.create(
model=model,
max_tokens=256,
messages=[
{"role": "system", "content": "You are a helpful AI assistant."},
{"role": "user", "content": "What is the capital of France?"},
],
)
try:
main()
finally:
Observability.shutdown()
To get a richer trace tree when building agents on top of this provider, use the
@agent,@tool,@workflow, or@taskdecorators. See the Python SDK for details.
- Install SDK
bash
npm install @progress/observability
- Instrument your app
TS
import '@progress/observability/register/hooks';
import { Observability } from '@progress/observability';
await Observability.instrument({
appName: process.env.OBSERVABILITY_APP_NAME ?? 'my-openai-app',
apiKey: process.env.OBSERVABILITY_API_KEY
});
- Complete example
TS
import '@progress/observability/register/hooks';
import 'dotenv/config';
import { Observability } from '@progress/observability';
await Observability.instrument({
appName: process.env.OBSERVABILITY_APP_NAME ?? 'my-openai-app',
apiKey: process.env.OBSERVABILITY_API_KEY,
});
try {
// Import the OpenAI SDK only after instrument(), so it gets patched.
const { default: OpenAI } = await import('openai');
const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const completion = await client.chat.completions.create({
model: process.env.OPENAI_MODEL ?? 'gpt-4o-mini',
max_tokens: 256,
messages: [
{ role: 'system', content: 'You are a helpful AI assistant.' },
{ role: 'user', content: 'What is the capital of France?' },
],
});
} finally {
await Observability.shutdown();
}
To get a richer trace tree when building agents on top of this provider, use the
@agent,@tool,@workflow, or@taskdecorators. See the TypeScript SDK for details.
- Install SDK
bash
dotnet add package Progress.Observability.Instrumentation
- Instrument your app
cs
try
{
chatClient = chatClient.AddObservability((options) =>
{
options.AppName = Environment.GetEnvironmentVariable("OBSERVABILITY_APP_NAME")!;
options.ApiKey = Environment.GetEnvironmentVariable("OBSERVABILITY_API_KEY")!;
});
// Your code here.
}
finally
{
// Call the Shutdown() method before exiting your agent to flush any remaining data.
ObservabilityTracer.Shutdown();
}
- Complete example
cs
using Microsoft.Extensions.AI;
using OpenAI;
using Progress.Observability.Extensions.AI;
using DotNetEnv;
namespace Examples.OpenAI;
public class Program
{
public static async Task Main(string[] args)
{
try
{
Env.Load(".env");
IChatClient chatClient = new OpenAIClient(
Environment.GetEnvironmentVariable("OPENAI_API_KEY")!)
.GetChatClient("gpt-4o-mini")
.AsIChatClient()
.AddObservability((options) =>
{
options.AppName = "OpenAI Example";
options.ApiKey = Environment.GetEnvironmentVariable("OBSERVABILITY_API_KEY")!;
});
var response = await chatClient.GetResponseAsync(
"What is the capital of France?");
Console.WriteLine(response.Text);
}
finally
{
ObservabilityTracer.Shutdown();
}
}
}
To get a richer trace tree when building agents on top of this provider, use custom spans. See the .NET SDK for details.