33 AUTO_GENERATED_KEY_PREFIX ,
44 COLON_REGEX ,
55 DOUBLE_BACKSLASH ,
6- ParsedFieldName ,
6+ ParsedKey ,
77 PERIOD_REGEX ,
88 REPLACEMENT_CHARACTER ,
99 SINGLE_BACKSLASH ,
@@ -22,6 +22,22 @@ import RoundFormatter from "./FieldFormatters/RoundFormatter";
2222import TimestampFormatter from "./FieldFormatters/TimestampFormatter" ;
2323
2424
25+ /**
26+ * Error message for when a key is prefixed with the `@` symbol in the format string or
27+ * filter key for JSON logs.
28+ */
29+ const UNEXPECTED_AUTOGENERATED_SYMBOL_ERROR_MESSAGE =
30+ "`@` is a reserved symbol for CLP IR logs and must be escaped with `\\` for JSONL logs." ;
31+
32+
33+ /**
34+ * Warning message for when Unicode replacement character is found in format string or filter
35+ * key.
36+ */
37+ const EXISTING_REPLACEMENT_CHARACTER_WARNING =
38+ "Unicode replacement character `U+FFFD` found in format string or filter key; " +
39+ "it will be replaced with a double backlash" ;
40+
2541/**
2642 * List of currently supported field formatters.
2743 */
@@ -81,7 +97,7 @@ const replaceDoubleBacklash = (str: string): string => {
8197
8298/**
8399 * Retrieves fields from auto-generated or user-generated namespace of a structured IR log
84- * event based on the prefix of the parsed key .
100+ * event based on the prefix of the parsed field name .
85101 *
86102 * @param logEvent
87103 * @param structuredIrNamespaceKeys
@@ -93,7 +109,7 @@ const replaceDoubleBacklash = (str: string): string => {
93109const getFieldsByNamespace = (
94110 logEvent : LogEvent ,
95111 structuredIrNamespaceKeys : StructuredIrNamespaceKeys ,
96- parsedFieldName : ParsedFieldName
112+ parsedFieldName : ParsedKey
97113) : JsonObject => {
98114 const namespaceKey = parsedFieldName . isAutoGenerated ?
99115 structuredIrNamespaceKeys . autoGenerated :
@@ -162,7 +178,7 @@ const validateComponent = (component: string | undefined): Nullable<string> => {
162178 * @param key The key to be parsed.
163179 * @return The parsed key.
164180 */
165- const parseKey = ( key : string ) : ParsedFieldName => {
181+ const parseKey = ( key : string ) : ParsedKey => {
166182 const isAutoGenerated = AUTO_GENERATED_KEY_PREFIX === key . charAt ( 0 ) ;
167183 const keyWithoutAutoPrefix = isAutoGenerated ?
168184 key . substring ( 1 ) :
@@ -176,22 +192,20 @@ const parseKey = (key: string): ParsedFieldName => {
176192} ;
177193
178194/**
179- * Splits a field placeholder string into its components: parsed field name, formatter name, and
195+ * Splits a field placeholder string into its components: field name, formatter name, and
180196 * formatter options.
181197 *
182198 * @param placeholderString
183- * @param structuredIrNamespaceKeys
184199 * @return - An object containing:
185- * - parsedFieldName : The parsed field name.
200+ * - fieldName : The field name.
186201 * - formatterName: The formatter name, or `null` if not provided.
187202 * - formatterOptions: The formatter options, or `null` if not provided.
188203 * @throws {Error } If the field name could not be parsed.
189204 */
190205const splitFieldPlaceholder = (
191206 placeholderString : string ,
192- structuredIrNamespaceKeys : Nullable < StructuredIrNamespaceKeys >
193207) : {
194- parsedFieldName : ParsedFieldName ;
208+ fieldName : string ;
195209 formatterName : Nullable < string > ;
196210 formatterOptions : Nullable < string > ;
197211} => {
@@ -207,14 +221,6 @@ const splitFieldPlaceholder = (
207221 throw Error ( "Field name could not be parsed" ) ;
208222 }
209223
210- const parsedFieldName : ParsedFieldName = parseKey ( fieldName ) ;
211- if ( null === structuredIrNamespaceKeys && parsedFieldName . isAutoGenerated ) {
212- throw new Error (
213- "`@` is a reserved symbol and must be escaped with `\\` " +
214- "for JSONL logs."
215- ) ;
216- }
217-
218224 formatterName = validateComponent ( formatterName ) ;
219225 if ( null !== formatterName ) {
220226 formatterName = removeEscapeCharacters ( formatterName ) ;
@@ -225,15 +231,17 @@ const splitFieldPlaceholder = (
225231 formatterOptions = removeEscapeCharacters ( formatterOptions ) ;
226232 }
227233
228- return { parsedFieldName , formatterName, formatterOptions} ;
234+ return { fieldName , formatterName, formatterOptions} ;
229235} ;
230236
231237
232238export {
239+ EXISTING_REPLACEMENT_CHARACTER_WARNING ,
233240 getFormattedField ,
234241 parseKey ,
235242 removeEscapeCharacters ,
236243 replaceDoubleBacklash ,
237244 splitFieldPlaceholder ,
245+ UNEXPECTED_AUTOGENERATED_SYMBOL_ERROR_MESSAGE ,
238246 YSCOPE_FIELD_FORMATTER_MAP ,
239247} ;
0 commit comments