diff --git a/app/controllers/content_items_controller.rb b/app/controllers/content_items_controller.rb index a10a5e9dd..28092357a 100644 --- a/app/controllers/content_items_controller.rb +++ b/app/controllers/content_items_controller.rb @@ -25,6 +25,7 @@ def show load_content_item set_expiry + set_prometheus_labels if is_service_manual? show_service_manual_page @@ -234,6 +235,14 @@ def set_expiry ) end + def set_prometheus_labels + prometheus_labels = request.env.fetch("govuk.prometheus_labels", {}) + request.env["govuk.prometheus_labels"] = prometheus_labels.merge( + document_type: @content_item.document_type, + schema_name: @content_item.schema_name, + ) + end + def service_url(original_url) ga_param = params[:_ga] return original_url if ga_param.nil? diff --git a/test/controllers/content_items_controller_test.rb b/test/controllers/content_items_controller_test.rb index 692c1a1ff..d7be54947 100644 --- a/test/controllers/content_items_controller_test.rb +++ b/test/controllers/content_items_controller_test.rb @@ -158,6 +158,14 @@ class ContentItemsControllerTest < ActionController::TestCase assert_equal content_item["title"], assigns[:content_item].title end + test "sets prometheus labels on the rack env" do + content_item = content_store_has_schema_example("case_study", "case_study") + + get :show, params: { path: path_for(content_item) } + assert_response :success + assert_equal @request.env["govuk.prometheus_labels"], { document_type: "case_study", schema_name: "case_study" } + end + test "gets item from content store and keeps existing ordered_related_items when links already exist" do content_item = content_store_has_schema_example("guide", "guide")