Install & Compatibility
Where this runs
tested against v0.7.61 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.915 runs
installs and imports cleanly · install 0.0s · import 2.015s · 73.8MB
glibcpy 3.10–3.915 runs
installs and imports cleanly · install 13.5s · import 1.518s · 70MB
70MB installed
● package 70MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Laminar
✓ from lmnr import Laminar
observe
✓ from lmnr import observe
wrap_llm_call
✓ from lmnr import wrap_llm_call
lmnr_context
✓ from lmnr import lmnr_context
This quickstart demonstrates how to initialize Laminar, instrument the OpenAI SDK, and trace an LLM call using the `@observe` decorator. It expects `LMNR_PROJECT_API_KEY` and `OPENAI_API_KEY` to be set in environment variables.
import os
import openai
from lmnr import Laminar, observe
# It's recommended to install with pip install -U 'lmnr[all]' openai python-dotenv
# Initialize Laminar. project_api_key will be read from LMNR_PROJECT_API_KEY environment
# variable if not explicitly passed.
Laminar.initialize(
project_api_key=os.environ.get('LMNR_PROJECT_API_KEY', ''),
# Instrument the OpenAI module for automatic tracing of API calls.
instrumentModules={
"OpenAI": openai
}
)
# Initialize OpenAI client *after* Laminar has instrumented the module.
# The OpenAI API key will be read from OPENAI_API_KEY environment variable.
client = openai.OpenAI(api_key=os.environ.get('OPENAI_API_KEY', ''))
@observe(name="poem_generator")
def generate_poem(topic: str) -> str:
"""Generates a short poem using OpenAI and traces the call with Laminar."""
print(f"Calling OpenAI to generate a poem about: {topic}")
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "user", "content": f"Write a short poem about {topic}"},
],
)
return response.choices[0].message.content
if __name__ == "__main__":
# Ensure LMNR_PROJECT_API_KEY and OPENAI_API_KEY are set in your environment
# or a .env file loaded with python-dotenv.
if not os.environ.get('LMNR_PROJECT_API_KEY') or not os.environ.get('OPENAI_API_KEY'):
print("Please set LMNR_PROJECT_API_KEY and OPENAI_API_KEY environment variables.")
print("You can get LMNR_PROJECT_API_KEY from your Laminar dashboard.")
exit(1)
print("Generating a poem with Laminar tracing enabled...")
try:
poem = generate_poem("a starry night")
print("\nGenerated Poem:")
print(poem)
print("\nCheck your Laminar dashboard for the trace of this operation!")
except Exception as e:
print(f"An error occurred: {e}")
print("Ensure your API keys are correct and you have network connectivity.")
lmnr --version
Errors
Common errors & fixes
Error initializing MistralAI instrumentor
This error occurs when the MistralAI instrumentor encounters a problem during initialization, often due to an outdated or incompatible version of the `lmnr` library or its specific instrumentor package, or when multiple instrumentation packages conflict.
fixUpdate the `lmnr` library to the latest version (`pip install --upgrade lmnr`) and ensure that only the necessary instrumentor packages are installed. If `lmnr[all]` was installed, consider removing it and installing only the specific instrumentors you need (e.g., `pip install lmnr[openai]`).
SSL Certificate Verification Error
This error, often accompanied by `StatusCode.UNAVAILABLE` for GRPC connections, indicates a problem with SSL certificate verification. This can be due to an incomplete or incorrect certificate chain, or the client not being configured to accept the server's certificate.
fixEnsure that the SSL certificate chain is correctly configured and that the client is set up to trust the server's certificate. For self-hosted environments, verify that `base_url`, `http_port`, and `grpc_port` are correctly specified during `Laminar.initialize()`.
AttributeError: 'Thread' object has no attribute '_otel_context'
This `AttributeError` suggests a conflict or issue with how OpenTelemetry's context management interacts with Python's threading, particularly within the `lmnr` library's instrumentation.
fixThis issue was addressed in a fix related to threading instrumentor in the `lmnr-python` repository. Updating `lmnr` to the latest version should resolve this problem.
ModuleNotFoundError: No module named 'lmnr'
This common error indicates that the `lmnr` package is not installed in the Python environment being used, or the Python interpreter cannot find the installed package due to a misconfigured `PYTHONPATH` or virtual environment.
fixInstall the `lmnr` library using pip: `pip install lmnr`. If you need specific instrumentations, install them with `pip install lmnr[openai]`, `pip install lmnr[langchain]`, etc. Ensure you are running your code in the same Python environment where `lmnr` was installed.
Laminar.initialize() must be called once in your application
The `Laminar.initialize()` method is designed to be called only once early in the application's lifecycle to set up observability. Calling it multiple times can lead to unexpected behavior or resource conflicts.
fixEnsure that `Laminar.initialize()` is called a single time at the very beginning of your application's startup code, before any LLM or instrumented calls are made. It should ideally be placed in the main entry point of your application or a dedicated configuration file.
Upgrade
Version history
0.7.61latest on PyPI · released Aug 27, 2026
Audit
Dependencies
openaioptionalOptional, for OpenAI API instrumentation.
anthropicoptionalOptional, for Anthropic API instrumentation.
python-dotenvoptionalOptional, for loading API keys from .env files.