Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kiosk_show_replacement/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# Import main application factory and database for convenience
from .app import create_app, db

__version__ = "0.3.4"
__version__ = "0.3.5"
__author__ = "Jason Antman"
__email__ = "jason@jasonantman.com"
__license__ = "MIT"
Expand Down
43 changes: 17 additions & 26 deletions kiosk_show_replacement/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,63 +211,54 @@ def inject_app_version() -> dict[str, str]:

@app.context_processor
def newrelic_browser_timing() -> dict[str, Markup]:
"""Provide NewRelic browser timing scripts to templates."""
"""Provide NewRelic browser timing script to templates."""
try:
import newrelic.agent

return {
"newrelic_header": Markup(newrelic.agent.get_browser_timing_header()),
"newrelic_footer": Markup(newrelic.agent.get_browser_timing_footer()),
}
except ImportError:
# NewRelic not installed - this is expected in development
return {"newrelic_header": Markup(""), "newrelic_footer": Markup("")}
return {"newrelic_header": Markup("")}
except Exception as e:
logger.warning("NewRelic browser timing failed: %s", e)
return {"newrelic_header": Markup(""), "newrelic_footer": Markup("")}
return {"newrelic_header": Markup("")}

def _get_newrelic_browser_scripts() -> tuple[str, str]:
"""Get NewRelic browser timing scripts for injection.
def _get_newrelic_browser_script() -> str:
"""Get NewRelic browser timing script for injection.

Returns:
Tuple of (header_script, footer_script). Empty strings if
The browser timing script string. Empty string if
NewRelic is not active.
"""
try:
import newrelic.agent

return (
newrelic.agent.get_browser_timing_header(),
newrelic.agent.get_browser_timing_footer(),
)
return str(newrelic.agent.get_browser_timing_header())
except ImportError:
# NewRelic not installed - this is expected in development
return ("", "")
return ""
except Exception as e:
logger.warning("NewRelic browser scripts failed: %s", e)
return ("", "")
logger.warning("NewRelic browser script failed: %s", e)
return ""
Comment thread
jantman marked this conversation as resolved.

def _inject_newrelic_into_html(html: str) -> str:
"""Inject NewRelic browser timing scripts into HTML.
"""Inject NewRelic browser timing script into HTML.

Args:
html: The HTML content to inject scripts into.
html: The HTML content to inject the script into.

Returns:
HTML with NewRelic scripts injected, or original HTML if
HTML with NewRelic script injected, or original HTML if
NewRelic is not active.
"""
header, footer = _get_newrelic_browser_scripts()
if not header and not footer:
script = _get_newrelic_browser_script()
if not script:
return html

# Inject header after <head> tag
if header:
html = html.replace("<head>", f"<head>\n {header}", 1)

# Inject footer before </body> tag
if footer:
html = html.replace("</body>", f" {footer}\n</body>", 1)
# Inject after <head> tag
html = html.replace("<head>", f"<head>\n {script}", 1)

return html

Expand Down
1 change: 0 additions & 1 deletion kiosk_show_replacement/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,5 @@
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>

{% block scripts %}{% endblock %}
{{ newrelic_footer }}
</body>
</html>
1 change: 0 additions & 1 deletion kiosk_show_replacement/templates/display.html
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,5 @@
}
});
</script>
{{ newrelic_footer }}
</body>
</html>
1 change: 0 additions & 1 deletion kiosk_show_replacement/templates/display/slideshow.html
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,5 @@
if (sseClient) sseClient.disconnect();
});
</script>
{{ newrelic_footer }}
</body>
</html>
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "kiosk-show-replacement"
version = "0.3.4"
version = "0.3.5"
description = "A self-hosted replacement for kiosk.show"
authors = ["Jason Antman <jason@jasonantman.com>"]
license = "MIT"
Expand Down
Loading