Skip to content

Commit 321eca7

Browse files
Address PR #586 review comments
- Change emit_all() logging from INFO to DEBUG to reduce production log volume - Optional token-detail fields default to None when absent instead of 0 - Remove redundant extract_usage_from_stream_chunk() fallback in TokenUsageScope.add() - Pin azure-monitor-events-extension to ==0.1.0 in both projects - Revert enableMonitoring to false in default parameters Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 021c7b2 commit 321eca7

5 files changed

Lines changed: 17 additions & 17 deletions

File tree

infra/main.parameters.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"value": "${AZURE_ENV_IMAGETAG=latest_v2}"
3737
},
3838
"enableMonitoring": {
39-
"value": true
39+
"value": false
4040
}
4141
}
4242
}

src/ContentProcessor/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dependencies = [
99
"azure-ai-inference==1.0.0b9",
1010
"azure-appconfiguration==1.8.0",
1111
"azure-identity==1.26.0b1",
12-
"azure-monitor-events-extension>=0.1.0",
12+
"azure-monitor-events-extension==0.1.0",
1313
"azure-monitor-opentelemetry==1.8.7",
1414
"azure-storage-blob==12.29.0b1",
1515
"azure-storage-queue==12.16.0b1",

src/ContentProcessor/src/libs/llm_token_telemetry.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,11 @@ def extract_realtime_usage(response_obj: Any) -> Optional[TokenUsage]:
326326
input_tokens=inp,
327327
output_tokens=out,
328328
total_tokens=tot,
329-
input_audio_tokens=_to_int(_get(in_details, "audio_tokens")),
330-
input_text_tokens=_to_int(_get(in_details, "text_tokens")),
331-
input_cached_tokens=_to_int(_get(in_details, "cached_tokens")),
332-
output_audio_tokens=_to_int(_get(out_details, "audio_tokens")),
333-
output_text_tokens=_to_int(_get(out_details, "text_tokens")),
329+
input_audio_tokens=_to_int(_get(in_details, "audio_tokens")) if _get(in_details, "audio_tokens") is not None else None,
330+
input_text_tokens=_to_int(_get(in_details, "text_tokens")) if _get(in_details, "text_tokens") is not None else None,
331+
input_cached_tokens=_to_int(_get(in_details, "cached_tokens")) if _get(in_details, "cached_tokens") is not None else None,
332+
output_audio_tokens=_to_int(_get(out_details, "audio_tokens")) if _get(out_details, "audio_tokens") is not None else None,
333+
output_text_tokens=_to_int(_get(out_details, "text_tokens")) if _get(out_details, "text_tokens") is not None else None,
334334
)
335335
if record.has_any or any(
336336
v for v in (
@@ -776,7 +776,7 @@ def emit_all(
776776
**dimensions,
777777
)
778778

779-
self._log.info(
779+
self._log.debug(
780780
"[TOKEN USAGE] agent=%s model=%s input=%d output=%d total=%d %s",
781781
agent_name,
782782
model_deployment_name,
@@ -856,7 +856,7 @@ def add(self, source: Any) -> Optional[TokenUsage]:
856856
"""
857857
start_ns = time.perf_counter_ns()
858858
try:
859-
found = extract_usage(source) or extract_usage_from_stream_chunk(source)
859+
found = extract_usage(source)
860860
except Exception as exc:
861861
logger.debug("TokenUsageScope.add failed: %s", exc, exc_info=True)
862862
return None

src/ContentProcessorWorkflow/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies = [
1414
"azure-appconfiguration==1.8.0",
1515
"azure-core==1.38.0",
1616
"azure-identity==1.26.0b1",
17-
"azure-monitor-events-extension>=0.1.0",
17+
"azure-monitor-events-extension==0.1.0",
1818
"azure-monitor-opentelemetry==1.8.7",
1919
"azure-storage-blob==12.29.0b1",
2020
"azure-storage-file-datalake==12.23.0",

src/ContentProcessorWorkflow/src/libs/llm_token_telemetry.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,11 @@ def extract_realtime_usage(response_obj: Any) -> Optional[TokenUsage]:
326326
input_tokens=inp,
327327
output_tokens=out,
328328
total_tokens=tot,
329-
input_audio_tokens=_to_int(_get(in_details, "audio_tokens")),
330-
input_text_tokens=_to_int(_get(in_details, "text_tokens")),
331-
input_cached_tokens=_to_int(_get(in_details, "cached_tokens")),
332-
output_audio_tokens=_to_int(_get(out_details, "audio_tokens")),
333-
output_text_tokens=_to_int(_get(out_details, "text_tokens")),
329+
input_audio_tokens=_to_int(_get(in_details, "audio_tokens")) if _get(in_details, "audio_tokens") is not None else None,
330+
input_text_tokens=_to_int(_get(in_details, "text_tokens")) if _get(in_details, "text_tokens") is not None else None,
331+
input_cached_tokens=_to_int(_get(in_details, "cached_tokens")) if _get(in_details, "cached_tokens") is not None else None,
332+
output_audio_tokens=_to_int(_get(out_details, "audio_tokens")) if _get(out_details, "audio_tokens") is not None else None,
333+
output_text_tokens=_to_int(_get(out_details, "text_tokens")) if _get(out_details, "text_tokens") is not None else None,
334334
)
335335
if record.has_any or any(
336336
v for v in (
@@ -776,7 +776,7 @@ def emit_all(
776776
**dimensions,
777777
)
778778

779-
self._log.info(
779+
self._log.debug(
780780
"[TOKEN USAGE] agent=%s model=%s input=%d output=%d total=%d %s",
781781
agent_name,
782782
model_deployment_name,
@@ -856,7 +856,7 @@ def add(self, source: Any) -> Optional[TokenUsage]:
856856
"""
857857
start_ns = time.perf_counter_ns()
858858
try:
859-
found = extract_usage(source) or extract_usage_from_stream_chunk(source)
859+
found = extract_usage(source)
860860
except Exception as exc:
861861
logger.debug("TokenUsageScope.add failed: %s", exc, exc_info=True)
862862
return None

0 commit comments

Comments
 (0)