Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot incorporate VCS root_path #813

Open
fwinokur opened this issue Jan 21, 2025 · 6 comments
Open

Cannot incorporate VCS root_path #813

fwinokur opened this issue Jan 21, 2025 · 6 comments
Assignees

Comments

@fwinokur
Copy link

fwinokur commented Jan 21, 2025

I am struggling to get the root_path component of my VCS configuration to work. I've tried configuring via logfire.CodeSource() as well as setting the OTEL_RESOURCE_ATTRIBUTES environment variable (not at the same time).

My current configuration is as follows -

logfire.configure(
    environment=os.environ["ENVIRONMENT"],
    code_source=logfire.CodeSource(
        repository=os.environ["LOGFIRE_REPOSITORY"],
        revision=os.environ["LOGFIRE_REVISION"],
        root_path=os.environ["LOGFIRE_ROOT_PATH"],
    ),
)

The root directory of my code is in a subdirectory mounted in my Docker container at - /repository_root_path/code_subdirectory
And my actual python code runs out of - /repository_root_path/code_subdirectory/src

I've set the variables as the following -

LOGFIRE_REPOSITORY=https://github.com/my-org/my-repo
LOGFIRE_REVISION=main
LOGFIRE_ROOT_PATH=code_subdirectory

The resulting links generated in Logfire follow this format - https://github.com/my-org/my-repo/blob/main/src/path/to/code

Whereas the valid link is - https://github.com/my-org/my-repo/blob/main/code_subdirectory/src/path/to/code

Upon further review, it seems like changing the root_path doesn't impact the links at all so I'm not sure what to do.

@fwinokur fwinokur changed the title Cannot incorporate my VCS root_path Cannot incorporate VCS root_path Jan 21, 2025
@Kludex
Copy link
Member

Kludex commented Jan 22, 2025

The root path is used to extract that prefix from the path, not to add as a prefix.

Can you try adding the follow env var:

OTEL_RESOURCE_ATTRIBUTES="logfire.code.work_dir=/repository_root_path/code_subdirectory/src"

@Kludex Kludex self-assigned this Jan 22, 2025
@Kludex
Copy link
Member

Kludex commented Jan 22, 2025

Hmmm... Hold on... We actually add the logfire.code.work_dir automatically.

@Kludex
Copy link
Member

Kludex commented Jan 22, 2025

Can you try to just add a / in front of code_subdirectory?

@fwinokur
Copy link
Author

Thanks @Kludex for the response here! I did a fair amount of playing around with different permutations, but I wasn't able to get it to work.

After inspecting the Raw Data in the Logfire UI, I noticed that Logfire sets the current working directory (as you noted above) as /repository_root_path/code_subdirectory which seems to cause it to be truncated from VCS url (I could be wrong about that, I tried to explore the code, but I couldn't understand the interplay between what's native to OTEL vs. controlled by Logfire). What's puzzling me is that /code_subdirectory is part of GitHub's url so my links are still missing that and I can't seem to "re-add" it via any the mechanisms available.

@Kludex
Copy link
Member

Kludex commented Jan 23, 2025

Oh, I see. You don't need to set the root path.

The root path removes the prefix from the generated link, it doesn't add.

@fwinokur
Copy link
Author

fwinokur commented Jan 23, 2025

Okay that makes sense and I understand that now, thank you for that. But my problem persists because even with the root_path omitted, the GitHub link in the Logfire UI after the REF_REVISION seemingly starts from one directory deeper than the CODE_WORK_DIR.

So in essence, this test is passing for me and the configuration is working as intended.

I can't see how the GitHub link is composed in the frontend though. For me, it's generating ${RESOURCE_ATTRIBUTES_CODE_WORK_DIR}/${RESOURCE_ATTRIBUTES_VCS_REPOSITORY_REF_REVISION}/${CODE_PATH_WITHOUT-RESOURCE_ATTRIBUTES_CODE_WORK_DIR}

Where CODE_PATH_WITHOUT-RESOURCE_ATTRIBUTES_CODE_WORK_DIR starts in the src/ directory.

The valid link is ${RESOURCE_ATTRIBUTES_CODE_WORK_DIR}/${RESOURCE_ATTRIBUTES_VCS_REPOSITORY_REF_REVISION}/code_subdirectory/${CODE_PATH_WITHOUT-RESOURCE_ATTRIBUTES_CODE_WORK_DIR}

Let me know if that makes sense, I'm not doing a great job explaining...

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

No branches or pull requests

2 participants