Skip to content

Commit 68690fc

Browse files
committed
Add telemetry fields and CI matrix for telemetry variants
- Add standard telemetry fields to tracing spans: * hostname: Host header from incoming request (tracked even when worker not found) * http_method: HTTP method (GET, POST, etc.) * response_status_code: HTTP response status code for all responses - Add error_response_with_span() helper to record status code in error paths - Add CI matrix to build both v8 and v8-telemetry Docker image variants - Update Dockerfile and Dockerfile.multi to conditionally compile telemetry feature based on TELEMETRY build arg - Update dependencies (Cargo.lock)
1 parent 887181f commit 68690fc

6 files changed

Lines changed: 71 additions & 28 deletions

File tree

.github/workflows/docker.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ on:
1414

1515
jobs:
1616
build:
17-
name: Build (${{ matrix.runtime }})
17+
name: Build (${{ matrix.runtime }}${{ matrix.telemetry && '-telemetry' || '' }})
1818
runs-on: ubuntu-24.04
1919
strategy:
2020
matrix:
2121
runtime: [v8] # deno disabled (requires core 0.5, we're on 0.6)
22+
telemetry: [false, true]
2223
steps:
2324
- name: Check Out Repo
2425
uses: actions/checkout@v4
@@ -29,10 +30,10 @@ jobs:
2930
images: |
3031
ghcr.io/${{ github.repository }}
3132
tags: |
32-
type=raw,value=${{ matrix.runtime }},enable={{is_default_branch}}
33-
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' && matrix.runtime == 'v8' }}
34-
type=ref,event=branch,suffix=-${{ matrix.runtime }}
35-
type=ref,event=tag,suffix=-${{ matrix.runtime }}
33+
type=raw,value=${{ matrix.runtime }}${{ matrix.telemetry && '-telemetry' || '' }},enable={{is_default_branch}}
34+
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' && matrix.runtime == 'v8' && !matrix.telemetry }}
35+
type=ref,event=branch,suffix=-${{ matrix.runtime }}${{ matrix.telemetry && '-telemetry' || '' }}
36+
type=ref,event=tag,suffix=-${{ matrix.runtime }}${{ matrix.telemetry && '-telemetry' || '' }}
3637
- name: Set up Docker Buildx
3738
uses: docker/setup-buildx-action@v3
3839
- name: Login to GitHub Container Registry
@@ -50,7 +51,8 @@ jobs:
5051
tags: ${{ steps.metadata.outputs.tags }}
5152
build-args: |
5253
RUNTIME=${{ matrix.runtime }}
53-
cache-from: type=gha,scope=${{ matrix.runtime }}
54-
cache-to: type=gha,mode=max,scope=${{ matrix.runtime }}
54+
TELEMETRY=${{ matrix.telemetry }}
55+
cache-from: type=gha,scope=${{ matrix.runtime }}-${{ matrix.telemetry }}
56+
cache-to: type=gha,mode=max,scope=${{ matrix.runtime }}-${{ matrix.telemetry }}
5557
# TODO: re-enable linux/arm64 once openworkers-v8 provides prebuilt binaries for aarch64-unknown-linux-gnu
5658
platforms: linux/amd64

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "openworkers-runner"
3-
version = "0.12.8"
3+
version = "0.12.9"
44
edition = "2024"
55
license = "MIT"
66
default-run = "openworkers-runner"

Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ RUN cargo chef prepare --recipe-path recipe.json
99
FROM chef AS builder
1010

1111
ARG RUNTIME=v8
12+
ARG TELEMETRY=false
1213

13-
ENV FEATURES=$RUNTIME,database,telemetry
1414
ENV RUST_BACKTRACE=1
1515
ENV RUNTIME_SNAPSHOT_PATH=/build/snapshot.bin
1616

@@ -21,6 +21,8 @@ COPY --from=planner /build/recipe.json recipe.json
2121
RUN --mount=type=cache,target=$CARGO_HOME/git \
2222
--mount=type=cache,target=$CARGO_HOME/registry \
2323
--mount=type=cache,target=/build/target \
24+
FEATURES="$RUNTIME,database"; \
25+
if [ "$TELEMETRY" = "true" ]; then FEATURES="$FEATURES,telemetry"; fi; \
2426
cargo chef cook --release --features=$FEATURES --recipe-path recipe.json
2527

