diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Customizations/Models/TelemetryItem.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Customizations/Models/TelemetryItem.cs index 915841941ac1e..6cf8d0f9beb2f 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Customizations/Models/TelemetryItem.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Customizations/Models/TelemetryItem.cs @@ -27,15 +27,15 @@ public TelemetryItem(Activity activity, ref ActivityTagsProcessor activityTagsPr { if (activityTagsProcessor.activityType.HasFlag(OperationType.V2)) { - Tags[ContextTagKeys.AiOperationName.ToString()] = TraceHelper.GetOperationNameV2(activity, ref activityTagsProcessor.MappedTags); + Tags[ContextTagKeys.AiOperationName.ToString()] = TraceHelper.GetOperationNameV2(activity, ref activityTagsProcessor.MappedTags).Truncate(SchemaConstants.Tags_AiOperationName_MaxLength); } else if (activityTagsProcessor.activityType.HasFlag(OperationType.Http)) { - Tags[ContextTagKeys.AiOperationName.ToString()] = TraceHelper.GetOperationName(activity, ref activityTagsProcessor.MappedTags); + Tags[ContextTagKeys.AiOperationName.ToString()] = TraceHelper.GetOperationName(activity, ref activityTagsProcessor.MappedTags).Truncate(SchemaConstants.Tags_AiOperationName_MaxLength); } else { - Tags[ContextTagKeys.AiOperationName.ToString()] = activity.DisplayName; + Tags[ContextTagKeys.AiOperationName.ToString()] = activity.DisplayName.Truncate(SchemaConstants.Tags_AiOperationName_MaxLength); } // Set ip in case of server spans only. @@ -79,8 +79,8 @@ public TelemetryItem(string name, TelemetryItem telemetryItem, ActivitySpanId ac Tags["ai.user.userAgent"] = userAgent; } - Tags[ContextTagKeys.AiCloudRole.ToString()] = telemetryItem.Tags[ContextTagKeys.AiCloudRole.ToString()]; - Tags[ContextTagKeys.AiCloudRoleInstance.ToString()] = telemetryItem.Tags[ContextTagKeys.AiCloudRoleInstance.ToString()]; + Tags[ContextTagKeys.AiCloudRole.ToString()] = telemetryItem.Tags[ContextTagKeys.AiCloudRole.ToString()].Truncate(SchemaConstants.Tags_AiCloudRole_MaxLength); + Tags[ContextTagKeys.AiCloudRoleInstance.ToString()] = telemetryItem.Tags[ContextTagKeys.AiCloudRoleInstance.ToString()].Truncate(SchemaConstants.Tags_AiCloudRoleInstance_MaxLength); Tags[ContextTagKeys.AiInternalSdkVersion.ToString()] = SdkVersionUtils.s_sdkVersion.Truncate(SchemaConstants.Tags_AiInternalSdkVersion_MaxLength); InstrumentationKey = telemetryItem.InstrumentationKey; @@ -116,8 +116,8 @@ public TelemetryItem(DateTime time, AzureMonitorResource? resource, string instr private void SetResourceSdkVersionAndIkey(AzureMonitorResource? resource, string instrumentationKey) { InstrumentationKey = instrumentationKey; - Tags[ContextTagKeys.AiCloudRole.ToString()] = resource?.RoleName; - Tags[ContextTagKeys.AiCloudRoleInstance.ToString()] = resource?.RoleInstance; + Tags[ContextTagKeys.AiCloudRole.ToString()] = resource?.RoleName.Truncate(SchemaConstants.Tags_AiCloudRole_MaxLength); + Tags[ContextTagKeys.AiCloudRoleInstance.ToString()] = resource?.RoleInstance.Truncate(SchemaConstants.Tags_AiCloudRoleInstance_MaxLength); Tags[ContextTagKeys.AiInternalSdkVersion.ToString()] = SdkVersionUtils.s_sdkVersion.Truncate(SchemaConstants.Tags_AiInternalSdkVersion_MaxLength); } @@ -131,7 +131,7 @@ private void SetAuthenticatedUserId(ref ActivityTagsProcessor activityTagsProces { if (activityTagsProcessor.EndUserId != null) { - Tags[ContextTagKeys.AiUserAuthUserId.ToString()] = activityTagsProcessor.EndUserId; + Tags[ContextTagKeys.AiUserAuthUserId.ToString()] = activityTagsProcessor.EndUserId.Truncate(SchemaConstants.Tags_AiUserAuthUserId_MaxLength); } } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/SchemaConstants.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/SchemaConstants.cs index 5c7022d478fc6..b1871e06f4675 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/SchemaConstants.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/SchemaConstants.cs @@ -116,6 +116,12 @@ internal static class SchemaConstants public const int TelemetryEnvelope_Time_MaxLength = 64; public const int TelemetryEnvelope_InstrumentationKey_MaxLength = 40; + public const int Tags_AiOperationId_MaxLength = 128; + public const int Tags_AiOperationName_MaxLength = 1024; + public const int Tags_AiOperationParentId_MaxLength = 512; + public const int Tags_AiUserAuthUserId_MaxLength = 1024; + public const int Tags_AiCloudRole_MaxLength = 256; + public const int Tags_AiCloudRoleInstance_MaxLength = 256; public const int Tags_AiInternalSdkVersion_MaxLength = 64; } }