Skip to content

Conversation

@Zavierazo
Copy link
Contributor

@Zavierazo Zavierazo commented Nov 17, 2025

Add support for dynamic tag_ labels in metrics

Description

This change introduces support for dynamic labels in Prometheus custom metrics using the syntax tag_.
Previously, the pump only supported a fixed set of labels mapped to AnalyticsRecord fields. With this enhancement, users can now include tags associated with API requests as metric labels, enabling richer and more contextual Prometheus metrics.

Related Issue

Original ticket: https://support.tyk.io/hc/en-gb/requests/23608

Motivation and Context

This feature allows users to enrich Prometheus metrics with business-specific or contextual metadata already associated with APIs via tags in Tyk Dashboard. It enables dynamic metric segmentation without requiring hardcoded label sets.

How This Has Been Tested

  • Added a custom metric with labels: ["tag_customer", "tag_wrong"].
  • Sent analytics records with Tags: []string{"customer-test"} and verified Prometheus metrics include "test" for these labels.
  • Tested with records missing tags to ensure "" is used as value.
  • Ran unit tests successfully.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • Make sure you are requesting to pull a topic/feature/bugfix branch (right side). If pulling from your own
    fork, don't request your master!
  • Make sure you are making a pull request against the master branch (left side). Also, you should start
    your branch off our latest master.
  • My change requires a change to the documentation.
    • If you've changed APIs, describe what needs to be updated in the documentation.
  • I have updated the documentation accordingly.
  • Modules and vendor dependencies have been updated; run go mod tidy && go mod vendor
  • I have added tests to cover my changes.
  • All new and existing tests passed. (test requiring external components not tested)
  • Check your code additions will not fail linting checks:
    • go fmt -s
    • go vet

Copilot AI review requested due to automatic review settings November 17, 2025 15:14
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for dynamic tag_<name> labels in Prometheus custom metrics. Previously, only a fixed set of labels mapped to AnalyticsRecord fields were supported. This enhancement allows users to include tags associated with API requests as metric labels by using the syntax tag_<name>, where tags are matched from the AnalyticsRecord.Tags array.

  • Dynamic label support for tags in Prometheus metrics using tag_<name> syntax
  • Tag matching logic that extracts values from AnalyticsRecord.Tags array
  • Documentation update to include the new label syntax

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
pumps/prometheus.go Implements tag extraction logic in GetLabelsValues to support dynamic tag labels
pumps/prometheus_test.go Adds test cases for valid custom tags and missing tag scenarios
README.md Updates documentation to include tag_<tag-name> in available label values

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@andyo-tyk
Copy link

Hi @Zavierazo,

Thanks for submitting this PR - we're looking at this and aiming to bring it, (either directly or as part of a larger addition to functionality) into the product in Q1.

Thanks again for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants