Truncate gen_ai attributes to 256KB instead of exempting from truncation#48454
Open
Truncate gen_ai attributes to 256KB instead of exempting from truncation#48454
Conversation
Co-authored-by: harsimar <19897860+harsimar@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
harsimar
March 17, 2026 21:36
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates Azure Monitor OTel autoconfigure telemetry property truncation behavior so that gen_ai.* custom dimensions are no longer fully exempt from truncation, but instead use a higher truncation threshold (256 * 1024) compared to the default 8192.
Changes:
- Introduced a higher max value length for a defined set of
gen_ai.*property keys and routed them through the truncation helper using that higher limit. - Updated unit tests to validate
gen_ai.*properties truncate at the higher limit and remain unmodified below it.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/builders/AbstractTelemetryBuilder.java |
Adds a higher truncation limit for specific gen_ai.* keys and applies TelemetryTruncation.truncatePropertyValue with that limit. |
sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/test/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/builders/AbstractTelemetryBuilderTest.java |
Replaces the prior “not truncated” test with parameterized tests covering truncation at the new threshold and preservation below it. |
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+26
to
+30
| private static final int MAX_GENAI_PROPERTY_VALUE_LENGTH = 256 * 1024; // 256 KB | ||
|
|
||
| // gen_ai properties can contain large payloads (e.g. full conversation messages, | ||
| // tool definitions) that should not be truncated | ||
| private static final Set<String> TRUNCATION_EXEMPT_PROPERTY_KEYS = new HashSet<>(asList("gen_ai.input.messages", | ||
| // tool definitions) that are truncated at a higher limit (256 KB) | ||
| private static final Set<String> GENAI_PROPERTY_KEYS = new HashSet<>(asList("gen_ai.input.messages", |
Comment on lines
+93
to
97
| if (GENAI_PROPERTY_KEYS.contains(key)) { | ||
| getProperties().put(key, | ||
| TelemetryTruncation.truncatePropertyValue(value, MAX_GENAI_PROPERTY_VALUE_LENGTH, key)); | ||
| } else { | ||
| getProperties().put(key, TelemetryTruncation.truncatePropertyValue(value, MAX_PROPERTY_VALUE_LENGTH, key)); |
Comment on lines
+40
to
+46
| int size256KB = 256 * 1024; | ||
| String longValue = repeat("a", size256KB + 10000); | ||
| builder.addProperty(key, longValue); | ||
|
|
||
| TelemetryItem item = builder.build(); | ||
| Map<String, String> properties = getProperties(item); | ||
| assertEquals(size256KB, properties.get(key).length()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #48385. Instead of fully exempting gen_ai custom dimensions from truncation, truncate them at 256KB.
Changes
AbstractTelemetryBuilder: ReplaceTRUNCATION_EXEMPT_PROPERTY_KEYSwithGENAI_PROPERTY_KEYSand addMAX_GENAI_PROPERTY_VALUE_LENGTH = 256 * 1024. Gen_ai keys now route throughTelemetryTruncation.truncatePropertyValuewith the higher limit rather than bypassing truncation entirely.AbstractTelemetryBuilderTest: ReplacegenAiPropertyIsNotTruncatedwith two parameterized tests —genAiPropertyIsTruncatedAt256KB(verifies truncation above limit) andgenAiPropertyUnder256KBIsNotTruncated(verifies preservation below limit).