feat(llmobs): auto-tag git commit and repository URL on traces and ex…#17939
Open
feat(llmobs): auto-tag git commit and repository URL on traces and ex…#17939
Conversation
…periments Reuses ddtrace.internal.gitmetadata.get_git_tags() so LLM Observability spans and Experiment._tags pick up git.commit.sha and git.repository_url from the existing DD_GIT_* env vars or the main package's Project-URL metadata, gated by DD_TRACE_GIT_METADATA_ENABLED. User-supplied experiment tags with the same keys take precedence. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codeowners resolved as |
This comment has been minimized.
This comment has been minimized.
Adds an experiment-only fallback in _resolve_experiment_git_metadata that shells out to `git rev-parse HEAD` / `git ls-remote --get-url` when the standard gitmetadata source (DD_GIT_* env vars / package Project-URL) is empty. Cached for the process lifetime; URL is scrubbed via _filter_sensitive_info. Prod LLM Obs span tagging is unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Test the resolver _resolve_experiment_git_metadata directly instead of through Experiment(...) for fallback scenarios; parametrize the three gitmetadata-vs-fallback combinations; mock the resolver in the two Experiment integration tests so they no longer reach down into gitmetadata + extract_*. Same coverage, ~50 fewer lines. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
gsvigruha
commented
May 7, 2026
| not repeatedly invoke ``git``. | ||
| """ | ||
| global _GIT_FALLBACK_CACHE | ||
| repository_url, commit_sha, _ = gitmetadata.get_git_tags() |
Contributor
Author
There was a problem hiding this comment.
this is not sufficient in a typical dev env
Yun-Kim
reviewed
May 8, 2026
| cached for the process lifetime so repeated experiment construction does | ||
| not repeatedly invoke ``git``. | ||
| """ | ||
| global _GIT_FALLBACK_CACHE |
Contributor
There was a problem hiding this comment.
Why are we reading/modifying a global scope cache variable for every experiment init? Why don't we just modify gitmetadata.get_git_tags() to include this subprocess fallback?
| if _GIT_FALLBACK_CACHE is None: | ||
| fallback_url, fallback_sha = "", "" | ||
| try: | ||
| fallback_sha = git.extract_commit_sha() |
Contributor
There was a problem hiding this comment.
If DD_TRACE_GIT_METADATA_ENABLED=false, won't this still default to the git cli fallback and tag experiments anyway even though the user explicitly disabled git metadata tagging? Is this intentional
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Auto detect git variables and add as tags.
Testing
Risks
Performance: both mechanisms are computing the git vars once and caching it for the lifetime of the process so should not be an issue