Sometimes you have some context prior to running a function and you want to label it at creation time. For example, you may want to tag a span with the model provider endpoint that you use, or the test dataset that you used to run the request.

Note that labels are not the same as metadata. Metadata is additional information about a trace in a form of key-value pairs. Labels are used to categorize and filter spans, and they must be created in the Laminar UI in advance. See metadata for a more detailed comparison.

Label spans from code

This functionality is available from v0.5.0.

Example 1. Labeling a span created with automatic instrumentation

from lmnr import Laminar

with Laminar.with_labels(["my_label", "another_label"]):
    openai_client.chat.completions.create(...)

Note that any spans created within the with_labels block will inherit the labels, including auto-instrumented spans or any calls to observed functions.

Example 2. Labeling a span created manually

with Laminar.start_as_current_span(name="foo", labels=["my_label", "another_label"]):
    # your code here
    pass

Note that only the span created by this Laminar.start_as_current_span call will have the labels.

Every label must have a string key and a string value. They must exactly match the name and possible values of the label class.

3. Viewing labels

The labels will be visible in the Laminar UI, shown on each span as shields.