diff --git a/packages/opentelemetry-instrumentation-bedrock/opentelemetry/instrumentation/bedrock/__init__.py b/packages/opentelemetry-instrumentation-bedrock/opentelemetry/instrumentation/bedrock/__init__.py index d54bde1d8a..53a818b8ad 100644 --- a/packages/opentelemetry-instrumentation-bedrock/opentelemetry/instrumentation/bedrock/__init__.py +++ b/packages/opentelemetry-instrumentation-bedrock/opentelemetry/instrumentation/bedrock/__init__.py @@ -493,7 +493,12 @@ class GuardrailMeters: class PromptCaching: # will be moved under the AI SemConv. Not namespaced since also OpenAI supports this. - LLM_BEDROCK_PROMPT_CACHING = "gen_ai.prompt.caching" + # FR: canonical name uses an underscore (`gen_ai.prompt_caching`) to match the + # FortifyRoot backend metric contract / catalog and the span attribute + # `CacheSpanAttrs.CACHED`. Prometheus normalizes both forms to + # `gen_ai_prompt_caching`, but the OTel/contract name must match exactly for + # registry, discovery, and SDK/backend round-trips. + LLM_BEDROCK_PROMPT_CACHING = "gen_ai.prompt_caching" def _create_metrics(meter: Meter): diff --git a/packages/opentelemetry-instrumentation-bedrock/tests/metrics/test_bedrock_prompt_caching_metrics.py b/packages/opentelemetry-instrumentation-bedrock/tests/metrics/test_bedrock_prompt_caching_metrics.py index abc6ddd523..099f393ee7 100644 --- a/packages/opentelemetry-instrumentation-bedrock/tests/metrics/test_bedrock_prompt_caching_metrics.py +++ b/packages/opentelemetry-instrumentation-bedrock/tests/metrics/test_bedrock_prompt_caching_metrics.py @@ -1,3 +1,7 @@ +# NOTE: +# This file has been modified by FortifyRoot. +# Original source: https://github.com/traceloop/openllmetry + import json import pytest @@ -6,6 +10,18 @@ from opentelemetry.instrumentation.bedrock.prompt_caching import CacheSpanAttrs +def test_prompt_caching_metric_name_is_canonical(): + # The Bedrock prompt-caching counter must be emitted with the canonical + # FortifyRoot/backend contract name `gen_ai.prompt_caching` (underscore), + # matching the span attribute `CacheSpanAttrs.CACHED` and the backend metric + # catalog. Prometheus collapses `gen_ai.prompt.caching` and + # `gen_ai.prompt_caching` to the same series, but the OTel/contract name must + # match exactly for registry/discovery and SDK/backend round-trips. + assert PromptCaching.LLM_BEDROCK_PROMPT_CACHING == "gen_ai.prompt_caching" + assert CacheSpanAttrs.CACHED == "gen_ai.prompt_caching" + assert PromptCaching.LLM_BEDROCK_PROMPT_CACHING == CacheSpanAttrs.CACHED + + def call(brt): body = { "anthropic_version": "bedrock-2023-05-31",