-
Notifications
You must be signed in to change notification settings - Fork 356
Design review to allow underscore in event name #2232
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
Changes from 1 commit
7d816f4
444b078
316c6b7
9e2f04a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,34 +7,45 @@ | |
|
|
||
| namespace OpenTelemetry.Exporter.OneCollector; | ||
|
|
||
| public enum EventNameDelimiter | ||
| { | ||
| Period, | ||
| Underscore | ||
| } | ||
|
|
||
| internal sealed class EventNameManager | ||
| { | ||
| // Note: OneCollector will silently drop events which have a name less than 4 characters. | ||
| internal const int MinimumEventFullNameLength = 4; | ||
| internal const int MaximumEventFullNameLength = 100; | ||
|
|
||
| // Make change to allow underscore in eventnamespace below. | ||
| private static readonly Regex EventNamespaceValidationRegex = new(@"^[A-Za-z](?:\.?[A-Za-z0-9]+?)*$", RegexOptions.Compiled); | ||
| private static readonly Regex EventNameValidationRegex = new(@"^[A-Za-z][A-Za-z0-9]*$", RegexOptions.Compiled); | ||
|
|
||
| private readonly string defaultEventNamespace; | ||
| private readonly string defaultEventName; | ||
| private readonly EventNameDelimiter defaultEventNameDelimiter; | ||
| private readonly IReadOnlyDictionary<string, EventFullName>? eventFullNameMappings; | ||
| private readonly ResolvedEventFullName defaultEventFullName; | ||
| private readonly Hashtable eventNamespaceCache = new(StringComparer.OrdinalIgnoreCase); | ||
|
|
||
| public EventNameManager( | ||
| string defaultEventNamespace, | ||
| string defaultEventName, | ||
| IReadOnlyDictionary<string, EventFullName>? eventFullNameMappings = null) | ||
| IReadOnlyDictionary<string, EventFullName>? eventFullNameMappings = null, | ||
| EventNameDelimiter eventNameDelimiter = EventNameDelimiter.Period) | ||
| { | ||
| Debug.Assert(defaultEventNamespace != null, "defaultEventNamespace was null"); | ||
| Debug.Assert(defaultEventName != null, "defaultEventName was null"); | ||
|
|
||
| this.defaultEventNamespace = defaultEventNamespace!; | ||
| this.defaultEventName = defaultEventName!; | ||
| this.eventFullNameMappings = eventFullNameMappings; | ||
| this.defaultEventNameDelimiter = eventNameDelimiter; | ||
|
|
||
| this.defaultEventFullName = new( | ||
| eventFullName: BuildEventFullName(this.defaultEventNamespace, this.defaultEventName), | ||
| eventFullName: BuildEventFullName(this.defaultEventNamespace, this.defaultEventName, this.defaultEventNameDelimiter), | ||
| originalEventNamespace: null, | ||
| originalEventName: null); | ||
|
|
||
|
|
@@ -54,7 +65,8 @@ public static bool IsEventNameValid(string eventName) | |
|
|
||
| public ResolvedEventFullName ResolveEventFullName( | ||
| string? eventNamespace, | ||
| string? eventName) | ||
| string? eventName, | ||
| EventNameDelimiter eventNameDelimiter = EventNameDelimiter.Period) | ||
|
||
| { | ||
| var originalEventNamespace = eventNamespace; | ||
| var originalEventName = eventName; | ||
|
|
@@ -112,7 +124,7 @@ public ResolvedEventFullName ResolveEventFullName( | |
| return resolvedEventFullName; | ||
| } | ||
|
|
||
| private static byte[] BuildEventFullName(string eventNamespace, string eventName) | ||
| private static byte[] BuildEventFullName(string eventNamespace, string eventName, EventNameDelimiter eventNameDelimiter = EventNameDelimiter.Period) | ||
|
||
| { | ||
| Span<byte> destination = stackalloc byte[128]; | ||
|
|
||
|
|
@@ -124,7 +136,8 @@ private static byte[] BuildEventFullName(string eventNamespace, string eventName | |
| { | ||
| WriteEventFullNameComponent(eventNamespace, destination, ref cursor); | ||
|
|
||
| destination[cursor++] = (byte)'.'; | ||
| byte delimiter = eventNameDelimiter == EventNameDelimiter.Period ? (byte)'.' : (byte)'_'; | ||
|
||
| destination[cursor++] = delimiter; | ||
| } | ||
|
|
||
| WriteEventFullNameComponent(eventName, destination, ref cursor); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should just be 'eventNameDelimiter'.
The 'defaultEventNamespace' and 'defaultEventName' properties are about the values for a default event, not the default values for an arbitrary event
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is - someone could call log(dataFields: foo) without passing an event name, and the event name would be the default event name. (pseudocode, something like that)