2628
# Build application
@@ -31,6 +33,8 @@ RUN touch $RUNTIME_SNAPSHOT_PATH
3133
RUN --mount=type=cache,target=$CARGO_HOME/git \
3234
--mount=type=cache,target=$CARGO_HOME/registry \
3335
--mount=type=cache,target=/build/target \
36+
FEATURES="$RUNTIME,database"; \
37+
if [ "$TELEMETRY" = "true" ]; then FEATURES="$FEATURES,telemetry"; fi; \
3438
cargo run --release --features=$FEATURES --bin snapshot && \
3539
# Build the runner and copy executable out of the cache so it can be used in the next stage
3640
cargo build --release --features=$FEATURES && cp /build/target/release/openworkers-runner /build/output

Dockerfile.multi

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ RUN cargo chef prepare --recipe-path recipe.json
3636
FROM prepare AS platform
3737

3838
ARG RUNTIME=v8
39+
ARG TELEMETRY=false
3940
ARG TARGETPLATFORM
40-
41-
ENV FEATURES=$RUNTIME,database,telemetry
41+
4242
ENV RUST_BACKTRACE=1
4343
ENV RUNTIME_SNAPSHOT_PATH=/build/snapshot.bin
4444

@@ -49,12 +49,13 @@ RUN touch $RUNTIME_SNAPSHOT_PATH
4949
# Copy recipe from planner
5050
COPY --from=planner /build/recipe.json recipe.json
5151

52-
RUN echo "Building for $TARGETPLATFORM with features $FEATURES"
53-
5452
# Build dependencies for target platform
55-
RUN --mount=type=cache,id=cargo-$TARGETPLATFORM-$RUNTIME,sharing=locked,target=$CARGO_HOME/git \
56-
--mount=type=cache,id=cargo-$TARGETPLATFORM-$RUNTIME,sharing=locked,target=$CARGO_HOME/registry \
57-
--mount=type=cache,id=cargo-$TARGETPLATFORM-$RUNTIME,sharing=locked,target=/build/target \
53+
RUN --mount=type=cache,id=cargo-$TARGETPLATFORM-$RUNTIME-$TELEMETRY,sharing=locked,target=$CARGO_HOME/git \
54+
--mount=type=cache,id=cargo-$TARGETPLATFORM-$RUNTIME-$TELEMETRY,sharing=locked,target=$CARGO_HOME/registry \
55+
--mount=type=cache,id=cargo-$TARGETPLATFORM-$RUNTIME-$TELEMETRY,sharing=locked,target=/build/target \
56+
FEATURES="$RUNTIME,database"; \
57+
if [ "$TELEMETRY" = "true" ]; then FEATURES="$FEATURES,telemetry"; fi; \
58+
echo "Building for $TARGETPLATFORM with features $FEATURES"; \
5859
case "$TARGETPLATFORM" in \
5960
"linux/arm64") cargo chef cook --release --features=$FEATURES --target aarch64-unknown-linux-gnu --recipe-path recipe.json ;; \
6061
"linux/amd64") cargo chef cook --release --features=$FEATURES --target x86_64-unknown-linux-gnu --recipe-path recipe.json ;; \
@@ -68,9 +69,11 @@ COPY . /build
6869
# 1. Build the snapshot generator for the TARGET platform
6970
# 2. Run it (via QEMU emulation explicitly) to generate the snapshot.bin
7071
# 3. Build the final runner which embeds the snapshot.bin
71-
RUN --mount=type=cache,id=cargo-$TARGETPLATFORM-$RUNTIME,sharing=locked,target=$CARGO_HOME/git \
72-
--mount=type=cache,id=cargo-$TARGETPLATFORM-$RUNTIME,sharing=locked,target=$CARGO_HOME/registry \
73-
--mount=type=cache,id=cargo-$TARGETPLATFORM-$RUNTIME,sharing=locked,target=/build/target \
72+
RUN --mount=type=cache,id=cargo-$TARGETPLATFORM-$RUNTIME-$TELEMETRY,sharing=locked,target=$CARGO_HOME/git \
73+
--mount=type=cache,id=cargo-$TARGETPLATFORM-$RUNTIME-$TELEMETRY,sharing=locked,target=$CARGO_HOME/registry \
74+
--mount=type=cache,id=cargo-$TARGETPLATFORM-$RUNTIME-$TELEMETRY,sharing=locked,target=/build/target \
75+
FEATURES="$RUNTIME,database"; \
76+
if [ "$TELEMETRY" = "true" ]; then FEATURES="$FEATURES,telemetry"; fi; \
7477
case "$TARGETPLATFORM" in \
7578
"linux/arm64") \
7679
# Build snapshot generator for target \

