diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 00000000..b1bbed87 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1 @@ +- Telemetry attributes: follow rules in https://github.com/getlantern/semconv/blob/main/AGENTS.md diff --git a/go.mod b/go.mod index dd0b0577..51af11c4 100644 --- a/go.mod +++ b/go.mod @@ -37,6 +37,7 @@ require ( github.com/getlantern/psmux v1.5.15 github.com/getlantern/quicwrapper v0.0.0-20250417060014-acb01527c4c2 github.com/getlantern/ratelimit v0.0.0-20220926192648-933ab81a6fc7 + github.com/getlantern/semconv v0.0.0-20260327040646-21845dda05cb github.com/getlantern/sing-vmess v0.0.0-20241209111030-0f2c02b4eb9a github.com/getlantern/tinywss v0.0.0-20211216020538-c10008a7d461 github.com/getlantern/tlsdefaults v0.0.0-20171004213447-cf35cfd0b1b4 @@ -53,18 +54,18 @@ require ( github.com/sagernet/sing v0.6.0-alpha.18 github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726 github.com/spaolacci/murmur3 v1.1.0 - github.com/stretchr/testify v1.10.0 + github.com/stretchr/testify v1.11.1 github.com/vharitonsky/iniflags v0.0.0-20180513140207-a33cd0b5f3de github.com/xtaci/smux v1.5.35-0.20250217141229-e6b0586a4539 gitlab.com/yawning/obfs4.git v0.0.0-20220204003609-77af0cba934d - go.opentelemetry.io/otel v1.36.0 + go.opentelemetry.io/otel v1.38.0 go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.35.0 go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.35.0 go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.35.0 - go.opentelemetry.io/otel/metric v1.36.0 + go.opentelemetry.io/otel/metric v1.38.0 go.opentelemetry.io/otel/sdk v1.35.0 go.opentelemetry.io/otel/sdk/metric v1.35.0 - go.opentelemetry.io/otel/trace v1.36.0 + go.opentelemetry.io/otel/trace v1.38.0 golang.org/x/net v0.41.0 google.golang.org/api v0.169.0 ) @@ -136,7 +137,7 @@ require ( github.com/getlantern/uuid v1.2.0 // indirect github.com/go-llsqlite/adapter v0.0.0-20230927005056-7f5ce7f0c916 // indirect github.com/go-llsqlite/crawshaw v0.4.0 // indirect - github.com/go-logr/logr v1.4.2 // indirect + github.com/go-logr/logr v1.4.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-stack/stack v1.8.1 // indirect @@ -226,7 +227,7 @@ require ( gitlab.com/yawning/edwards25519-extra.git v0.0.0-20211229043746-2f91fcc9fbdb // indirect go.etcd.io/bbolt v1.3.6 // indirect go.opencensus.io v0.24.0 // indirect - go.opentelemetry.io/auto/sdk v1.1.0 // indirect + go.opentelemetry.io/auto/sdk v1.2.1 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect go.opentelemetry.io/proto/otlp v1.5.0 // indirect diff --git a/go.sum b/go.sum index bfe2498c..2ccdf344 100644 --- a/go.sum +++ b/go.sum @@ -304,6 +304,12 @@ github.com/getlantern/quicwrapper v0.0.0-20250417060014-acb01527c4c2 h1:4TMpZ++G github.com/getlantern/quicwrapper v0.0.0-20250417060014-acb01527c4c2/go.mod h1:8JUff02h2OIo2TSuJDJmTVphoh3MzeE7V5gbjPa+r0w= github.com/getlantern/ratelimit v0.0.0-20220926192648-933ab81a6fc7 h1:47FJ5kTeXc3I1VPpi2hWW9I16/Y3K0cpUq/B7oWJGF8= github.com/getlantern/ratelimit v0.0.0-20220926192648-933ab81a6fc7/go.mod h1:OOqKCIkspqXtIWEex4uhH1H9l7NGekT9i3Hs591ZDk4= +github.com/getlantern/semconv v0.0.0-20260327033412-364dfaa6b6ec h1:lPQMlQuENIRaBFS1aFHuyTJ0nFpNuxMXau+5KUyznKY= +github.com/getlantern/semconv v0.0.0-20260327033412-364dfaa6b6ec/go.mod h1:GkPT5P9JoOTIRXRmFWxYgu1hhXgTFFTNc2hoG7WQc3g= +github.com/getlantern/semconv v0.0.0-20260327035242-c93140b6acf3 h1:0xOiOarpwjmO+5dH/W456yXgHPbTB28qAjhQUGvcp0w= +github.com/getlantern/semconv v0.0.0-20260327035242-c93140b6acf3/go.mod h1:GkPT5P9JoOTIRXRmFWxYgu1hhXgTFFTNc2hoG7WQc3g= +github.com/getlantern/semconv v0.0.0-20260327040646-21845dda05cb h1:c5YM7b3a4r2J8Eh89KkI6M/iTFe6Bi+b8AJlfkKdFq4= +github.com/getlantern/semconv v0.0.0-20260327040646-21845dda05cb/go.mod h1:GkPT5P9JoOTIRXRmFWxYgu1hhXgTFFTNc2hoG7WQc3g= github.com/getlantern/sing-vmess v0.0.0-20241209111030-0f2c02b4eb9a h1:EaWmH5vANbKEXCdfgTChyEpWWwLsSrLPKqO6j0h+IB8= github.com/getlantern/sing-vmess v0.0.0-20241209111030-0f2c02b4eb9a/go.mod h1:eyj3LXZUf1aYph1WD19MKwbj5kMUQR92WBQfOAYpb/4= github.com/getlantern/telemetry v0.0.0-20250606052628-8960164ec1f5 h1:6ITBYqNkLbVZ1tQNXwmH8N80rZtvyW6IZa8L6EAhBQo= @@ -341,8 +347,8 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9 github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= -github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= +github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= @@ -635,8 +641,8 @@ github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 h1:f/FNXud6gA3MNr github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3/go.mod h1:HgjTstvQsPGkxUsCd2KWxErBblirPizecHcpD3ffK+s= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= -github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII= -github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o= +github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= +github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= github.com/rs/dnscache v0.0.0-20211102005908-e0241e321417 h1:Lt9DzQALzHoDwMBGJ6v8ObDPR0dzr2a6sXTB1Fq7IHs= github.com/rs/dnscache v0.0.0-20211102005908-e0241e321417/go.mod h1:qe5TWALJ8/a1Lqznoc5BDHpYX/8HU60Hm2AwRmqzxqA= github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46 h1:GHRpF1pTW19a8tTFrMLUcfWwyC0pnifVo2ClaLq+hP8= @@ -675,8 +681,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/templexxx/cpu v0.0.1/go.mod h1:w7Tb+7qgcAlIyX4NhLuDKt78AHA5SzPmq0Wj6HiEnnk= github.com/templexxx/cpu v0.0.8 h1:va6GebSxedVdR5XEyPJD49t94p5ZsjWO6Wh/PfbmZnc= github.com/templexxx/cpu v0.0.8/go.mod h1:w7Tb+7qgcAlIyX4NhLuDKt78AHA5SzPmq0Wj6HiEnnk= @@ -734,30 +740,30 @@ go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= -go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= -go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= +go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= +go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 h1:4Pp6oUg3+e/6M4C0A/3kJ2VYa++dsWVTtGgLVj5xtHg= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0/go.mod h1:Mjt1i1INqiaoZOMGR1RIUJN+i3ChKoFRqzrRQhlkbs0= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 h1:jq9TW8u3so/bN+JPT166wjOI6/vQPF6Xe7nMNIltagk= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0/go.mod h1:p8pYQP+m5XfbZm9fxtSKAbM6oIllS7s2AfxrChvc7iw= go.opentelemetry.io/otel v1.9.0/go.mod h1:np4EoPGzoPs3O67xUVNoPPcmSvsfOxNlNA4F4AC+0Eo= -go.opentelemetry.io/otel v1.36.0 h1:UumtzIklRBY6cI/lllNZlALOF5nNIzJVb16APdvgTXg= -go.opentelemetry.io/otel v1.36.0/go.mod h1:/TcFMXYjyRNh8khOAO9ybYkqaDBb/70aVwkNML4pP8E= +go.opentelemetry.io/otel v1.38.0 h1:RkfdswUDRimDg0m2Az18RKOsnI8UDzppJAtj01/Ymk8= +go.opentelemetry.io/otel v1.38.0/go.mod h1:zcmtmQ1+YmQM9wrNsTGV/q/uyusom3P8RxwExxkZhjM= go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.35.0 h1:0NIXxOCFx+SKbhCVxwl3ETG8ClLPAa0KuKV6p3yhxP8= go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.35.0/go.mod h1:ChZSJbbfbl/DcRZNc9Gqh6DYGlfjw4PvO1pEOZH1ZsE= go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.35.0 h1:1fTNlAIJZGWLP5FVu0fikVry1IsiUnXjf7QFvoNN3Xw= go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.35.0/go.mod h1:zjPK58DtkqQFn+YUMbx0M2XV3QgKU0gS9LeGohREyK4= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.35.0 h1:xJ2qHD0C1BeYVTLLR9sX12+Qb95kfeD/byKj6Ky1pXg= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.35.0/go.mod h1:u5BF1xyjstDowA1R5QAO9JHzqK+ublenEW/dyqTjBVk= -go.opentelemetry.io/otel/metric v1.36.0 h1:MoWPKVhQvJ+eeXWHFBOPoBOi20jh6Iq2CcCREuTYufE= -go.opentelemetry.io/otel/metric v1.36.0/go.mod h1:zC7Ks+yeyJt4xig9DEw9kuUFe5C3zLbVjV2PzT6qzbs= +go.opentelemetry.io/otel/metric v1.38.0 h1:Kl6lzIYGAh5M159u9NgiRkmoMKjvbsKtYRwgfrA6WpA= +go.opentelemetry.io/otel/metric v1.38.0/go.mod h1:kB5n/QoRM8YwmUahxvI3bO34eVtQf2i4utNVLr9gEmI= go.opentelemetry.io/otel/sdk v1.35.0 h1:iPctf8iprVySXSKJffSS79eOjl9pvxV9ZqOWT0QejKY= go.opentelemetry.io/otel/sdk v1.35.0/go.mod h1:+ga1bZliga3DxJ3CQGg3updiaAJoNECOgJREo9KHGQg= go.opentelemetry.io/otel/sdk/metric v1.35.0 h1:1RriWBmCKgkeHEhM7a2uMjMUfP7MsOF5JpUCaEqEI9o= go.opentelemetry.io/otel/sdk/metric v1.35.0/go.mod h1:is6XYCUMpcKi+ZsOvfluY5YstFnhW0BidkR+gL+qN+w= go.opentelemetry.io/otel/trace v1.9.0/go.mod h1:2737Q0MuG8q1uILYm2YYVkAyLtOofiTNGg6VODnOiPo= -go.opentelemetry.io/otel/trace v1.36.0 h1:ahxWNuqZjpdiFAyrIoQ4GIiAIhxAunQR6MUoKrsNd4w= -go.opentelemetry.io/otel/trace v1.36.0/go.mod h1:gQ+OnDZzrybY4k4seLzPAWNwVBBVlF2szhehOBB/tGA= +go.opentelemetry.io/otel/trace v1.38.0 h1:Fxk5bKrDZJUH+AMyyIXGcFAPah0oRcT+LuNtJrmcNLE= +go.opentelemetry.io/otel/trace v1.38.0/go.mod h1:j1P9ivuFsTceSWe1oY+EeW3sc+Pp42sO++GHkg4wwhs= go.opentelemetry.io/proto/otlp v1.5.0 h1:xJvq7gMzB31/d406fB8U5CBdyQGw4P399D1aQWU/3i4= go.opentelemetry.io/proto/otlp v1.5.0/go.mod h1:keN8WnHxOy8PG0rQZjJJ5A2ebUoafqWp0eVQ4yIXvJ4= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= diff --git a/instrument/instrument.go b/instrument/instrument.go index e76a1c10..051d9326 100644 --- a/instrument/instrument.go +++ b/instrument/instrument.go @@ -9,6 +9,7 @@ import ( "sync" "time" + semconv "github.com/getlantern/semconv" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" sdktrace "go.opentelemetry.io/otel/sdk/trace" @@ -16,7 +17,6 @@ import ( "github.com/getlantern/errors" "github.com/getlantern/geo" - "github.com/getlantern/http-proxy-lantern/v2/common" "github.com/getlantern/http-proxy-lantern/v2/instrument/otelinstrument" "github.com/getlantern/multipath" "github.com/getlantern/proxy/v3/filters" @@ -183,13 +183,13 @@ func (ins *defaultInstrument) WrapConnErrorHandler(prefix string, f func(conn ne // Blacklist instruments the blacklist checking. func (ins *defaultInstrument) Blacklist(ctx context.Context, b bool) { otelinstrument.Blacklist.Add(ctx, 1, - metric.WithAttributes(attribute.KeyValue{"blacklisted", attribute.BoolValue(b)})) + metric.WithAttributes(attribute.Bool("blacklisted", b))) } // Mimic instruments the Apache mimicry. func (ins *defaultInstrument) Mimic(ctx context.Context, m bool) { otelinstrument.Mimicked.Add(ctx, 1, metric.WithAttributes( - attribute.KeyValue{"mimicked", attribute.BoolValue(m)})) + attribute.Bool("mimicked", m))) if m { otelinstrument.Mimicked.Add(ctx, 1) @@ -200,8 +200,8 @@ func (ins *defaultInstrument) Mimic(ctx context.Context, m bool) { func (ins *defaultInstrument) Throttle(ctx context.Context, m bool, reason string) { otelinstrument.Throttling.Add(ctx, 1, metric.WithAttributes( - attribute.KeyValue{"throttled", attribute.BoolValue(m)}, - attribute.KeyValue{"reason", attribute.StringValue(reason)}, + attribute.Bool("throttled", m), + attribute.String("reason", reason), )) } @@ -219,8 +219,8 @@ func (ins *defaultInstrument) SuspectedProbing(ctx context.Context, fromIP net.I ctx, 1, metric.WithAttributes( - attribute.KeyValue{"country", attribute.StringValue(fromCountry)}, - attribute.KeyValue{"reason", attribute.StringValue(reason)}, + semconv.GeoCountryISOCodeKey.String(fromCountry), + attribute.String("reason", reason), ), ) } @@ -237,24 +237,25 @@ func (ins *defaultInstrument) ProxiedBytes(ctx context.Context, sent, recv int, isp := ins.ispLookup.ISP(clientIP) asn := ins.ispLookup.ASN(clientIP) - otelAttributes := []attribute.KeyValue{ - {common.Platform, attribute.StringValue(platform)}, - {common.PlatformVersion, attribute.StringValue(platformVersion)}, - {common.KernelArch, attribute.StringValue(arch)}, - {common.LibraryVersion, attribute.StringValue(libVersion)}, - {common.AppVersion, attribute.StringValue(appVersion)}, - {common.App, attribute.StringValue(app)}, - {"datacap_cohort", attribute.StringValue(dataCapCohort)}, - {"country", attribute.StringValue(country)}, - {"client_isp", attribute.StringValue(isp)}, - {"client_asn", attribute.StringValue(asn)}, + otelAttrs := []attribute.KeyValue{ + semconv.ClientPlatformKey.String(platform), + attribute.String("client.platform_version", platformVersion), + attribute.String("client.kernel_arch", arch), + attribute.String("client.library_version", libVersion), + semconv.ClientVersionKey.String(appVersion), + semconv.ClientAppKey.String(app), + attribute.String("datacap_cohort", dataCapCohort), + semconv.GeoCountryISOCodeKey.String(country), + semconv.ClientISPKey.String(isp), + semconv.ClientAsnKey.String(asn), } otelinstrument.ProxyIO.Add( ctx, int64(sent), metric.WithAttributes( - append(otelAttributes, attribute.KeyValue{"direction", attribute.StringValue("transmit")})..., + append(otelAttrs, + semconv.NetworkIODirectionKey.String("transmit"))..., ), ) @@ -262,7 +263,8 @@ func (ins *defaultInstrument) ProxiedBytes(ctx context.Context, sent, recv int, ctx, int64(recv), metric.WithAttributes( - append(otelAttributes, attribute.KeyValue{"direction", attribute.StringValue("receive")})..., + append(otelAttrs, + semconv.NetworkIODirectionKey.String("receive"))..., ), ) @@ -308,18 +310,18 @@ func (ins *defaultInstrument) Connection(ctx context.Context, clientIP net.IP) { fromCountry := ins.countryLookup.CountryCode(clientIP) otelinstrument.Connections.Add(ctx, 1, metric.WithAttributes( - attribute.KeyValue{"country", attribute.StringValue(fromCountry)}, - attribute.KeyValue{"proxy.name", attribute.StringValue(ins.proxyName)}, + semconv.GeoCountryISOCodeKey.String(fromCountry), + semconv.ProxyNameKey.String(ins.proxyName), )) } // quicPackets is used by QuicTracer to update QUIC retransmissions mainly for block detection. func (ins *defaultInstrument) quicSentPacket(ctx context.Context) { - otelinstrument.QuicPackets.Add(ctx, 1, metric.WithAttributes(attribute.KeyValue{"state", attribute.StringValue("sent")})) + otelinstrument.QuicPackets.Add(ctx, 1, metric.WithAttributes(attribute.String("state", "sent"))) } func (ins *defaultInstrument) quicLostPacket(ctx context.Context) { - otelinstrument.QuicPackets.Add(ctx, 1, metric.WithAttributes(attribute.KeyValue{"state", attribute.StringValue("lost")})) + otelinstrument.QuicPackets.Add(ctx, 1, metric.WithAttributes(attribute.String("state", "lost"))) } type stats struct { @@ -328,25 +330,25 @@ type stats struct { func (s *stats) OnRecv(n uint64) { otelinstrument.MultipathFrames.Add(context.Background(), 1, - metric.WithAttributes(append(s.otelAttributes, attribute.KeyValue{"direction", attribute.StringValue("receive")})...)) + metric.WithAttributes(append(s.otelAttributes, semconv.NetworkIODirectionKey.String("receive"))...)) otelinstrument.MultipathIO.Add(context.Background(), int64(n), - metric.WithAttributes(append(s.otelAttributes, attribute.KeyValue{"direction", attribute.StringValue("receive")})...)) + metric.WithAttributes(append(s.otelAttributes, semconv.NetworkIODirectionKey.String("receive"))...)) } func (s *stats) OnSent(n uint64) { otelinstrument.MultipathFrames.Add(context.Background(), 1, - metric.WithAttributes(append(s.otelAttributes, attribute.KeyValue{"direction", attribute.StringValue("transmit")})...)) + metric.WithAttributes(append(s.otelAttributes, semconv.NetworkIODirectionKey.String("transmit"))...)) otelinstrument.MultipathIO.Add(context.Background(), int64(n), - metric.WithAttributes(append(s.otelAttributes, attribute.KeyValue{"direction", attribute.StringValue("transmit")})...)) + metric.WithAttributes(append(s.otelAttributes, semconv.NetworkIODirectionKey.String("transmit"))...)) } func (s *stats) OnRetransmit(n uint64) { otelinstrument.MultipathFrames.Add(context.Background(), 1, metric.WithAttributes(append(s.otelAttributes, - attribute.KeyValue{"direction", attribute.StringValue("transmit")}, - attribute.KeyValue{"state", attribute.StringValue("retransmit")})...)) + semconv.NetworkIODirectionKey.String("transmit"), + attribute.String("state", "retransmit"))...)) otelinstrument.MultipathIO.Add(context.Background(), int64(n), metric.WithAttributes(append(s.otelAttributes, - attribute.KeyValue{"direction", attribute.StringValue("transmit")}, - attribute.KeyValue{"state", attribute.StringValue("retransmit")})...)) + semconv.NetworkIODirectionKey.String("transmit"), + attribute.String("state", "retransmit"))...)) } func (s *stats) UpdateRTT(time.Duration) { // do nothing as the RTT from different clients can vary significantly @@ -356,7 +358,7 @@ func (ins *defaultInstrument) MultipathStats(protocols []string) (trackers []mul for _, p := range protocols { trackers = append(trackers, &stats{ otelAttributes: []attribute.KeyValue{ - {"path_protocol", attribute.StringValue(p)}}, + attribute.String("path_protocol", p)}, }) } return @@ -424,15 +426,15 @@ func (ins *defaultInstrument) ReportProxiedBytes(tp *sdktrace.TracerProvider) { attribute.Int("bytes_sent", value.sent), attribute.Int("bytes_recv", value.recv), attribute.Int("bytes_total", value.sent+value.recv), - attribute.String(common.DeviceID, key.deviceID), - attribute.String(common.Platform, key.platform), - attribute.String(common.LibraryVersion, key.libVersion), - attribute.String(common.AppVersion, key.appVersion), - attribute.String(common.Locale, key.locale), - attribute.String("client_country", key.country), - attribute.String("client_isp", key.isp), - attribute.String("client_asn", key.asn), - attribute.String(common.ProbingError, key.probingError))) + semconv.ClientDeviceIDKey.String(key.deviceID), + semconv.ClientPlatformKey.String(key.platform), + attribute.String("client.library_version", key.libVersion), + semconv.ClientVersionKey.String(key.appVersion), + attribute.String("client.locale", key.locale), + semconv.GeoCountryISOCodeKey.String(key.country), + semconv.ClientISPKey.String(key.isp), + semconv.ClientAsnKey.String(key.asn), + attribute.String("probing.error", key.probingError))) span.End() } } @@ -465,9 +467,9 @@ func (ins *defaultInstrument) ReportOriginBytes(tp *sdktrace.TracerProvider) { attribute.Int("origin_bytes_recv", value.recv), attribute.Int("origin_bytes_total", value.sent+value.recv), attribute.String("origin", key.origin), - attribute.String("client_platform", key.platform), - attribute.String("client_version", key.version), - attribute.String("client_country", key.country))) + semconv.ClientPlatformKey.String(key.platform), + attribute.String("client.library_version", key.version), + semconv.GeoCountryISOCodeKey.String(key.country))) span.End() } } diff --git a/otel/otel.go b/otel/otel.go index 2157ac09..4d53f3c3 100644 --- a/otel/otel.go +++ b/otel/otel.go @@ -5,6 +5,7 @@ import ( "strings" "time" + semconv "github.com/getlantern/semconv" sdkotel "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp" @@ -14,7 +15,6 @@ import ( "go.opentelemetry.io/otel/sdk/metric/metricdata" "go.opentelemetry.io/otel/sdk/resource" sdktrace "go.opentelemetry.io/otel/sdk/trace" - semconv "go.opentelemetry.io/otel/semconv/v1.7.0" "github.com/getlantern/golog" ) @@ -44,47 +44,35 @@ type Opts struct { } func (opts *Opts) buildResource() *resource.Resource { - attributes := []attribute.KeyValue{ + attrs := []attribute.KeyValue{ semconv.ServiceNameKey.String("http-proxy-lantern"), - attribute.String("protocol", opts.ProxyProtocol), - attribute.Bool("pro", opts.IsPro), + semconv.ProxyProtocolKey.String(opts.ProxyProtocol), + semconv.ClientIsProKey.Bool(opts.IsPro), attribute.Bool("legacy", opts.Legacy), } - // Disable reporting proxy port for Datadog cost reasons - // parts := strings.Split(opts.Addr, ":") - // if len(parts) == 2 { - // _port := parts[1] - // port, err := strconv.Atoi(_port) - // if err == nil { - // log.Debugf("will report with proxy.port %d", port) - // attributes = append(attributes, attribute.Int("proxy.port", port)) - // } else { - // log.Errorf("Unable to parse proxy.port %v: %v", _port, err) - // } - // } else { - // log.Errorf("Unable to split proxy address %v into two pieces", opts.Addr) - // } if opts.Track != "" { - attributes = append(attributes, attribute.String("track", opts.Track)) + attrs = append(attrs, + semconv.ProxyTrackKey.String(opts.Track)) } if opts.ProxyName != "" { - log.Debugf("Will report with proxy.name %v", opts.ProxyName) - attributes = append(attributes, attribute.String("proxy.name", opts.ProxyName)) + attrs = append(attrs, + semconv.ProxyNameKey.String(opts.ProxyName)) } if opts.Provider != "" { - log.Debugf("Will report with provider %v", opts.Provider) - attributes = append(attributes, attribute.String("provider", opts.Provider)) + attrs = append(attrs, + semconv.ProxyProviderKey.String(opts.Provider)) } if opts.DC != "" { - log.Debugf("Will report with dc %v", opts.DC) - attributes = append(attributes, attribute.String("dc", opts.DC)) + attrs = append(attrs, attribute.String("dc", opts.DC)) } if opts.FrontendProvider != "" { - log.Debugf("Will report frontend provider %v in dc %v", opts.FrontendProvider, opts.FrontendDC) - attributes = append(attributes, attribute.String("frontend.provider", opts.FrontendProvider)) - attributes = append(attributes, attribute.String("frontend.dc", opts.FrontendDC)) + attrs = append(attrs, + semconv.ProxyFrontendProviderKey.String(opts.FrontendProvider), + attribute.String("frontend.dc", opts.FrontendDC), + ) } - return resource.NewWithAttributes(semconv.SchemaURL, attributes...) + log.Debugf("Resource attributes: %v", attrs) + return resource.NewWithAttributes(semconv.SchemaURL, attrs...) } func BuildTracerProvider(opts *Opts) (*sdktrace.TracerProvider, func()) {