[
https://issues.apache.org/jira/browse/CAMEL-26611?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Claus Ibsen resolved CAMEL-26611.
---------------------------------
Resolution: Fixed
Merged to main in https://github.com/apache/camel/pull/29223, backported to
camel-4.22.x in https://github.com/apache/camel/pull/29251 and camel-4.18.x in
https://github.com/apache/camel/pull/29252. Upgrade guide notes for 4.22.3 and
4.18.6 in https://github.com/apache/camel/pull/29262.
_Claude Code on behalf of davsclaus_
> camel-micrometer - use tags and attributes from headers as given
> ----------------------------------------------------------------
>
> Key: CAMEL-26611
> URL: https://issues.apache.org/jira/browse/CAMEL-26611
> Project: Camel
> Issue Type: Bug
> Components: camel-micrometer, camel-opentelemetry
> Reporter: Claus Ibsen
> Assignee: Claus Ibsen
> Priority: Major
> Fix For: 4.18.6, 4.22.3, 4.24.0
>
>
> The metrics producers of camel-micrometer and camel-opentelemetry-metrics
> apply the Simple language to every tag and attribute of a metric, including
> the ones supplied in the CamelMetricsTags and CamelMetricsAttributes headers.
> Only the endpoint options tags and attributes are documented as supporting
> Simple; the header metadata and the component docs do not say that header
> values are resolved. The CamelMetricsName and CamelMetricsDescription headers
> are already used literally.
> h3. Behaviour today
> * A tag or attribute set in the header whose key or value contains ${...} is
> resolved as a Simple expression, so the recorded meter carries a different
> value than the one the route set, or the exchange fails when the text is not
> a valid expression.
> h3. Behaviour after the change
> * Only the endpoint tags / attributes options are resolved with Simple, per
> exchange, as today.
> * Tags and attributes from the CamelMetricsTags / CamelMetricsAttributes
> headers are used as given, like the name and description headers.
> * A header tag or attribute still overrides an endpoint tag or attribute with
> the same key.
> * A route that needs a computed value in a header tag builds the value in the
> route (for example in a processor) before setting the header.
> h3. Classes involved
> * components/camel-micrometer: AbstractMicrometerProducer.process() - resolve
> only the endpoint tags with simple(...), then add the header Tags unchanged
> (Tags.and(...), so header tags keep precedence), then the camelContext tag.
> * components/camel-opentelemetry-metrics:
> AbstractOpenTelemetryProducer.process() - resolve only the entries of the
> endpoint attributes, then put the header Attributes entries without resolving
> them, keeping the current String conversion of keys and values.
> * MicrometerConstants.HEADER_METRIC_TAGS and
> OpenTelemetryConstants.HEADER_METRIC_ATTRIBUTES: the @Metadata description
> says that the values are used as given and points to the tags / attributes
> options for Simple expressions. Regenerate the component JSON and the catalog.
> * Docs: micrometer-component.adoc and opentelemetry-metrics-component.adoc
> state that header tags / attributes are used as given, with an example of
> computing the value in the route.
> h3. Tests
> * camel-micrometer CounterRouteTest: a header tag whose value or key contains
> ${body} is recorded with that literal text; the existing route with
> tags.a=${body.length} still shows endpoint tags resolved per exchange.
> * camel-micrometer TimerRouteTest / DistributionSummaryRouteTest: a header
> tag overrides an endpoint tag with the same key.
> * camel-opentelemetry-metrics CounterRouteTest: a header attribute value is
> used as given, and a header attribute overrides an endpoint attribute with
> the same key.
> h3. Upgrade guide
> Routes that relied on tags or attributes from the headers being resolved as
> Simple must resolve the value in the route before setting the header.
> Document this in the 4.24 upgrade guide, and in the 4.22.3 and 4.18.6
> sections of the 4.22 and 4.18 guides.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)