Skip to content
This repository has been archived by the owner on Feb 16, 2025. It is now read-only.

Commit

Permalink
feat: add link to logs (#620)
Browse files Browse the repository at this point in the history
* feat: add link to logs

* Timestamps -> trace IDs

* Get trace IDs semi-working

* Specify project ID

* fix lint

Co-authored-by: Patti Shin <[email protected]>
  • Loading branch information
Ace Nassri and pattishin authored Aug 24, 2022
1 parent 3247df5 commit bab1ab7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
5 changes: 5 additions & 0 deletions website/static/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ img.emblem-avatar {
.emblem-campaign-details .mdc-button {
margin-top: 1em;
float: right;
display: inline-flex;
}

.emblem-campaign-details .mdc-button:nth-child(1) {
margin-left: 1em;
}

/***** Donate to Campaign page *****/
Expand Down
14 changes: 13 additions & 1 deletion website/templates/donations/view-donation.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,19 @@
<span class="mdc-list-item__meta">{{ donation.time_created }}</span>
</li>
</ul>

</div>
<!-- Buttons -->
<div class="emblem-campaign-details mdc-layout-grid__cell mdc-layout-grid__cell--span-12">
{% if logsUrl %}
<!-- View Logs button -->
<a href="{{ logsUrl }}" class="mdc-button mdc-button--raised" target=”_blank”>
<span class="mdc-button__ripple"></span>
<i class="material-icons mdc-button__icon" aria-hidden="true"
>manage_search</i
>
<span class="mdc-button__label">View logs</span>
</a>
{% endif %}
<!-- Donate button -->
<a href="/donate?campaign_id={{ campaign.id }}" class="mdc-button mdc-button--raised">
<span class="mdc-button__ripple"></span>
Expand Down
20 changes: 19 additions & 1 deletion website/views/donations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@


import os
import requests
from flask import after_this_request, Blueprint, g, redirect, request, render_template

from middleware import session
Expand Down Expand Up @@ -101,7 +102,8 @@ def add_header(response):
log(f"Exception when creating a donation: {e}", severity="ERROR")
return render_template("errors/403.html"), 403

return redirect("/viewDonation?donation_id=" + donation.id)
trace_id = request.headers.get("X-Cloud-Trace-Context").split("/")[0]
return redirect(f"/viewDonation?donation_id={donation.id}&trace_id={trace_id}")


@donations_bp.route("/viewDonation", methods=["GET"])
Expand All @@ -119,8 +121,24 @@ def webapp_view_donation():
log(f"Exception when getting a campaign for a donations: {e}", severity="ERROR")
return render_template("errors/403.html"), 403

logs_url = None
try:
trace_id = request.args.get("trace_id")

project_req = requests.get(
"http://metadata.google.internal/computeMetadata/v1/project/project-id",
headers={"Metadata-Flavor": "Google"},
)
project_id = project_req.text

if trace_id and project_id:
logs_url = f"https://console.cloud.google.com/logs/query;query=trace%3D~%22projects%2F{project_id}%2Ftraces%2F{trace_id}%22?project={project_id}"
except Exception as e:
log(f"Exception when getting trace ID: {e}", severity="WARNING")

return render_template(
"donations/view-donation.html",
donation=donation_instance,
campaign=campaign_instance,
logsUrl=logs_url,
)

0 comments on commit bab1ab7

Please sign in to comment.