Skip to content

feat: add tag filtering to traces command#27

Open
Harry Nguyen (Hazzng) wants to merge 2 commits into
langchain-ai:mainfrom
Hazzng:feature/fetch-tags
Open

feat: add tag filtering to traces command#27
Harry Nguyen (Hazzng) wants to merge 2 commits into
langchain-ai:mainfrom
Hazzng:feature/fetch-tags

Conversation

@Hazzng
Copy link
Copy Markdown

@Hazzng Harry Nguyen (Hazzng) commented Dec 29, 2025

feat(tags): add tag-based trace filtering to traces command

Summary

Add the ability to filter traces by tag(s) using --tag/-t option on the traces command. This enables users to fetch traces that have been tagged in LangSmith, . Add the output handling for fetching traces so if message is [] then fetch all output to be compatible with more agent outputs (not all agents just output messages)

Problem

Users needed a way to fetch traces by their tags from LangSmith. The existing traces command only supported time-based filtering (--last-n-minutes, --since) but had no way to filter by tags assigned to traces.

Solution

Extended the traces command with:

  • --tag/-t TAG option (can be repeated for multiple tags)
  • New fetch_traces_by_tags() fetcher function
  • Fallback to return full outputs dict for custom agents without standard message format

Changes

File Description
src/langsmith_cli/fetchers.py Added fetch_traces_by_tags() function (+147 lines); Fixed message extraction to fall back to full outputs for custom agents
src/langsmith_cli/cli.py Added --tag options; Added tag filtering logic for both directory and stdout modes
tests/test_fetchers.py Added TestFetchTracesByTags class with 6 unit tests
tests/test_cli.py Added TestTracesCommandTagOption class with 5 CLI tests
tests/conftest.py Added tag-related test constants and fixtures
README.md Added tag filtering documentation and examples

Usage Examples

# Fetch traces with a single tag
langsmith-fetch traces --tag production --limit 10

# Fetch traces with multiple tags (OR logic - any tag matches)
langsmith-fetch traces --tag prod,staging --limit 10

# Combine with existing options
langsmith-fetch traces --tag production --last-n-minutes 60 --project-uuid <uuid>

Testing

  • All 86 tests pass (uv run pytest tests/ -v)
  • Manual testing with real LangSmith API (tag: 20251225_023631)
  • Verified custom agent outputs are returned correctly

Breaking Changes

None - this is a purely additive feature.

- Introduced `--tag` option for filtering traces by specified tags, supporting both OR and AND logic with `--all-tags`.
- Updated README with usage examples for tag filtering.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant