From a881e4646af2d6e35ff67bc989867544af083dd0 Mon Sep 17 00:00:00 2001 From: EraKin575 Date: Wed, 6 Aug 2025 21:36:19 +0000 Subject: [PATCH 1/3] added a function to response labels Signed-off-by: EraKin575 --- pkg/observability/key.go | 2 ++ pkg/observability/newcontext.go | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/pkg/observability/key.go b/pkg/observability/key.go index 793c29a7415..0054d18b106 100644 --- a/pkg/observability/key.go +++ b/pkg/observability/key.go @@ -59,4 +59,6 @@ var ( // attributes relating to the request RequestScheme = attributekey.String("url.scheme") + ResponseStatusCode = attributekey.Int("response.statuscode") + ResponseStatusText = attributekey.String("response.statustext") ) diff --git a/pkg/observability/newcontext.go b/pkg/observability/newcontext.go index 97729fcc0e0..68c8c0d38fb 100644 --- a/pkg/observability/newcontext.go +++ b/pkg/observability/newcontext.go @@ -71,6 +71,20 @@ func WithLowCardinalityMessagingLabels(ctx context.Context, destinationTemplate, return ctx } +func WithResponseLabels(ctx context.Context, r *http.Response) context.Context { + labeler, ok := otelhttp.LabelerFromContext(ctx) + if !ok { + ctx = otelhttp.ContextWithLabeler(ctx, labeler) + } + + if r != nil { + labeler.Add(ResponseStatusCode.With(int(r.StatusCode))) + labeler.Add(ResponseStatusText.With(r.Status)) + } + + return ctx +} + func WithRequestLabels(ctx context.Context, r *http.Request) context.Context { labeler, ok := otelhttp.LabelerFromContext(ctx) if !ok { From 5b093a19715f0fe98112d823fe37fd54acd669c0 Mon Sep 17 00:00:00 2001 From: EraKin575 Date: Wed, 6 Aug 2025 21:39:23 +0000 Subject: [PATCH 2/3] added a function to response labels Signed-off-by: EraKin575 --- pkg/observability/key.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/observability/key.go b/pkg/observability/key.go index 0054d18b106..7b7a75de1c0 100644 --- a/pkg/observability/key.go +++ b/pkg/observability/key.go @@ -58,7 +58,7 @@ var ( CloudEventSpecVersion = attributekey.String(ceo11y.SpecversionAttr) // attributes relating to the request - RequestScheme = attributekey.String("url.scheme") + RequestScheme = attributekey.String("url.scheme") ResponseStatusCode = attributekey.Int("response.statuscode") - ResponseStatusText = attributekey.String("response.statustext") + ResponseStatusText = attributekey.String("response.statustext") ) From e7a8bc348cf2046bcaa519b241d986b3e5005bd3 Mon Sep 17 00:00:00 2001 From: EraKin575 Date: Fri, 8 Aug 2025 00:24:15 +0530 Subject: [PATCH 3/3] updated response label functions --- pkg/observability/newcontext.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pkg/observability/newcontext.go b/pkg/observability/newcontext.go index 68c8c0d38fb..58148149200 100644 --- a/pkg/observability/newcontext.go +++ b/pkg/observability/newcontext.go @@ -71,16 +71,13 @@ func WithLowCardinalityMessagingLabels(ctx context.Context, destinationTemplate, return ctx } -func WithResponseLabels(ctx context.Context, r *http.Response) context.Context { +func WithResponseLabels(ctx context.Context, statusCode int) context.Context { labeler, ok := otelhttp.LabelerFromContext(ctx) if !ok { ctx = otelhttp.ContextWithLabeler(ctx, labeler) } - if r != nil { - labeler.Add(ResponseStatusCode.With(int(r.StatusCode))) - labeler.Add(ResponseStatusText.With(r.Status)) - } + labeler.Add(ResponseStatusCode.With(statusCode)) return ctx }