From d1b9b718cae24118d03646479ee7d3af739220be Mon Sep 17 00:00:00 2001 From: Ox Cart Date: Thu, 19 Oct 2023 10:39:37 -0500 Subject: [PATCH] Include proxy_name with proxied_bytes data --- http_proxy.go | 4 ++-- instrument/instrument.go | 15 ++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/http_proxy.go b/http_proxy.go index 32b4a24b..b157f80c 100644 --- a/http_proxy.go +++ b/http_proxy.go @@ -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() } } diff --git a/instrument/instrument.go b/instrument/instrument.go index 3863c9aa..09e8bd80 100644 --- a/instrument/instrument.go +++ b/instrument/instrument.go @@ -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) } @@ -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) {} @@ -395,7 +395,7 @@ 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 @@ -403,11 +403,11 @@ func (ins *defaultInstrument) ReportToOTELPeriodically(interval time.Duration, t // 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 { @@ -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),