<@ULVA73B9P> I have this function ```from prefect.context import FlowRunContext def get_prefect_url...
j
@Marvin I have this function
Copy code
from prefect.context import FlowRunContext

def get_prefect_url(path:str) -> str:
    flow_run_context = FlowRunContext.get()
    return f'{flow_run_context.client.api_url.scheme}://{flow_run_context.client.api_url.host}:{flow_run_context.client.api_url.port}{path}'
and call it like this:
Copy code
artifact_url = get_prefect_url(f'/artifacts/artifact/{artifact_uuid})
and get back a valid artifact URL like this:
<http://server:port/artifacts/artifact/uuid>
however, when I log that URL with
<http://logger.info|logger.info>(artifact_url)
, the hyperlink in the log looks like this:
Copy code
<http://server>:port/runs/flow-run/<http://server>:port/artifacts/artifact/uuid
why is the URL being prefixed with
<http://server>:port/runs/flow-run/
?
m
To address your issue, understanding the Prefect version you are using is crucial since the context and functionality can be slightly different between Prefect 1.x, 2.x, and 3.x versions. Since you've mentioned using
FlowRunContext
, I'll perform some research on Prefect 2.x and 3.x. Let's get started on looking into documentation and issues that might relate to your problem regarding improper URL logging. I'll first search the Prefect documentation and GitHub issues for how
FlowRunContext.get()
works and if there are known issues with logging URLs using it. Please hold on while I do this. From my research, it seems that the
FlowRunContext.get()
function works similarly in both Prefect 2.x and 3.x, providing the context within which a flow is running. This context should give you information about the current flow run, including API details. There isn't any documentation or known bug directly tying
FlowRunContext.get()
to altering URLs upon logging. The issue with URLs getting prefixed in logs might be an unintended interaction with logging formatting, especially if the log system automatically inserts the current context's base URL. This isn't a documented functionality and might not be directly related to
FlowRunContext
. Here's what might be happening: - Logger configurations or plugins might prepend URLs with the current context's details when it detects URL patterns, especially if they are not properly formatted. - If your logging tool or interface applies certain rules or filters to URLs, it might misinterpret the URL formatting. Without concrete examples from the documentation indicating this behavior as standard, it's likely an environmental or setup issue rather than a direct artifact of Prefect’s operations. Here's how you can further diagnose and potentially resolve the issue: 1. Check your logging configuration: There might be a configuration or a plugin that affects URL formatting in logs. 2. Verify URL formatting: Ensure that the URLs are correctly formatted before logging, and try logging different examples to see if the issue persists. 3. Isolate the logging: Print or use a simpler logging method to see if the issue is specific to your current logger or environment. For the documentation and resources I found, you can explore these links: - Prefect 2.x Runtime Context - Prefect 3.x Runtime Context If further investigation with logging configurations doesn't help, you might want to reach out with an issue on Prefect's GitHub issues page to see if others have experienced similar behavior.