Skip to content

Commit c12f465

Browse files
author
Timothy Mothra
authored
[AzureMonitorExporter] fix SDK version (Azure#37807)
* fix SDK version * guard against excessively length * changelog * add truncate * changelog
1 parent 902abfb commit c12f465

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
### Bugs Fixed
1414

15+
* Fixed an issue causing no telemetry if SDK Version string exceeds max length.
16+
([#37807](https://github.com/Azure/azure-sdk-for-net/pull/37807))
17+
1518
### Other Changes
1619

1720
## 1.0.0-beta.13 (2023-07-13)

sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Customizations/Models/TelemetryItem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public TelemetryItem(string name, TelemetryItem telemetryItem, ActivitySpanId ac
8181

8282
Tags[ContextTagKeys.AiCloudRole.ToString()] = telemetryItem.Tags[ContextTagKeys.AiCloudRole.ToString()];
8383
Tags[ContextTagKeys.AiCloudRoleInstance.ToString()] = telemetryItem.Tags[ContextTagKeys.AiCloudRoleInstance.ToString()];
84-
Tags[ContextTagKeys.AiInternalSdkVersion.ToString()] = SdkVersionUtils.s_sdkVersion;
84+
Tags[ContextTagKeys.AiInternalSdkVersion.ToString()] = SdkVersionUtils.s_sdkVersion.Truncate(SchemaConstants.Tags_AiInternalSdkVersion_MaxLength);
8585
InstrumentationKey = telemetryItem.InstrumentationKey;
8686

8787
if (telemetryItem.SampleRate != 100f)
@@ -118,7 +118,7 @@ private void SetResourceSdkVersionAndIkey(AzureMonitorResource? resource, string
118118
InstrumentationKey = instrumentationKey;
119119
Tags[ContextTagKeys.AiCloudRole.ToString()] = resource?.RoleName;
120120
Tags[ContextTagKeys.AiCloudRoleInstance.ToString()] = resource?.RoleInstance;
121-
Tags[ContextTagKeys.AiInternalSdkVersion.ToString()] = SdkVersionUtils.s_sdkVersion;
121+
Tags[ContextTagKeys.AiInternalSdkVersion.ToString()] = SdkVersionUtils.s_sdkVersion.Truncate(SchemaConstants.Tags_AiInternalSdkVersion_MaxLength);
122122
}
123123

124124
internal static DateTimeOffset FormatUtcTimestamp(System.DateTime utcTimestamp)

sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/Diagnostics/AzureMonitorExporterEventSource.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,5 +352,8 @@ public void FailedToDeserializeIngestionResponse(Exception ex)
352352

353353
[Event(35, Message = "Failed to deserialize response from ingestion due to an exception. Not user actionable. {0}", Level = EventLevel.Warning)]
354354
public void FailedToDeserializeIngestionResponse(string exceptionMessage) => WriteEvent(35, exceptionMessage);
355+
356+
[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)]
357+
public void VersionStringUnexpectedLength(string typeName, string value) => WriteEvent(36, typeName, value);
355358
}
356359
}

sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/SchemaConstants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,7 @@ internal static class SchemaConstants
115115
public const int TelemetryEnvelope_Name_MaxLength = 1024;
116116
public const int TelemetryEnvelope_Time_MaxLength = 64;
117117
public const int TelemetryEnvelope_InstrumentationKey_MaxLength = 40;
118+
119+
public const int Tags_AiInternalSdkVersion_MaxLength = 64;
118120
}
119121
}

sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/SdkVersionUtils.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,21 @@ internal static string? SdkVersionPrefix
3030
try
3131
{
3232
string versionString = type
33-
.Assembly
34-
.GetCustomAttributes<AssemblyInformationalVersionAttribute>()
35-
.First()
36-
.InformationalVersion;
33+
.Assembly
34+
.GetCustomAttributes<AssemblyInformationalVersionAttribute>()
35+
.First()
36+
.InformationalVersion;
3737

38-
// Informational version will be something like 1.1.0-beta2+a25741030f05c60c85be102ce7c33f3899290d49.
39-
// Ignoring part after '+' if it is present.
40-
string? shortVersion = versionString?.Split('+')[0];
38+
// Informational version may contain extra information.
39+
// 1) "1.1.0-beta2+a25741030f05c60c85be102ce7c33f3899290d49". Ignoring part after '+' if it is present.
40+
// 2) "4.6.30411.01 @BuiltBy: XXXXXX @Branch: XXXXXX @srccode: XXXXXX XXXXXX" Ignoring part after '@' if it is present.
41+
string shortVersion = versionString.Split('+', '@', ' ')[0];
42+
43+
if (shortVersion.Length > 20)
44+
{
45+
AzureMonitorExporterEventSource.Log.VersionStringUnexpectedLength(type.Name, versionString);
46+
return shortVersion.Substring(0, 20);
47+
}
4148

4249
return shortVersion;
4350
}

0 commit comments

Comments
 (0)