Skip to content

Commit dd98d3c

Browse files
committed
feat: Add support for tracing
Signed-off-by: Bilal Hussain <[email protected]>
1 parent cf2c4a9 commit dd98d3c

18 files changed

+651
-37
lines changed

.github/workflows/linkinator.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ jobs:
1919
paths: "**/*.md"
2020
markdown: true
2121
retry: true
22-
linksToSkip: "https://github.com/kedacore/http-add-on/pkgs/container/http-add-on-interceptor, https://github.com/kedacore/http-add-on/pkgs/container/http-add-on-operator, https://github.com/kedacore/http-add-on/pkgs/container/http-add-on-scaler, http://opentelemetry-collector.open-telemetry-system:4318"
22+
linksToSkip: "https://github.com/kedacore/http-add-on/pkgs/container/http-add-on-interceptor, https://github.com/kedacore/http-add-on/pkgs/container/http-add-on-operator, https://github.com/kedacore/http-add-on/pkgs/container/http-add-on-scaler,http://opentelemetry-collector.open-telemetry-system:4318,http://opentelemetry-collector.open-telemetry-system:4318/v1/traces"

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ This changelog keeps track of work items that have been completed and are ready
2323

2424
### New
2525

26+
- **General**: Add configurable tracing support to the interceptor proxy ([#1021](https://github.com/kedacore/http-add-on/pull/1021))
2627
- **General**: TODO ([#TODO](https://github.com/kedacore/http-add-on/issues/TODO))
2728

2829
### Improvements

config/interceptor/e2e-test/otel/deployment.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@ spec:
1919
value: "http://opentelemetry-collector.open-telemetry-system:4318"
2020
- name: OTEL_METRIC_EXPORT_INTERVAL
2121
value: "1"
22+
- name: OTEL_EXPORTER_OTLP_TRACES_ENABLED
23+
value: "true"
24+
- name: OTEL_EXPORTER_OTLP_TRACES_PROTOCOL
25+
value: "http/protobuf"
26+
- name: OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
27+
value: "http://opentelemetry-collector.open-telemetry-system:4318/v1/traces"
28+
- name: OTEL_EXPORTER_OTLP_TRACES_INSECURE
29+
value: "true"

docs/operate.md

+28
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,31 @@ If you need to provide any headers such as authentication details in order to ut
2323
The interceptor proxy has the ability to run both a HTTP and HTTPS server simultaneously to allow you to scale workloads that use either protocol. By default, the interceptor proxy will only serve over HTTP, but this behavior can be changed by configuring the appropriate environment variables on the deployment.
2424

2525
The TLS server can be enabled by setting the environment variable `KEDA_HTTP_PROXY_TLS_ENABLED` to `true` on the interceptor deployment (`false` by default). The TLS server will start on port `8443` by default, but this can be configured by setting `KEDA_HTTP_PROXY_TLS_PORT` to your desired port number. The TLS server will require valid TLS certificates to start, the path to the certificates can be configured via the `KEDA_HTTP_PROXY_TLS_CERT_PATH` and `KEDA_HTTP_PROXY_TLS_KEY_PATH` environment variables (`/certs/tls.crt` and `/certs/tls.key` by default).
26+
27+
# Configuring tracing for the KEDA HTTP Add-on interceptor proxy
28+
29+
### Supported Exporters:
30+
* **console** - The console exporter is useful for development and debugging tasks, and is the simplest to set up.
31+
* **http/protobuf** - To send trace data to an OTLP endpoint (like the collector or Jaeger >= v1.35.0) you’ll want to configure an OTLP exporter that sends to your endpoint.
32+
* * **grpc** - To configure exporter to send trace data over gRPC connection to an OTLP endpoint (like the collector or Jaeger >= v1.35.0) you’ll want to configure an OTLP exporter that sends to your endpoint.
33+
34+
### Configuring tracing with console exporter
35+
36+
To enable tracing with the console exporter, the `OTEL_EXPORTER_OTLP_TRACES_ENABLED` environment variable should be set to `true` on the interceptor deployment. (`false` by default).
37+
Secondly set `OTEL_EXPORTER_OTLP_TRACES_PROTOCOL` to `console` (`console` by default). Other protocols include (`http/protobuf` and `grpc`).
38+
Finally set `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` to `"http://localhost:4318/v1/traces"` (`"http://localhost:4318/v1/traces"` by default).
39+
40+
41+
### Configuring tracing with OTLP exporter
42+
When configured, the interceptor proxy can export metrics to a OTEL HTTP collector.
43+
44+
To enable tracing with otlp exporter, the `OTEL_EXPORTER_OTLP_TRACES_ENABLED` environment variable should be set to `true` on the interceptor deployment. (`false` by default).
45+
Secondly set `OTEL_EXPORTER_OTLP_TRACES_PROTOCOL` to `otlphttp` (`console` by default). Other protocols include (`http/protobuf` and `grpc`)
46+
Finally set `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` to the collector to send the traces to (e.g. http://opentelemetry-collector.open-telemetry-system:4318/v1/traces) (`"http://localhost:4318/v1/traces"` by default).
47+
NOTE: full path is required to be set including <scheme><url><port><path>
48+
49+
50+
Optional variables
51+
`OTEL_EXPORTER_OTLP_HEADERS` - To pass any extra headers to the spans to utilise your OTEL collector e.g. authentication details (`"key1=value1,key2=value2"`)
52+
`OTEL_EXPORTER_OTLP_TRACES_INSECURE` - To send traces to the tracing via HTTP rather than HTTPS (`false` by default)
53+
`OTEL_EXPORTER_OTLP_TRACES_TIMEOUT` - The batcher timeout in seconds to send batch of data points (`5` by default)

go.mod

+23-14
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,26 @@ require (
66
github.com/go-logr/logr v1.4.2
77
github.com/google/go-cmp v0.6.0
88
github.com/hashicorp/go-immutable-radix/v2 v2.1.0
9-
github.com/kedacore/keda/v2 v2.14.1-0.20240429185716-c55e306af94b
9+
github.com/kedacore/keda/v2 v2.14.0
1010
github.com/kelseyhightower/envconfig v1.4.0
1111
github.com/onsi/ginkgo/v2 v2.19.0
1212
github.com/onsi/gomega v1.33.1
1313
github.com/stretchr/testify v1.9.0
14+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0
1415
go.opentelemetry.io/otel v1.27.0
1516
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.27.0
17+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.22.0
18+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0
19+
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.24.0
1620
go.opentelemetry.io/otel/sdk v1.27.0
21+
go.opentelemetry.io/otel/trace v1.27.0
1722
go.uber.org/mock v0.4.0
1823
golang.org/x/sync v0.7.0
1924
google.golang.org/grpc v1.64.0
2025
google.golang.org/protobuf v1.34.1
2126
k8s.io/api v0.29.4
2227
k8s.io/apimachinery v0.29.4
23-
k8s.io/client-go v0.29.4
28+
k8s.io/client-go v1.5.2
2429
k8s.io/code-generator v0.29.4
2530
k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0
2631
sigs.k8s.io/controller-runtime v0.17.5
@@ -44,6 +49,21 @@ require (
4449
github.com/beorn7/perks v1.0.1 // indirect
4550
github.com/blang/semver/v4 v4.0.0 // indirect
4651
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
52+
github.com/felixge/httpsnoop v1.0.4 // indirect
53+
github.com/go-logr/stdr v1.2.2 // indirect
54+
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
55+
github.com/gorilla/websocket v1.5.1 // indirect
56+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
57+
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
58+
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
59+
go.uber.org/zap v1.27.0 // indirect
60+
google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 // indirect
61+
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
62+
k8s.io/component-base v0.29.4 // indirect
63+
k8s.io/gengo v0.0.0-20240129211411-f967bbeff4b4 // indirect
64+
)
65+
66+
require (
4767
github.com/cespare/xxhash/v2 v2.3.0 // indirect
4868
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
4969
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
@@ -52,12 +72,10 @@ require (
5272
github.com/expr-lang/expr v1.16.9 // indirect
5373
github.com/fsnotify/fsnotify v1.7.0 // indirect
5474
github.com/go-errors/errors v1.5.1 // indirect
55-
github.com/go-logr/stdr v1.2.2 // indirect
5675
github.com/go-logr/zapr v1.3.0 // indirect
5776
github.com/go-openapi/jsonpointer v0.21.0 // indirect
5877
github.com/go-openapi/jsonreference v0.21.0 // indirect
5978
github.com/go-openapi/swag v0.23.0 // indirect
60-
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
6179
github.com/gogo/protobuf v1.3.2 // indirect
6280
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
6381
github.com/golang/protobuf v1.5.4 // indirect
@@ -66,8 +84,6 @@ require (
6684
github.com/google/pprof v0.0.0-20240528025155-186aa0362fba // indirect
6785
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
6886
github.com/google/uuid v1.6.0 // indirect
69-
github.com/gorilla/websocket v1.5.1 // indirect
70-
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
7187
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
7288
github.com/imdario/mergo v0.3.16 // indirect
7389
github.com/inconshreveable/mousetrap v1.1.0 // indirect
@@ -79,7 +95,6 @@ require (
7995
github.com/modern-go/reflect2 v1.0.2 // indirect
8096
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
8197
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
82-
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
8398
github.com/pkg/errors v0.9.1 // indirect
8499
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
85100
github.com/prometheus/client_golang v1.19.0
@@ -89,14 +104,12 @@ require (
89104
github.com/spf13/cobra v1.8.0 // indirect
90105
github.com/spf13/pflag v1.0.5 // indirect
91106
github.com/xlab/treeprint v1.2.0 // indirect
107+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 // indirect
92108
go.opentelemetry.io/otel/exporters/prometheus v0.45.1
93109
go.opentelemetry.io/otel/metric v1.27.0
94110
go.opentelemetry.io/otel/sdk/metric v1.27.0
95-
go.opentelemetry.io/otel/trace v1.27.0 // indirect
96-
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
97111
go.starlark.net v0.0.0-20231121155337-90ade8b19d09 // indirect
98112
go.uber.org/multierr v1.11.0 // indirect
99-
go.uber.org/zap v1.27.0 // indirect
100113
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
101114
golang.org/x/mod v0.18.0 // indirect
102115
golang.org/x/net v0.25.0 // indirect
@@ -107,15 +120,11 @@ require (
107120
golang.org/x/time v0.5.0 // indirect
108121
golang.org/x/tools v0.21.0 // indirect
109122
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
110-
google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 // indirect
111123
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect
112-
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
113124
gopkg.in/inf.v0 v0.9.1 // indirect
114125
gopkg.in/yaml.v2 v2.4.0 // indirect
115126
gopkg.in/yaml.v3 v3.0.1 // indirect
116127
k8s.io/apiextensions-apiserver v0.29.4 // indirect
117-
k8s.io/component-base v0.29.4 // indirect
118-
k8s.io/gengo v0.0.0-20240129211411-f967bbeff4b4 // indirect
119128
k8s.io/klog/v2 v2.120.1 // indirect
120129
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
121130
knative.dev/pkg v0.0.0-20240423132823-3c6badc82748 // indirect

go.sum

+14-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0
2121
github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ=
2222
github.com/expr-lang/expr v1.16.9 h1:WUAzmR0JNI9JCiF0/ewwHB1gmcGw5wW7nWt8gc6PpCI=
2323
github.com/expr-lang/expr v1.16.9/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
24+
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
25+
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
2426
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
2527
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
2628
github.com/go-errors/errors v1.5.1 h1:ZwEMSLRCapFLflTpT7NKaAc7ukJ8ZPEjzlxt8rPN8bk=
@@ -82,8 +84,8 @@ github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8Hm
8284
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
8385
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
8486
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
85-
github.com/kedacore/keda/v2 v2.14.1-0.20240429185716-c55e306af94b h1:FCGepXWVVCrqPDhPFFAuMyeJfgC7bcu1GFgQQsXESVA=
86-
github.com/kedacore/keda/v2 v2.14.1-0.20240429185716-c55e306af94b/go.mod h1:V03Uj1+jxKYAzqa09FSwlEzqj8HfYeXM6yhH4gm4PyA=
87+
github.com/kedacore/keda/v2 v2.14.0 h1:0vxF1cEbEcAVWwbSHzgmanA43Hnnz5oGZZPN9yC7/rg=
88+
github.com/kedacore/keda/v2 v2.14.0/go.mod h1:Gk8Bm9uiiQcUwhS31Aib72y+9K4LvBaMPZuA1n3kKR8=
8789
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
8890
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
8991
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
@@ -147,12 +149,22 @@ github.com/xlab/treeprint v1.2.0 h1:HzHnuAF1plUN2zGlAFHbSQP2qJ0ZAD3XF5XD7OesXRQ=
147149
github.com/xlab/treeprint v1.2.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0=
148150
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
149151
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
152+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 h1:jq9TW8u3so/bN+JPT166wjOI6/vQPF6Xe7nMNIltagk=
153+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0/go.mod h1:p8pYQP+m5XfbZm9fxtSKAbM6oIllS7s2AfxrChvc7iw=
150154
go.opentelemetry.io/otel v1.27.0 h1:9BZoF3yMK/O1AafMiQTVu0YDj5Ea4hPhxCs7sGva+cg=
151155
go.opentelemetry.io/otel v1.27.0/go.mod h1:DMpAK8fzYRzs+bi3rS5REupisuqTheUlSZJ1WnZaPAQ=
152156
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.27.0 h1:CIHWikMsN3wO+wq1Tp5VGdVRTcON+DmOJSfDjXypKOc=
153157
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.27.0/go.mod h1:TNupZ6cxqyFEpLXAZW7On+mLFL0/g0TE3unIYL91xWc=
158+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 h1:t6wl9SPayj+c7lEIFgm4ooDBZVb01IhLB4InpomhRw8=
159+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0/go.mod h1:iSDOcsnSA5INXzZtwaBPrKp/lWu/V14Dd+llD0oI2EA=
160+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.22.0 h1:H2JFgRcGiyHg7H7bwcwaQJYrNFqCqrbTQ8K4p1OvDu8=
161+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.22.0/go.mod h1:WfCWp1bGoYK8MeULtI15MmQVczfR+bFkk0DF3h06QmQ=
162+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0 h1:Xw8U6u2f8DK2XAkGRFV7BBLENgnTGX9i4rQRxJf+/vs=
163+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0/go.mod h1:6KW1Fm6R/s6Z3PGXwSJN2K4eT6wQB3vXX6CVnYX9NmM=
154164
go.opentelemetry.io/otel/exporters/prometheus v0.45.1 h1:R/bW3afad6q6VGU+MFYpnEdo0stEARMCdhWu6+JI6aI=
155165
go.opentelemetry.io/otel/exporters/prometheus v0.45.1/go.mod h1:wnHAfKRav5Dfp4iZhyWZ7SzQfT+rDZpEpYG7To+qJ1k=
166+
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.24.0 h1:s0PHtIkN+3xrbDOpt2M8OTG92cWqUESvzh2MxiR5xY8=
167+
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.24.0/go.mod h1:hZlFbDbRt++MMPCCfSJfmhkGIWnX1h3XjkfxZUjLrIA=
156168
go.opentelemetry.io/otel/metric v1.27.0 h1:hvj3vdEKyeCi4YaYfNjv2NUje8FqKqUY8IlF0FxV/ik=
157169
go.opentelemetry.io/otel/metric v1.27.0/go.mod h1:mVFgmRlhljgBiuk/MP/oKylr4hs85GZAylncepAX/ak=
158170
go.opentelemetry.io/otel/sdk v1.27.0 h1:mlk+/Y1gLPLn84U4tI8d3GNJmGT/eXe3ZuOXN9kTWmI=

interceptor/config/tracing.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package config
2+
3+
import (
4+
"github.com/kelseyhightower/envconfig"
5+
)
6+
7+
// Tracing is the configuration for configuring tracing through the interceptor.
8+
type Tracing struct {
9+
// States whether tracing should be enabled, False by default
10+
Enabled bool `envconfig:"OTEL_EXPORTER_OTLP_TRACES_ENABLED" default:"false"`
11+
// Sets what tracing export to use, must be one of: console,http/protobuf, grpc
12+
Exporter string `envconfig:"OTEL_EXPORTER_OTLP_TRACES_PROTOCOL" default:"console"`
13+
}
14+
15+
// Parse parses standard configs using envconfig and returns a pointer to the
16+
// newly created config. Returns nil and a non-nil error if parsing failed
17+
func MustParseTracing() *Tracing {
18+
ret := new(Tracing)
19+
envconfig.MustProcess("", ret)
20+
return ret
21+
}

interceptor/handler/upstream.go

+24-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ import (
55
"net/http"
66
"net/http/httputil"
77

8+
"go.opentelemetry.io/otel"
9+
"go.opentelemetry.io/otel/attribute"
10+
"go.opentelemetry.io/otel/propagation"
11+
"go.opentelemetry.io/otel/trace"
12+
13+
"github.com/kedacore/http-add-on/interceptor/config"
14+
"github.com/kedacore/http-add-on/interceptor/tracing"
815
"github.com/kedacore/http-add-on/pkg/util"
916
)
1017

@@ -14,11 +21,13 @@ var (
1421

1522
type Upstream struct {
1623
roundTripper http.RoundTripper
24+
tracingCfg *config.Tracing
1725
}
1826

19-
func NewUpstream(roundTripper http.RoundTripper) *Upstream {
27+
func NewUpstream(roundTripper http.RoundTripper, tracingCfg *config.Tracing) *Upstream {
2028
return &Upstream{
2129
roundTripper: roundTripper,
30+
tracingCfg: tracingCfg,
2231
}
2332
}
2433

@@ -28,6 +37,20 @@ func (uh *Upstream) ServeHTTP(w http.ResponseWriter, r *http.Request) {
2837
r = util.RequestWithLoggerWithName(r, "UpstreamHandler")
2938
ctx := r.Context()
3039

40+
if uh.tracingCfg.Enabled {
41+
p := tracing.NewPropagator()
42+
ctx = otel.GetTextMapPropagator().Extract(ctx, propagation.HeaderCarrier(r.Header))
43+
p.Inject(ctx, propagation.HeaderCarrier(w.Header()))
44+
45+
span := trace.SpanFromContext(ctx)
46+
defer span.End()
47+
48+
serviceValAttr := attribute.String("service", "keda-http-interceptor-proxy-upstream")
49+
coldStartValAttr := attribute.String("cold-start", w.Header().Get("X-KEDA-HTTP-Cold-Start"))
50+
51+
span.SetAttributes(serviceValAttr, coldStartValAttr)
52+
}
53+
3154
stream := util.StreamFromContext(ctx)
3255
if stream == nil {
3356
sh := NewStatic(http.StatusInternalServerError, errNilStream)

interceptor/handler/upstream_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestForwarderSuccess(t *testing.T) {
4343
timeouts := defaultTimeouts()
4444
dialCtxFunc := retryDialContextFunc(timeouts, timeouts.DefaultBackoff())
4545
rt := newRoundTripper(dialCtxFunc, timeouts.ResponseHeader)
46-
uh := NewUpstream(rt)
46+
uh := NewUpstream(rt, &config.Tracing{})
4747
uh.ServeHTTP(res, req)
4848

4949
r.True(
@@ -88,7 +88,7 @@ func TestForwarderHeaderTimeout(t *testing.T) {
8888
r.NoError(err)
8989
req = util.RequestWithStream(req, originURL)
9090
rt := newRoundTripper(dialCtxFunc, timeouts.ResponseHeader)
91-
uh := NewUpstream(rt)
91+
uh := NewUpstream(rt, &config.Tracing{})
9292
uh.ServeHTTP(res, req)
9393

9494
forwardedRequests := hdl.IncomingRequests()
@@ -138,7 +138,7 @@ func TestForwarderWaitsForSlowOrigin(t *testing.T) {
138138
r.NoError(err)
139139
req = util.RequestWithStream(req, originURL)
140140
rt := newRoundTripper(dialCtxFunc, timeouts.ResponseHeader)
141-
uh := NewUpstream(rt)
141+
uh := NewUpstream(rt, &config.Tracing{})
142142
uh.ServeHTTP(res, req)
143143
// wait for the goroutine above to finish, with a little cusion
144144
ensureSignalBeforeTimeout(originWaitCh, originDelay*2)
@@ -161,7 +161,7 @@ func TestForwarderConnectionRetryAndTimeout(t *testing.T) {
161161
r.NoError(err)
162162
req = util.RequestWithStream(req, noSuchURL)
163163
rt := newRoundTripper(dialCtxFunc, timeouts.ResponseHeader)
164-
uh := NewUpstream(rt)
164+
uh := NewUpstream(rt, &config.Tracing{})
165165

166166
start := time.Now()
167167
uh.ServeHTTP(res, req)
@@ -217,7 +217,7 @@ func TestForwardRequestRedirectAndHeaders(t *testing.T) {
217217
r.NoError(err)
218218
req = util.RequestWithStream(req, srvURL)
219219
rt := newRoundTripper(dialCtxFunc, timeouts.ResponseHeader)
220-
uh := NewUpstream(rt)
220+
uh := NewUpstream(rt, &config.Tracing{})
221221
uh.ServeHTTP(res, req)
222222
r.Equal(301, res.Code)
223223
r.Equal("abc123.com", res.Header().Get("Location"))

0 commit comments

Comments
 (0)