Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AzureMonitorExporter] fix SDK version #37807

Merged
merged 5 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

### Bugs Fixed

* 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

## 1.0.0-beta.13 (2023-07-13)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,21 @@ internal static string? SdkVersionPrefix
try
{
string versionString = type
.Assembly
.GetCustomAttributes<AssemblyInformationalVersionAttribute>()
.First()
.InformationalVersion;
.Assembly
.GetCustomAttributes<AssemblyInformationalVersionAttribute>()
.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];

if (shortVersion.Length > 20)
{
AzureMonitorExporterEventSource.Log.VersionStringUnexpectedLength(type.Name, versionString);
return shortVersion.Substring(0, 20);
}

return shortVersion;
}
Expand Down