From ce88d222d3722b814e04b934ebb1cbb102120bf9 Mon Sep 17 00:00:00 2001 From: Timothy Mothra Lee Date: Mon, 24 Jul 2023 10:22:10 -0700 Subject: [PATCH 1/5] fix SDK version --- .../src/Internals/SdkVersionUtils.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/SdkVersionUtils.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/SdkVersionUtils.cs index c222c861d2a35..6f4d8e42f5235 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/SdkVersionUtils.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/SdkVersionUtils.cs @@ -30,14 +30,15 @@ internal static string? SdkVersionPrefix try { string versionString = type - .Assembly - .GetCustomAttributes() - .First() - .InformationalVersion; + .Assembly + .GetCustomAttributes() + .First() + .InformationalVersion; - // Informational version will be something like 1.1.0-beta2+a25741030f05c60c85be102ce7c33f3899290d49. - // Ignoring part after '+' if it is present. - string? shortVersion = versionString?.Split('+')[0]; + // Informational version may contain extra information. + // 1) "1.1.0-beta2+a25741030f05c60c85be102ce7c33f3899290d49". Ignoring part after '+' if it is present. + // 2) "4.6.30411.01 @BuiltBy: XXXXXX @Branch: XXXXXX @srccode: XXXXXX XXXXXX" Ignoring part after '@' if it is present. + string shortVersion = versionString.Split('+', '@', ' ')[0]; return shortVersion; } From 731191eace731ad391871333c7a84794059991cb Mon Sep 17 00:00:00 2001 From: Timothy Mothra Lee Date: Mon, 24 Jul 2023 14:07:09 -0700 Subject: [PATCH 2/5] guard against excessively length --- .../Diagnostics/AzureMonitorExporterEventSource.cs | 3 +++ .../src/Internals/SdkVersionUtils.cs | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/Diagnostics/AzureMonitorExporterEventSource.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/Diagnostics/AzureMonitorExporterEventSource.cs index b39d04f88941d..cabcc6c7772ce 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/Diagnostics/AzureMonitorExporterEventSource.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/Diagnostics/AzureMonitorExporterEventSource.cs @@ -352,5 +352,8 @@ public void FailedToDeserializeIngestionResponse(Exception ex) [Event(35, Message = "Failed to deserialize response from ingestion due to an exception. Not user actionable. {0}", Level = EventLevel.Warning)] public void FailedToDeserializeIngestionResponse(string exceptionMessage) => WriteEvent(35, exceptionMessage); + + [Event(36, Message = "Version string exceeds expected length. This is only for internal telemetry and can safely be ignored. Type Name: {0}. Version: {1}", Level = EventLevel.Verbose)] + public void VersionStringUnexpectedLength(string typeName, string value) => WriteEvent(36, typeName, value); } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/SdkVersionUtils.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/SdkVersionUtils.cs index 6f4d8e42f5235..15c760ff46df3 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/SdkVersionUtils.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/SdkVersionUtils.cs @@ -40,6 +40,12 @@ internal static string? SdkVersionPrefix // 2) "4.6.30411.01 @BuiltBy: XXXXXX @Branch: XXXXXX @srccode: XXXXXX XXXXXX" Ignoring part after '@' if it is present. string shortVersion = versionString.Split('+', '@', ' ')[0]; + if (shortVersion.Length > 20) + { + AzureMonitorExporterEventSource.Log.VersionStringUnexpectedLength(type.Name, versionString); + return shortVersion.Substring(0, 20); + } + return shortVersion; } catch (Exception ex) From bf3130596c7b3c6dd4cbab00e115c18048859d3d Mon Sep 17 00:00:00 2001 From: Timothy Mothra Lee Date: Mon, 24 Jul 2023 14:14:31 -0700 Subject: [PATCH 3/5] changelog --- sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/CHANGELOG.md b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/CHANGELOG.md index 7517c75ec9533..7d7844f79eb30 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/CHANGELOG.md +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/CHANGELOG.md @@ -12,6 +12,9 @@ ### Bugs Fixed +* Fixed an issue causing no telemetry if SDK Version string exceeds spec length. + ([#37807](https://github.com/Azure/azure-sdk-for-net/pull/37807)) + ### Other Changes ## 1.0.0-beta.13 (2023-07-13) From 5cbdd4e0234bc58049c58701f5e9d505f152bea5 Mon Sep 17 00:00:00 2001 From: Timothy Mothra Lee Date: Tue, 25 Jul 2023 13:20:18 -0700 Subject: [PATCH 4/5] add truncate --- .../src/Customizations/Models/TelemetryItem.cs | 4 ++-- .../src/Internals/SchemaConstants.cs | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) 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 e8576a0afc118..18098d908bdc8 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 @@ -80,7 +80,7 @@ public TelemetryItem(string name, TelemetryItem telemetryItem, ActivitySpanId ac Tags[ContextTagKeys.AiCloudRole.ToString()] = telemetryItem.Tags[ContextTagKeys.AiCloudRole.ToString()]; Tags[ContextTagKeys.AiCloudRoleInstance.ToString()] = telemetryItem.Tags[ContextTagKeys.AiCloudRoleInstance.ToString()]; - Tags[ContextTagKeys.AiInternalSdkVersion.ToString()] = SdkVersionUtils.s_sdkVersion; + Tags[ContextTagKeys.AiInternalSdkVersion.ToString()] = SdkVersionUtils.s_sdkVersion.Truncate(SchemaConstants.Tags_AiInternalSdkVersion_MaxLength); InstrumentationKey = telemetryItem.InstrumentationKey; SampleRate = telemetryItem.SampleRate; } @@ -113,7 +113,7 @@ private void SetResourceSdkVersionAndIkey(AzureMonitorResource? resource, string InstrumentationKey = instrumentationKey; Tags[ContextTagKeys.AiCloudRole.ToString()] = resource?.RoleName; Tags[ContextTagKeys.AiCloudRoleInstance.ToString()] = resource?.RoleInstance; - Tags[ContextTagKeys.AiInternalSdkVersion.ToString()] = SdkVersionUtils.s_sdkVersion; + Tags[ContextTagKeys.AiInternalSdkVersion.ToString()] = SdkVersionUtils.s_sdkVersion.Truncate(SchemaConstants.Tags_AiInternalSdkVersion_MaxLength); } internal static DateTimeOffset FormatUtcTimestamp(System.DateTime utcTimestamp) 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 fbe7b606fd09a..5c7022d478fc6 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/SchemaConstants.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/SchemaConstants.cs @@ -115,5 +115,7 @@ internal static class SchemaConstants public const int TelemetryEnvelope_Name_MaxLength = 1024; public const int TelemetryEnvelope_Time_MaxLength = 64; public const int TelemetryEnvelope_InstrumentationKey_MaxLength = 40; + + public const int Tags_AiInternalSdkVersion_MaxLength = 64; } } From dc7e4de5ab148200f3add9db98b09188b21a36e8 Mon Sep 17 00:00:00 2001 From: Timothy Mothra Lee Date: Tue, 25 Jul 2023 13:25:45 -0700 Subject: [PATCH 5/5] changelog --- sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/CHANGELOG.md b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/CHANGELOG.md index 7d7844f79eb30..e074fa52d49fc 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/CHANGELOG.md +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/CHANGELOG.md @@ -12,7 +12,7 @@ ### Bugs Fixed -* Fixed an issue causing no telemetry if SDK Version string exceeds spec length. +* Fixed an issue causing no telemetry if SDK Version string exceeds max length. ([#37807](https://github.com/Azure/azure-sdk-for-net/pull/37807)) ### Other Changes