Skip to content

Commit 2607368

Browse files
committed
Allow specifying SAMPLY_SERVER_URL
This patch adds reading envvar SAMPLY_SERVER_URL to embed it into the served HTML & used URLs for samply output. It is possible that we would like to launch this samply result in the testbed server and we would like to offer profiler result remotely. So we can launch samply with --address 0.0.0.0 and by using this SAMPLY_SERVER_URL, we can expose samply as a remote symbol / profile server.
1 parent 4a5afec commit 2607368

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

samply/src/server.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,14 @@ pub async fn start_server(
7070

7171
let token = generate_token();
7272
let path_prefix = format!("/{token}");
73-
let server_origin = format!("http://{addr}");
73+
let env_server_override = std::env::var("SAMPLY_SERVER_URL").ok();
74+
let server_origin = match &env_server_override {
75+
Some(s) => s.trim_end_matches('/').to_string(),
76+
None => format!("http://{addr}"),
77+
};
7478
let symbol_server_url = format!("{server_origin}{path_prefix}");
7579
let mut template_values: HashMap<&'static str, String> = HashMap::new();
76-
template_values.insert("SERVER_URL", server_origin.clone());
80+
template_values.insert("SAMPLY_SERVER_URL", server_origin.clone());
7781
template_values.insert("PATH_PREFIX", path_prefix.clone());
7882

7983
let profiler_url = if profile_filename.is_some() {
@@ -166,7 +170,7 @@ const TEMPLATE_WITH_PROFILE: &str = r#"
166170
<title>Profiler Symbol Server</title>
167171
<body>
168172
169-
<p>This is the profiler symbol server, running at <code>SERVER_URL</code>. You can:</p>
173+
<p>This is the profiler symbol server, running at <code>SAMPLY_SERVER_URL</code>. You can:</p>
170174
<ul>
171175
<li><a href="PROFILER_URL">Open the profile in the profiler UI</a></li>
172176
<li><a download href="PROFILE_URL">Download the raw profile JSON</a></li>
@@ -182,7 +186,7 @@ const TEMPLATE_WITHOUT_PROFILE: &str = r#"
182186
<title>Profiler Symbol Server</title>
183187
<body>
184188
185-
<p>This is the profiler symbol server, running at <code>SERVER_URL</code>. You can:</p>
189+
<p>This is the profiler symbol server, running at <code>SAMPLY_SERVER_URL</code>. You can:</p>
186190
<ul>
187191
<li>Obtain symbols by POSTing to <code>PATH_PREFIX/symbolicate/v5</code>, with the format specified by the <a href="https://tecken.readthedocs.io/en/latest/symbolication.html">Mozilla symbolication API documentation</a>.</li>
188192
<li>Obtain source code by POSTing to <code>PATH_PREFIX/source/v1</code>, with the format specified in this <a href="https://github.com/mstange/profiler-get-symbols/issues/24#issuecomment-989985588">github comment</a>.</li>

0 commit comments

Comments
 (0)