Use this file to discover all available pages before exploring further.
Identify your users, track their cost, conversations and more.The strict minimum to enable user tracking is to report a userId, however you can report any property you’d like such as an email or name using an userProps object.
If you’re using LangChain, you can similarly pass user data as metadata.
Javascript
Python
const chat = new ChatOpenAI({ callbacks: [new LunaryHandler()],});const res = await chat.call([new HumanMessage("Hello!")], {metadata: {userId: "123",userProps: { name: "John" },},});
handler = LunaryCallbackHandler()chat = ChatOpenAI( callbacks=[handler], metadata={ "user_id": "user123" }, # Assigning user ids to models in the metadata)
When tracking traces, you can inject user data into the context using the identify methods. This will cascade down to all the child runs.
Javascript
Python
async function TranslatorAgent(input) { // Some AI queries // Everything done in this context will be tracked with the user}// Wrap the agent with the monitorconst translate = lunary.wrapAgent(TranslatorAgent)// Using identify to inject the user into the contextconst res = await translate(`Hello, what's your name?`).identify("user123", { email: "email@example.org" })
import lunarydef my_agent(): # Some AI queries # Everything done in this context will be tracked with the userdef main(): # Using identify to inject the user into the context with lunary.identify('user123', user_props={"email": "email@example.org"}): my_agent()