Skip to content

Add button to download task logs as a text file #49412

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

aarochuk
Copy link
Contributor

Added ability to download task instance logs in airflow 3 ui as described in issue #47689
closes: #47689

@boring-cyborg boring-cyborg bot added the area:UI Related to UI/UX. For Frontend Developers. label Apr 17, 2025
const element = document.createElement("a");

element.href = URL.createObjectURL(file);
element.download = `taskInstanceLogs.txt`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks the filename for the downloaded log file. This should include dagId and taskInstance details in the name like Airflow 2 else this might keep overwriting the file on disk or create something like taskInstanceLogs(1).txt

Copy link
Contributor

@bbovenzi bbovenzi Apr 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on ${dagId}-${taskId}-${runId}-${mapIndex}-${tryNumber}.txt

) => {
const refetchInterval = useAutoRefresh({ dagId });

const { data, ...rest } = useTaskInstanceServiceGetLog(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you can pass text/plain in the accept here and get the raw value of the log file in the storage which is the value users usually want to reduce the code for formatting.

accept?: "application/json" | "text/plain" | "*/*";

if accept == Mimetype.JSON or accept == Mimetype.ANY: # default
logs, metadata = task_log_reader.read_log_chunks(ti, try_number, metadata)
encoded_token = None
if not metadata.get("end_of_log", False):
encoded_token = URLSafeSerializer(request.app.state.secret_key).dumps(metadata)
return TaskInstancesLogResponse.model_construct(continuation_token=encoded_token, content=logs)
# text/plain, or something else we don't understand. Return raw log content
# We need to exhaust the iterator before we can generate the continuation token.
# We could improve this by making it a streaming/async response, and by then setting the header using
# HTTP Trailers
logs = "".join(task_log_reader.read_log_stream(ti, try_number, metadata))
headers = None
if not metadata.get("end_of_log", False):
headers = {
"Airflow-Continuation-Token": URLSafeSerializer(request.app.state.secret_key).dumps(metadata)
}
return Response(media_type="application/x-ndjson", content=logs, headers=headers)

@bbovenzi bbovenzi changed the title Issue #47689 Implementation Add button to download task logs as a text file Apr 22, 2025
@bbovenzi bbovenzi added this to the Airflow 3.1.0 milestone Apr 30, 2025
@bbovenzi
Copy link
Contributor

bbovenzi commented May 6, 2025

@aarochuk mind rebasing and addressing PR comments?

@aarochuk
Copy link
Contributor Author

aarochuk commented May 7, 2025

@bbovenzi I will make sure to make another push by the end of the week sorry it has taken so long

Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Jun 22, 2025
@github-actions github-actions bot closed this Jun 28, 2025
@bbovenzi bbovenzi reopened this Jul 1, 2025
@bbovenzi bbovenzi requested a review from shubhamraj-git as a code owner July 1, 2025 16:05
@bbovenzi
Copy link
Contributor

bbovenzi commented Jul 1, 2025

@aarochuk are you still able to finish this PR?

@github-actions github-actions bot removed the stale Stale PRs per the .github/workflows/stale.yml policy file label Jul 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:UI Related to UI/UX. For Frontend Developers.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No option to download task logs on Airflow 3 UI
3 participants