Skip to content

implement span for device_id.connected#108

Open
jay-418 wants to merge 15 commits intomainfrom
jay/conn-stats
Open

implement span for device_id.connected#108
jay-418 wants to merge 15 commits intomainfrom
jay/conn-stats

Conversation

@jay-418
Copy link

@jay-418 jay-418 commented Feb 13, 2026

purpose

Provide mechanism for recording a device_id's first connection to a route to provide an indication of poor network conditions.

mechanism

Emit a span with device_id (and some attrs) when a proxy is assigned by the API during config request. Then also emit a span (here, this code) when a device_id first connects to a proxy.

In SigNoz, we can calculate (using some kinda gnarly ClickHouse queries as discussed in https://github.com/getlantern/engineering/issues/2987):

  • the percentage of api config requests that never result in a proxy connections
  • the latency between config request and initial proxy connection

@jay-418 jay-418 self-assigned this Feb 24, 2026
@jay-418 jay-418 marked this pull request as ready for review February 28, 2026 02:40
Copilot AI review requested due to automatic review settings February 28, 2026 02:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds OpenTelemetry tracing to correlate a device’s proxy assignment with its first observed proxy connection, enabling connectivity success-rate and time-to-connect analysis in SigNoz.

Changes:

  • Emit a device_id.connected span when CLIENTINFO is received on routed TCP/packet connections.
  • Add OTLP/HTTP trace exporter initialization alongside existing metrics exporter initialization.
  • Wire clientcontext manager into the run path by default and add a local ping script / Makefile flag plumbing.

Reviewed changes

Copilot reviewed 7 out of 9 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
tracker/clientcontext/manager.go Emits device_id.connected span with client attributes on successful CLIENTINFO parsing.
otel/otel.go Adds InitGlobalTracerProvider using OTLP/HTTP exporter and SDK tracer provider.
cmd/main.go Initializes global meter + tracer providers during CLI pre-run when proxy info is available.
cmd/cmd_run.go Always registers the clientcontext manager (previously conditional) to enable tracing.
cmd/Makefile Passes --telemetry-endpoint through make run.
scripts/ping.sh Adds a script intended to exercise CLIENTINFO and produce the new span.
go.mod / go.sum Adds OTLP trace HTTP exporter dependencies.
.gitignore Ignores cmd/cmd.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +8 to +23
# which triggers the device_id.connected span in telemetry.

set -e

HOST="${1:-127.0.0.1}"
PORT="${2:-8888}"

echo "Connecting to $HOST:$PORT..."

(
echo -e "CONNECT example.com:443 HTTP/1.1\r\nHost: example.com:443\r\n\r"
sleep 0.5
echo -n 'CLIENTINFO {"DeviceID":"test-device","Platform":"linux","IsPro":false,"CountryCode":"US","Version":"1.0.0"}'
sleep 0.5
) | nc -w 2 "$HOST" "$PORT" | head -1

Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script won’t trigger the CLIENTINFO handling / device_id.connected span as written: the server-side Manager expects the first bytes on the connection to start with the CLIENTINFO prefix. Sending an HTTP CONNECT request first means the Manager will treat the connection as non-CLIENTINFO and the later CLIENTINFO ... bytes will just be forwarded as normal payload. Also, the CONNECT request line terminator looks incomplete (\r\n\r instead of \r\n\r\n). Consider sending the CLIENTINFO {...} packet first and reading the OK response (or otherwise matching the actual injector protocol) so this is a reliable test.

Copilot uses AI. Check for mistakes.
@jay-418 jay-418 requested a review from Crosse February 28, 2026 03:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants