Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
15 changes: 0 additions & 15 deletions hack/upload-traces-otelcol-config.yaml

This file was deleted.

82 changes: 65 additions & 17 deletions hack/upload-traces.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#!/usr/bin/env bash
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONFIG_TEMPLATE="${SCRIPT_DIR}/upload-traces-otelcol-config.yaml"

die() { echo "error: $*" >&2; exit 1; }

usage() {
Expand All @@ -20,8 +17,9 @@ Arguments:
--endpoint OTLP HTTP endpoint (e.g. http://localhost:4318)
--header key=value Header to send with OTLP requests (repeatable)

Headers are passed via the OTEL_EXPORTER_OTLP_HEADERS env var. Any value
already set in the environment is preserved and appended to.
Headers are injected into the Collector's otlphttp exporter config.
Any key=value pairs already set in the OTEL_EXPORTER_OTLP_HEADERS env
var are also included and merged with --header flags.

Examples:
$(basename "$0") run/agent-run-123/run-telemetry.jsonl --endpoint http://localhost:4318
Expand Down Expand Up @@ -71,9 +69,6 @@ done
command -v otelcol-contrib >/dev/null 2>&1 \
|| die "otelcol-contrib not found. Install: https://github.com/open-telemetry/opentelemetry-collector-releases/releases"

[[ -f "$CONFIG_TEMPLATE" ]] \
|| die "config template not found: $CONFIG_TEMPLATE"

# --- resolve to absolute include pattern ---
if [[ -d "$SOURCE" ]]; then
INCLUDE="$(cd "$SOURCE" && pwd)/**/*.jsonl"
Expand All @@ -89,19 +84,72 @@ else
fi
echo "include: $INCLUDE"

# --- run collector ---
export REPLAY_INCLUDE="$INCLUDE"
export REPLAY_ENDPOINT="$ENDPOINT"

# Merge --header flags with any existing OTEL_EXPORTER_OTLP_HEADERS.
# --- merge headers ---
# Combine --header flags with any pre-existing OTEL_EXPORTER_OTLP_HEADERS
# into a single comma-separated string for config generation.
MERGED_HEADERS="${OTEL_EXPORTER_OTLP_HEADERS:-}"
if [[ -n "$HEADERS" ]]; then
if [[ -n "${OTEL_EXPORTER_OTLP_HEADERS:-}" ]]; then
export OTEL_EXPORTER_OTLP_HEADERS="${OTEL_EXPORTER_OTLP_HEADERS},${HEADERS}"
if [[ -n "$MERGED_HEADERS" ]]; then
MERGED_HEADERS="${MERGED_HEADERS},${HEADERS}"
else
export OTEL_EXPORTER_OTLP_HEADERS="$HEADERS"
MERGED_HEADERS="$HEADERS"
fi
fi

# --- generate runtime config ---
# The otelcol-contrib Collector reads headers from its YAML config
# (exporters.otlphttp.headers), not from OTEL_EXPORTER_OTLP_HEADERS.
# Generate a runtime config that injects any headers into the YAML.
Comment thread
rh-hemartin marked this conversation as resolved.
Outdated
export REPLAY_INCLUDE="$INCLUDE"
export REPLAY_ENDPOINT="$ENDPOINT"

RUNTIME_CONFIG=$(mktemp "${TMPDIR:-/tmp}/otelcol-config-XXXXXX.yaml")
Comment thread
rh-hemartin marked this conversation as resolved.
Outdated
cleanup() { rm -f "$RUNTIME_CONFIG"; }
trap cleanup EXIT

cat > "$RUNTIME_CONFIG" <<'YAML'
receivers:
otlpjsonfile:
include:
- "${env:REPLAY_INCLUDE}"
start_at: beginning

exporters:
otlphttp:
endpoint: "${env:REPLAY_ENDPOINT}"
YAML

if [[ -n "$MERGED_HEADERS" ]]; then
Comment thread
rh-hemartin marked this conversation as resolved.
Outdated
echo " headers:" >> "$RUNTIME_CONFIG"
IFS=',' read -ra HEADER_ARRAY <<< "$MERGED_HEADERS"
Comment thread
rh-hemartin marked this conversation as resolved.
Outdated
for h in "${HEADER_ARRAY[@]}"; do
key="${h%%=*}"
value="${h#*=}"
[[ "$key" =~ ^[a-zA-Z0-9_-]+$ ]] \
|| die "invalid header key (must match [a-zA-Z0-9_-]+): $key"
value="${value//$'\n'/}"
value="${value//$'\r'/}"
value="${value//\$/\$\$}"
value="${value//\'/\'\'}"
printf " %s: '%s'\n" "$key" "$value" >> "$RUNTIME_CONFIG"
Comment thread
rh-hemartin marked this conversation as resolved.
Outdated
done
fi

cat >> "$RUNTIME_CONFIG" <<'YAML'

service:
pipelines:
traces:
receivers: [otlpjsonfile]
exporters: [otlphttp]
YAML

echo "endpoint: $ENDPOINT"
if [[ -n "$MERGED_HEADERS" ]]; then
IFS=',' read -ra _hdr_arr <<< "$MERGED_HEADERS"
header_count=${#_hdr_arr[@]}
echo "headers: ${header_count} configured (values redacted)"
fi

echo "starting otelcol-contrib (runs continuously, watching for new data; press Ctrl+C to stop)..."
otelcol-contrib --config "$CONFIG_TEMPLATE"
otelcol-contrib --config "$RUNTIME_CONFIG"
Loading