Skip to content

Commit

Permalink
Include proxy_name with proxied_bytes data
Browse files Browse the repository at this point in the history
  • Loading branch information
oxtoacart committed Oct 19, 2023
1 parent bb2cbec commit d1b9b71
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions http_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,10 +719,10 @@ func (p *Proxy) configureOTEL(
opts.SampleRate = sampleRate
tp, stop := otel.BuildTracerProvider(opts)
if tp != nil {
go p.instrument.ReportToOTELPeriodically(reportingInterval, tp, includeDeviceIDs)
go p.instrument.ReportToOTELPeriodically(reportingInterval, tp, p.ProxyName, includeDeviceIDs)
ogStop := stop
stop = func() {
p.instrument.ReportToOTEL(tp, includeDeviceIDs)
p.instrument.ReportToOTEL(tp, p.ProxyName, includeDeviceIDs)
ogStop()
}
}
Expand Down
15 changes: 8 additions & 7 deletions instrument/instrument.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ type Instrument interface {
SuspectedProbing(ctx context.Context, fromIP net.IP, reason string)
VersionCheck(ctx context.Context, redirect bool, method, reason string)
ProxiedBytes(ctx context.Context, sent, recv int, platform, version, app, locale, dataCapCohort, probingError string, clientIP net.IP, deviceID, originHost string)
ReportToOTELPeriodically(interval time.Duration, tp *sdktrace.TracerProvider, includeDeviceID bool)
ReportToOTEL(tp *sdktrace.TracerProvider, includeDeviceID bool)
ReportToOTELPeriodically(interval time.Duration, tp *sdktrace.TracerProvider, proxyName string, includeDeviceID bool)
ReportToOTEL(tp *sdktrace.TracerProvider, proxyName string, includeDeviceID bool)
quicSentPacket(ctx context.Context)
quicLostPacket(ctx context.Context)
}
Expand Down Expand Up @@ -71,9 +71,9 @@ func (i NoInstrument) SuspectedProbing(ctx context.Context, fromIP net.IP, reaso
func (i NoInstrument) VersionCheck(ctx context.Context, redirect bool, method, reason string) {}
func (i NoInstrument) ProxiedBytes(ctx context.Context, sent, recv int, platform, version, app, locale, dataCapCohort, probingError string, clientIP net.IP, deviceID, originHost string) {
}
func (i NoInstrument) ReportToOTELPeriodically(interval time.Duration, tp *sdktrace.TracerProvider, includeDeviceID bool) {
func (i NoInstrument) ReportToOTELPeriodically(interval time.Duration, tp *sdktrace.TracerProvider, proxyName string, includeDeviceID bool) {
}
func (i NoInstrument) ReportToOTEL(tp *sdktrace.TracerProvider, includeDeviceID bool) {
func (i NoInstrument) ReportToOTEL(tp *sdktrace.TracerProvider, proxyName string, includeDeviceID bool) {
}
func (i NoInstrument) quicSentPacket(ctx context.Context) {}
func (i NoInstrument) quicLostPacket(ctx context.Context) {}
Expand Down Expand Up @@ -395,19 +395,19 @@ func (u *usage) add(sent int, recv int) *usage {
return u
}

func (ins *defaultInstrument) ReportToOTELPeriodically(interval time.Duration, tp *sdktrace.TracerProvider, includeDeviceID bool) {
func (ins *defaultInstrument) ReportToOTELPeriodically(interval time.Duration, tp *sdktrace.TracerProvider, proxyName string, includeDeviceID bool) {
for {
// We randomize the sleep time to avoid bursty submission to OpenTelemetry.
// Even though each proxy sends relatively little data, proxies often run fairly
// closely synchronized since they all update to a new binary and restart around the same
// time. By randomizing each proxy's interval, we smooth out the pattern of submissions.
sleepInterval := rand.Int63n(int64(interval * 2))
time.Sleep(time.Duration(sleepInterval))
ins.ReportToOTEL(tp, includeDeviceID)
ins.ReportToOTEL(tp, proxyName, includeDeviceID)
}
}

func (ins *defaultInstrument) ReportToOTEL(tp *sdktrace.TracerProvider, includeDeviceID bool) {
func (ins *defaultInstrument) ReportToOTEL(tp *sdktrace.TracerProvider, proxyName string, includeDeviceID bool) {
var clientStats map[clientDetails]*usage
ins.statsMx.Lock()
if includeDeviceID {
Expand Down Expand Up @@ -452,6 +452,7 @@ func (ins *defaultInstrument) ReportToOTEL(tp *sdktrace.TracerProvider, includeD
attribute.Int("origin_bytes_sent", value.sent),
attribute.Int("origin_bytes_recv", value.recv),
attribute.Int("origin_bytes_total", value.sent+value.recv),
attribute.String("proxy_name", proxyName),
attribute.String("origin", key.origin),
attribute.String("client_platform", key.platform),
attribute.String("client_version", key.version),
Expand Down

0 comments on commit d1b9b71

Please sign in to comment.