Skip to content

Commit 1bfa322

Browse files
committed
chore: add proxied-by header
1 parent 368539b commit 1bfa322

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

common/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"github.com/3box/go-proxy/common/logging"
1010
)
1111

12+
const ServiceName = "go-proxy"
13+
1214
const (
1315
defaultProxyListenPort = "8080"
1416
defaultMetricsListenPort = "9464"

common/metric/otel.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ import (
1515

1616
"github.com/gin-gonic/gin"
1717

18+
"github.com/3box/go-proxy/common/config"
1819
"github.com/3box/go-proxy/common/logging"
1920
)
2021

21-
const serviceName = "go-proxy"
22-
2322
var _ MetricService = &otelMetricService{}
2423

2524
type otelMetricService struct {
@@ -41,7 +40,7 @@ func NewOTelMetricService() (MetricService, error) {
4140
sdk.WithReader(exporter),
4241
)
4342

44-
meter := provider.Meter(serviceName)
43+
meter := provider.Meter(config.ServiceName)
4544

4645
return &otelMetricService{
4746
meter: meter,
@@ -80,7 +79,7 @@ func (_this otelMetricService) RecordRequest(ctx context.Context, name, method,
8079
normalizedPath := normalizePath(path)
8180

8281
counter, err := _this.meter.Int64Counter(
83-
fmt.Sprintf("%s_%s_requests_total", serviceName, name),
82+
fmt.Sprintf("%s_%s_requests_total", config.ServiceName, name),
8483
metric.WithDescription("Total number of requests received"),
8584
)
8685
if err != nil {
@@ -107,7 +106,7 @@ func (_this otelMetricService) RecordDuration(ctx context.Context, name string,
107106
}
108107

109108
histogram, err := _this.meter.Float64Histogram(
110-
fmt.Sprintf("%s_%s_duration_seconds", serviceName, name),
109+
fmt.Sprintf("%s_%s_duration_seconds", config.ServiceName, name),
111110
metric.WithDescription("Duration of operation in seconds"),
112111
)
113112
if err != nil {

controllers/proxy_controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ func (_this proxyController) handleRequest(reqCtx requestContext) {
203203
reqCtx.ginContext.Header(k, v)
204204
}
205205
}
206+
// Add a header indicating that this request was proxied
207+
reqCtx.ginContext.Header("X-Proxied-By", config.ServiceName)
206208
reqCtx.ginContext.Data(resp.StatusCode, resp.Header.Get("Content-Type"), respBody)
207209
}
208210
}

0 commit comments

Comments
 (0)