Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,7 @@
"langsmith/setup-app-requirements-txt",
"langsmith/setup-pyproject",
"langsmith/setup-javascript",
"langsmith/setup-java",
"langsmith/monorepo-support"
]
},
Expand Down
57 changes: 57 additions & 0 deletions src/langsmith/add-metadata-tags.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,61 @@ import { wrapOpenAI } from "langsmith/wrappers";
await traceableCallOpenAI(messages);
```

```java Java
import com.langchain.smith.wrappers.openai.OpenTelemetryConfig;
import com.langchain.smith.wrappers.openai.WrappedOpenAIClient;
import com.openai.models.ChatModel;
import com.openai.models.chat.completions.ChatCompletion;
import com.openai.models.chat.completions.ChatCompletionCreateParams;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Scope;

public class MetadataTagsExample {
public static void main(String[] args) {
// Configure OpenTelemetry
OpenTelemetryConfig.builder()
.fromEnv()
.build();

// Get tracer
Tracer tracer = GlobalOpenTelemetry.get().getTracer("my-app");
WrappedOpenAIClient client = WrappedOpenAIClient.fromEnv();

// Create a span with metadata and tags
Span span = tracer.spanBuilder("openai_call")
.setAttribute("langsmith.span.kind", "llm")
// Add metadata as span attributes
.setAttribute("my-key", "my-value")
.setAttribute("environment", "production")
// Add tags as a comma-separated string
.setAttribute("langsmith.tags", "my-tag,another-tag")
.startSpan();

try (Scope scope = span.makeCurrent()) {
ChatCompletion completion = client.chat().completions().create(
ChatCompletionCreateParams.builder()
.model(ChatModel.GPT_4O_MINI)
.addSystemMessage("You are a helpful assistant.")
.addUserMessage("Hello!")
.build()
);

// Add dynamic metadata during execution
span.setAttribute("response-length",
completion.choices().get(0).message().content().orElse("").length());
span.setAttribute("user-id", "user-123");

System.out.println(completion.choices().get(0).message().content().orElse(""));
} finally {
span.end();
}

client.close();
OpenTelemetryConfig.flush(5, java.util.concurrent.TimeUnit.SECONDS);
}
}
```

</CodeGroup>
34 changes: 34 additions & 0 deletions src/langsmith/attach-user-feedback.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,40 @@ await client.createFeedback(
);
```

```java Java
import com.langchain.smith.client.LangsmithClient;
import com.langchain.smith.client.okhttp.LangsmithOkHttpClient;
import com.langchain.smith.models.feedback.FeedbackCreate;
import java.util.UUID;

public class FeedbackExample {
public static void main(String[] args) {
LangsmithClient client = LangsmithOkHttpClient.fromEnv();

// ... Run your application and get the run_id...
UUID runId = UUID.fromString("your-run-id-here");

// Provide feedback for a trace or run
client.feedback().create(FeedbackCreate.builder()
.runId(runId)
.key("user_feedback")
.score(1.0)
.comment("the user said that ...")
.build());

// Provide feedback with additional metadata
client.feedback().create(FeedbackCreate.builder()
.runId(runId)
.key("correctness")
.score(0.0)
.comment("This step needs improvement")
.build());

System.out.println("Feedback logged successfully");
}
}
```

</CodeGroup>

You can even log feedback for in-progress runs using `create_feedback() / createFeedback()`. See [this guide](/langsmith/access-current-span) for how to get the run ID of an in-progress run.
Expand Down
Loading