bin/main.rs

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,10 @@ async fn handle_request(
153153
let span = tracing::info_span!(
154154
"request",
155155
request_id = %request_id,
156-
method = %method,
156+
http_method = %method,
157157
uri = %uri,
158+
hostname = tracing::field::Empty,
159+
response_status_code = tracing::field::Empty,
158160
worker_id = tracing::field::Empty,
159161
worker_name = tracing::field::Empty,
160162
user_id = tracing::field::Empty,
@@ -188,6 +190,11 @@ async fn handle_worker_request(
188190
.and_then(|h| h.to_str().ok())
189191
.map(|s| s.to_string());
190192

193+
// Record hostname (even if worker not found)
194+
if let Some(ref hostname) = host {
195+
span.record("hostname", hostname.as_str());
196+
}
197+
191198
let worker_id = headers
192199
.get("x-worker-id")
193200
.and_then(|h| h.to_str().ok())
@@ -244,7 +251,13 @@ async fn handle_worker_request(
244251

245252
match worker {
246253
Some(w) => w,
247-
None => return Ok(error_response(404, "Worker not found")),
254+
None => {
255+
return Ok(error_response_with_span(
256+
&span,
257+
404,
258+
"Worker not found",
259+
));
260+
}
248261
}
249262
} else {
250263
return Ok(error_response(
@@ -299,8 +312,13 @@ async fn handle_worker_request(
299312
metrics_timer.start.elapsed().as_millis()
300313
);
301314

302-
// Convert HttpResponse to hyper::Response (handles streaming too!)
303-
return Ok(http_response.into_hyper());
315+
// Record status code and convert to hyper response
316+
let hyper_response = http_response.into_hyper();
317+
span.record(
318+
"response_status_code",
319+
hyper_response.status().as_u16(),
320+
);
321+
return Ok(hyper_response);
304322
}
305323
Err(e) => {
306324
debug!(
@@ -309,6 +327,7 @@ async fn handle_worker_request(
309327
);
310328

311329
error!("Failed to fetch from storage: {}", e);
330+
span.record("response_status_code", 404u16);
312331
return Ok(error_response(404, "File not found"));
313332
}
314333
}
@@ -325,17 +344,22 @@ async fn handle_worker_request(
325344

326345
match worker {
327346
Some(w) => w,
328-
None => return Ok(error_response(404, "Worker not found")),
347+
None => return Ok(error_response_with_span(&span, 404, "Worker not found")),
329348
}
330349
} else {
331-
return Ok(error_response(
350+
return Ok(error_response_with_span(
351+
&span,
332352
500,
333353
"Invalid resolution: no worker_id or project_id",
334354
));
335355
}
336356
}
337357
None => {
338-
return Ok(error_response(404, "Endpoint or route not found"));
358+
return Ok(error_response_with_span(
359+
&span,
360+
404,
361+
"Endpoint or route not found",
362+
));
339363
}
340364
};
341365

@@ -475,7 +499,8 @@ async fn handle_worker_request(
475499

476500
debug!("handle_request done in {}ms", start.elapsed().as_millis());
477501

478-
// Record metrics
502+
// Record response status code and metrics
503+
span.record("response_status_code", response.status().as_u16());
479504
metrics_timer.record_http_request(success);
480505

481506
Ok(response)
@@ -493,6 +518,15 @@ fn error_response(status: u16, message: &str) -> Response<HyperBody> {
493518
.unwrap()
494519
}
495520

521+
fn error_response_with_span(
522+
span: &tracing::Span,
523+
status: u16,
524+
message: &str,
525+
) -> Response<HyperBody> {
526+
span.record("response_status_code", status);
527+
error_response(status, message)
528+
}
529+
496530
#[tokio::main(flavor = "multi_thread", worker_threads = 4)]
497531
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
498532
dotenvy::dotenv().ok();

0 commit comments

Comments
 (0)