Get your API key
Create an API key in the Weflayr Dashboard. Either expose it as the
WEFLAYR_API_KEY environment variable, or pass it directly to autoInstrument() in the next step..env
Install and instrument
Choose your AI provider SDK you are using & follow the install commands. Then run the auto instrumentation command as shown.
PS: This works regardless of the Framework you are using (Langchain, Mastra, etc…)
Each value picks the matching OpenTelemetry instrumentation package to load. Install the package separately.
- Anthropic
- OpenAI
- AWS Bedrock
- Google GenAI
- Other
Install:Instrument:
All parameters for autoInstrument() / auto_instrument()
All parameters for autoInstrument() / auto_instrument()
string, enum member, or a list of them
required
- Node.js
- Python
'openai', 'anthropic', 'bedrock', 'cohere', 'google-genai', 'elevenlabs', or an array of them.string
Defaults to the
WEFLAYR_API_KEY environment variable. Pass explicitly to override.object
Tags stamped on every emitted span.
"batch" | "immediate"
default:"\"batch\""
Use
"immediate" to export telemetry after every call.boolean
default:"true"
Set
false to strip gen_ai.prompt / gen_ai.completion from spans before export.function
Redact or rewrite fields before they leave your process. See the mask example below.
boolean
default:"true"
Set
false to silence the one-shot stderr warning emitted on the first export failure.Mask example
Usemask to redact PII (emails, credit cards, customer names) or to drop entire prompts before they’re sent to Weflayr. Your callback runs on a copy of the span attributes right before export; whatever you return is what we store. Return null to drop the span entirely.Add metadata to your LLM calls for finer analysis
Wrap your LLM calls in As a callback / context managerWrap a single block of code. Every LLM call made inside picks up the metadata.As a decoratorApply once to a function or method, and every call automatically picks up the metadata.
propagateMetadata / propagate_metadata to stamp each emitted span with who the call is for (customer_name) and why it’s happening (feature_name). Anything inside the scope, including nested calls, picks up the same metadata.Tagging
feature_name and customer_name unlock per-customer and per-feature breakdowns across the dashboard, for analysis (e.g. margin) and for benchmarking (e.g. model benchmark).All parameters for propagateMetadata() / propagate_metadata()
All parameters for propagateMetadata() / propagate_metadata()
string
required
The product-side feature triggering the LLM call (e.g.
"support-chat", "onboarding-summary").string
required
Name of the end-user or tenant customer the call is made for.
enum member
Override the auto-detected provider. Use this when the SDK on the wire differs from the provider to bill (e.g. Mistral or the Vercel AI Gateway reached through the OpenAI SDK).
object
Any scalar key/value pairs (string / number / boolean) that you may need to analyse your costs in more detail.
Flush before exit (short-lived runtimes only)
In long-running servers, spans are flushed automatically. In short-lived runtimes (Lambda, scripts, edge functions), call
flush() before exit so the final spans reach Weflayr.Observe your margin and optimise your AI costs
Your calls now stream to the dashboard and can be optimised: see the platform documentation
Implementation examples
Multiple AI providers
A single app that calls both OpenAI and Anthropic.
AI Framework
Every call your framework’s chain makes, captured.