Skip to content

Truncate gen_ai attributes to 256KB instead of exempting from truncation#48454

Open
Copilot wants to merge 2 commits intomainfrom
copilot/truncate-genai-attributes-256kb
Open

Truncate gen_ai attributes to 256KB instead of exempting from truncation#48454
Copilot wants to merge 2 commits intomainfrom
copilot/truncate-genai-attributes-256kb

Conversation

Copy link
Contributor

Copilot AI commented Mar 17, 2026

Follow-up to #48385. Instead of fully exempting gen_ai custom dimensions from truncation, truncate them at 256KB.

Changes

  • AbstractTelemetryBuilder: Replace TRUNCATION_EXEMPT_PROPERTY_KEYS with GENAI_PROPERTY_KEYS and add MAX_GENAI_PROPERTY_VALUE_LENGTH = 256 * 1024. Gen_ai keys now route through TelemetryTruncation.truncatePropertyValue with the higher limit rather than bypassing truncation entirely.
  • AbstractTelemetryBuilderTest: Replace genAiPropertyIsNotTruncated with two parameterized tests — genAiPropertyIsTruncatedAt256KB (verifies truncation above limit) and genAiPropertyUnder256KBIsNotTruncated (verifies preservation below limit).
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));
}

Copilot AI and others added 2 commits March 17, 2026 21:08
Co-authored-by: harsimar <19897860+harsimar@users.noreply.github.com>
@harsimar harsimar marked this pull request as ready for review March 17, 2026 21:59
@harsimar harsimar self-requested a review as a code owner March 17, 2026 21:59
Copilot AI review requested due to automatic review settings March 17, 2026 21:59
Copy link
Contributor

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 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());
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.

3 participants