@loglayer/transport-new-relic 4.0.1 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +17 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +1 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value:
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
let _loglayer_transport_http = require("@loglayer/transport-http");
|
|
3
|
-
|
|
4
3
|
//#region src/NewRelicTransport.ts
|
|
5
4
|
const MAX_ATTRIBUTES = 255;
|
|
6
5
|
const MAX_ATTRIBUTE_NAME_LENGTH = 255;
|
|
@@ -90,26 +89,26 @@ var NewRelicTransport = class extends _loglayer_transport_http.HttpTransport {
|
|
|
90
89
|
});
|
|
91
90
|
}
|
|
92
91
|
};
|
|
93
|
-
|
|
94
92
|
//#endregion
|
|
95
|
-
Object.defineProperty(exports,
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
93
|
+
Object.defineProperty(exports, "HttpTransportError", {
|
|
94
|
+
enumerable: true,
|
|
95
|
+
get: function() {
|
|
96
|
+
return _loglayer_transport_http.HttpTransportError;
|
|
97
|
+
}
|
|
100
98
|
});
|
|
101
|
-
Object.defineProperty(exports,
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
99
|
+
Object.defineProperty(exports, "LogSizeError", {
|
|
100
|
+
enumerable: true,
|
|
101
|
+
get: function() {
|
|
102
|
+
return _loglayer_transport_http.LogSizeError;
|
|
103
|
+
}
|
|
106
104
|
});
|
|
107
105
|
exports.NewRelicTransport = NewRelicTransport;
|
|
108
|
-
Object.defineProperty(exports,
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
106
|
+
Object.defineProperty(exports, "RateLimitError", {
|
|
107
|
+
enumerable: true,
|
|
108
|
+
get: function() {
|
|
109
|
+
return _loglayer_transport_http.RateLimitError;
|
|
110
|
+
}
|
|
113
111
|
});
|
|
114
112
|
exports.ValidationError = ValidationError;
|
|
113
|
+
|
|
115
114
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["HttpTransport"],"sources":["../src/NewRelicTransport.ts"],"sourcesContent":["import type { HttpTransportConfig } from \"@loglayer/transport-http\";\nimport { HttpTransport } from \"@loglayer/transport-http\";\n\n// Constants defining New Relic's API limits\nconst MAX_ATTRIBUTES = 255;\nconst MAX_ATTRIBUTE_NAME_LENGTH = 255;\nconst MAX_ATTRIBUTE_VALUE_LENGTH = 4094;\n\n/**\n * Error thrown when log entry validation fails.\n * This includes attribute count, attribute name length, and other New Relic API validations.\n */\nexport class ValidationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"ValidationError\";\n }\n}\n\n/**\n * Configuration options for the New Relic transport.\n * Extends HttpTransportConfig with New Relic-specific options.\n */\nexport interface NewRelicTransportConfig extends Omit<HttpTransportConfig, \"url\" | \"headers\" | \"payloadTemplate\"> {\n /**\n * The New Relic API key\n */\n apiKey: string;\n /**\n * The New Relic Log API endpoint\n * @default \"https://log-api.newrelic.com/log/v1\"\n */\n endpoint?: string;\n /**\n * Custom payload template function (optional, defaults to New Relic format).\n * Receives log level, message, and optional data (metadata).\n */\n payloadTemplate?: (params: { logLevel: string; message: string; data?: Record<string, any> }) => string;\n}\n\n/**\n * Validates attributes against New Relic's constraints.\n * - Checks number of attributes (max 255)\n * - Validates attribute name length (max 255 characters)\n * - Truncates attribute values longer than 4094 characters\n *\n * @param attributes - The attributes to validate\n * @returns The validated (and potentially modified) attributes\n * @throws {ValidationError} If validation fails\n */\nfunction validateAttributes(attributes: Record<string, any>): Record<string, any> {\n const validated: Record<string, any> = {};\n\n // Check number of attributes\n const attributeCount = Object.keys(attributes).length;\n if (attributeCount > MAX_ATTRIBUTES) {\n throw new ValidationError(\n `Log entry exceeds maximum number of attributes (${MAX_ATTRIBUTES}). Found: ${attributeCount}`,\n );\n }\n\n // Check attribute names and values\n for (const [key, value] of Object.entries(attributes)) {\n // Check attribute name length\n if (key.length > MAX_ATTRIBUTE_NAME_LENGTH) {\n throw new ValidationError(\n `Attribute name exceeds maximum length (${MAX_ATTRIBUTE_NAME_LENGTH}). Found: ${key.length}`,\n );\n }\n\n // Truncate string values that are too long\n if (typeof value === \"string\" && value.length > MAX_ATTRIBUTE_VALUE_LENGTH) {\n validated[key] = value.slice(0, MAX_ATTRIBUTE_VALUE_LENGTH);\n } else {\n validated[key] = value;\n }\n }\n\n return validated;\n}\n\n/**\n * Default payload template that formats log data for New Relic's Log API.\n * Each entry includes timestamp, level, the log message, and optional attributes.\n */\nfunction defaultNewRelicPayload(params: { logLevel: string; message: string; data?: Record<string, any> }): string {\n const logEntry: Record<string, any> = {\n timestamp: Date.now(),\n level: params.logLevel,\n log: params.message,\n };\n\n if (params.data) {\n logEntry.attributes = validateAttributes(params.data);\n }\n\n return JSON.stringify(logEntry);\n}\n\n/**\n * NewRelicTransport is responsible for sending logs to New Relic's Log API.\n * It extends HttpTransport with New Relic-specific configuration, validation,\n * and formatting.\n *\n * Features:\n * - Validates attribute count (max 255)\n * - Validates attribute name length (max 255 characters)\n * - Truncates attribute values longer than 4094 characters\n * - Gzip compression by default (via HttpTransport)\n * - Retry logic with exponential backoff (via HttpTransport)\n * - Rate limiting support (via HttpTransport)\n * - Batch sending support (via HttpTransport)\n * - Error and debug callbacks\n */\nexport class NewRelicTransport extends HttpTransport {\n /**\n * Creates a new instance of NewRelicTransport.\n *\n * @param config - Configuration options for the transport\n */\n constructor(config: NewRelicTransportConfig) {\n const { apiKey, endpoint, payloadTemplate, ...httpConfig } = config;\n\n super({\n ...httpConfig,\n url: endpoint ?? \"https://log-api.newrelic.com/log/v1\",\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"Api-Key\": apiKey,\n },\n payloadTemplate: payloadTemplate ?? defaultNewRelicPayload,\n // Defaults (only apply if not provided)\n compression: httpConfig.compression ?? true,\n maxRetries: httpConfig.maxRetries ?? 3,\n retryDelay: httpConfig.retryDelay ?? 1000,\n respectRateLimit: httpConfig.respectRateLimit ?? true,\n maxLogSize: httpConfig.maxLogSize ?? 1_048_576,\n maxPayloadSize: httpConfig.maxPayloadSize ?? 1_048_576,\n } as HttpTransportConfig);\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["HttpTransport"],"sources":["../src/NewRelicTransport.ts"],"sourcesContent":["import type { HttpTransportConfig } from \"@loglayer/transport-http\";\nimport { HttpTransport } from \"@loglayer/transport-http\";\n\n// Constants defining New Relic's API limits\nconst MAX_ATTRIBUTES = 255;\nconst MAX_ATTRIBUTE_NAME_LENGTH = 255;\nconst MAX_ATTRIBUTE_VALUE_LENGTH = 4094;\n\n/**\n * Error thrown when log entry validation fails.\n * This includes attribute count, attribute name length, and other New Relic API validations.\n */\nexport class ValidationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"ValidationError\";\n }\n}\n\n/**\n * Configuration options for the New Relic transport.\n * Extends HttpTransportConfig with New Relic-specific options.\n */\nexport interface NewRelicTransportConfig extends Omit<HttpTransportConfig, \"url\" | \"headers\" | \"payloadTemplate\"> {\n /**\n * The New Relic API key\n */\n apiKey: string;\n /**\n * The New Relic Log API endpoint\n * @default \"https://log-api.newrelic.com/log/v1\"\n */\n endpoint?: string;\n /**\n * Custom payload template function (optional, defaults to New Relic format).\n * Receives log level, message, and optional data (metadata).\n */\n payloadTemplate?: (params: { logLevel: string; message: string; data?: Record<string, any> }) => string;\n}\n\n/**\n * Validates attributes against New Relic's constraints.\n * - Checks number of attributes (max 255)\n * - Validates attribute name length (max 255 characters)\n * - Truncates attribute values longer than 4094 characters\n *\n * @param attributes - The attributes to validate\n * @returns The validated (and potentially modified) attributes\n * @throws {ValidationError} If validation fails\n */\nfunction validateAttributes(attributes: Record<string, any>): Record<string, any> {\n const validated: Record<string, any> = {};\n\n // Check number of attributes\n const attributeCount = Object.keys(attributes).length;\n if (attributeCount > MAX_ATTRIBUTES) {\n throw new ValidationError(\n `Log entry exceeds maximum number of attributes (${MAX_ATTRIBUTES}). Found: ${attributeCount}`,\n );\n }\n\n // Check attribute names and values\n for (const [key, value] of Object.entries(attributes)) {\n // Check attribute name length\n if (key.length > MAX_ATTRIBUTE_NAME_LENGTH) {\n throw new ValidationError(\n `Attribute name exceeds maximum length (${MAX_ATTRIBUTE_NAME_LENGTH}). Found: ${key.length}`,\n );\n }\n\n // Truncate string values that are too long\n if (typeof value === \"string\" && value.length > MAX_ATTRIBUTE_VALUE_LENGTH) {\n validated[key] = value.slice(0, MAX_ATTRIBUTE_VALUE_LENGTH);\n } else {\n validated[key] = value;\n }\n }\n\n return validated;\n}\n\n/**\n * Default payload template that formats log data for New Relic's Log API.\n * Each entry includes timestamp, level, the log message, and optional attributes.\n */\nfunction defaultNewRelicPayload(params: { logLevel: string; message: string; data?: Record<string, any> }): string {\n const logEntry: Record<string, any> = {\n timestamp: Date.now(),\n level: params.logLevel,\n log: params.message,\n };\n\n if (params.data) {\n logEntry.attributes = validateAttributes(params.data);\n }\n\n return JSON.stringify(logEntry);\n}\n\n/**\n * NewRelicTransport is responsible for sending logs to New Relic's Log API.\n * It extends HttpTransport with New Relic-specific configuration, validation,\n * and formatting.\n *\n * Features:\n * - Validates attribute count (max 255)\n * - Validates attribute name length (max 255 characters)\n * - Truncates attribute values longer than 4094 characters\n * - Gzip compression by default (via HttpTransport)\n * - Retry logic with exponential backoff (via HttpTransport)\n * - Rate limiting support (via HttpTransport)\n * - Batch sending support (via HttpTransport)\n * - Error and debug callbacks\n */\nexport class NewRelicTransport extends HttpTransport {\n /**\n * Creates a new instance of NewRelicTransport.\n *\n * @param config - Configuration options for the transport\n */\n constructor(config: NewRelicTransportConfig) {\n const { apiKey, endpoint, payloadTemplate, ...httpConfig } = config;\n\n super({\n ...httpConfig,\n url: endpoint ?? \"https://log-api.newrelic.com/log/v1\",\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"Api-Key\": apiKey,\n },\n payloadTemplate: payloadTemplate ?? defaultNewRelicPayload,\n // Defaults (only apply if not provided)\n compression: httpConfig.compression ?? true,\n maxRetries: httpConfig.maxRetries ?? 3,\n retryDelay: httpConfig.retryDelay ?? 1000,\n respectRateLimit: httpConfig.respectRateLimit ?? true,\n maxLogSize: httpConfig.maxLogSize ?? 1_048_576,\n maxPayloadSize: httpConfig.maxPayloadSize ?? 1_048_576,\n } as HttpTransportConfig);\n }\n}\n"],"mappings":";;;AAIA,MAAM,iBAAiB;AACvB,MAAM,4BAA4B;AAClC,MAAM,6BAA6B;;;;;AAMnC,IAAa,kBAAb,cAAqC,MAAM;CACzC,YAAY,SAAiB;EAC3B,MAAM,OAAO;EACb,KAAK,OAAO;CACd;AACF;;;;;;;;;;;AAiCA,SAAS,mBAAmB,YAAsD;CAChF,MAAM,YAAiC,CAAC;CAGxC,MAAM,iBAAiB,OAAO,KAAK,UAAU,EAAE;CAC/C,IAAI,iBAAiB,gBACnB,MAAM,IAAI,gBACR,mDAAmD,eAAe,YAAY,gBAChF;CAIF,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,UAAU,GAAG;EAErD,IAAI,IAAI,SAAS,2BACf,MAAM,IAAI,gBACR,0CAA0C,0BAA0B,YAAY,IAAI,QACtF;EAIF,IAAI,OAAO,UAAU,YAAY,MAAM,SAAS,4BAC9C,UAAU,OAAO,MAAM,MAAM,GAAG,0BAA0B;OAE1D,UAAU,OAAO;CAErB;CAEA,OAAO;AACT;;;;;AAMA,SAAS,uBAAuB,QAAmF;CACjH,MAAM,WAAgC;EACpC,WAAW,KAAK,IAAI;EACpB,OAAO,OAAO;EACd,KAAK,OAAO;CACd;CAEA,IAAI,OAAO,MACT,SAAS,aAAa,mBAAmB,OAAO,IAAI;CAGtD,OAAO,KAAK,UAAU,QAAQ;AAChC;;;;;;;;;;;;;;;;AAiBA,IAAa,oBAAb,cAAuCA,yBAAAA,cAAc;;;;;;CAMnD,YAAY,QAAiC;EAC3C,MAAM,EAAE,QAAQ,UAAU,iBAAiB,GAAG,eAAe;EAE7D,MAAM;GACJ,GAAG;GACH,KAAK,YAAY;GACjB,QAAQ;GACR,SAAS;IACP,gBAAgB;IAChB,WAAW;GACb;GACA,iBAAiB,mBAAmB;GAEpC,aAAa,WAAW,eAAe;GACvC,YAAY,WAAW,cAAc;GACrC,YAAY,WAAW,cAAc;GACrC,kBAAkB,WAAW,oBAAoB;GACjD,YAAY,WAAW,cAAc;GACrC,gBAAgB,WAAW,kBAAkB;EAC/C,CAAwB;CAC1B;AACF"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { HttpTransport, HttpTransportError, LogSizeError, RateLimitError } from "@loglayer/transport-http";
|
|
2
|
-
|
|
3
2
|
//#region src/NewRelicTransport.ts
|
|
4
3
|
const MAX_ATTRIBUTES = 255;
|
|
5
4
|
const MAX_ATTRIBUTE_NAME_LENGTH = 255;
|
|
@@ -89,7 +88,7 @@ var NewRelicTransport = class extends HttpTransport {
|
|
|
89
88
|
});
|
|
90
89
|
}
|
|
91
90
|
};
|
|
92
|
-
|
|
93
91
|
//#endregion
|
|
94
92
|
export { HttpTransportError, LogSizeError, NewRelicTransport, RateLimitError, ValidationError };
|
|
93
|
+
|
|
95
94
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/NewRelicTransport.ts"],"sourcesContent":["import type { HttpTransportConfig } from \"@loglayer/transport-http\";\nimport { HttpTransport } from \"@loglayer/transport-http\";\n\n// Constants defining New Relic's API limits\nconst MAX_ATTRIBUTES = 255;\nconst MAX_ATTRIBUTE_NAME_LENGTH = 255;\nconst MAX_ATTRIBUTE_VALUE_LENGTH = 4094;\n\n/**\n * Error thrown when log entry validation fails.\n * This includes attribute count, attribute name length, and other New Relic API validations.\n */\nexport class ValidationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"ValidationError\";\n }\n}\n\n/**\n * Configuration options for the New Relic transport.\n * Extends HttpTransportConfig with New Relic-specific options.\n */\nexport interface NewRelicTransportConfig extends Omit<HttpTransportConfig, \"url\" | \"headers\" | \"payloadTemplate\"> {\n /**\n * The New Relic API key\n */\n apiKey: string;\n /**\n * The New Relic Log API endpoint\n * @default \"https://log-api.newrelic.com/log/v1\"\n */\n endpoint?: string;\n /**\n * Custom payload template function (optional, defaults to New Relic format).\n * Receives log level, message, and optional data (metadata).\n */\n payloadTemplate?: (params: { logLevel: string; message: string; data?: Record<string, any> }) => string;\n}\n\n/**\n * Validates attributes against New Relic's constraints.\n * - Checks number of attributes (max 255)\n * - Validates attribute name length (max 255 characters)\n * - Truncates attribute values longer than 4094 characters\n *\n * @param attributes - The attributes to validate\n * @returns The validated (and potentially modified) attributes\n * @throws {ValidationError} If validation fails\n */\nfunction validateAttributes(attributes: Record<string, any>): Record<string, any> {\n const validated: Record<string, any> = {};\n\n // Check number of attributes\n const attributeCount = Object.keys(attributes).length;\n if (attributeCount > MAX_ATTRIBUTES) {\n throw new ValidationError(\n `Log entry exceeds maximum number of attributes (${MAX_ATTRIBUTES}). Found: ${attributeCount}`,\n );\n }\n\n // Check attribute names and values\n for (const [key, value] of Object.entries(attributes)) {\n // Check attribute name length\n if (key.length > MAX_ATTRIBUTE_NAME_LENGTH) {\n throw new ValidationError(\n `Attribute name exceeds maximum length (${MAX_ATTRIBUTE_NAME_LENGTH}). Found: ${key.length}`,\n );\n }\n\n // Truncate string values that are too long\n if (typeof value === \"string\" && value.length > MAX_ATTRIBUTE_VALUE_LENGTH) {\n validated[key] = value.slice(0, MAX_ATTRIBUTE_VALUE_LENGTH);\n } else {\n validated[key] = value;\n }\n }\n\n return validated;\n}\n\n/**\n * Default payload template that formats log data for New Relic's Log API.\n * Each entry includes timestamp, level, the log message, and optional attributes.\n */\nfunction defaultNewRelicPayload(params: { logLevel: string; message: string; data?: Record<string, any> }): string {\n const logEntry: Record<string, any> = {\n timestamp: Date.now(),\n level: params.logLevel,\n log: params.message,\n };\n\n if (params.data) {\n logEntry.attributes = validateAttributes(params.data);\n }\n\n return JSON.stringify(logEntry);\n}\n\n/**\n * NewRelicTransport is responsible for sending logs to New Relic's Log API.\n * It extends HttpTransport with New Relic-specific configuration, validation,\n * and formatting.\n *\n * Features:\n * - Validates attribute count (max 255)\n * - Validates attribute name length (max 255 characters)\n * - Truncates attribute values longer than 4094 characters\n * - Gzip compression by default (via HttpTransport)\n * - Retry logic with exponential backoff (via HttpTransport)\n * - Rate limiting support (via HttpTransport)\n * - Batch sending support (via HttpTransport)\n * - Error and debug callbacks\n */\nexport class NewRelicTransport extends HttpTransport {\n /**\n * Creates a new instance of NewRelicTransport.\n *\n * @param config - Configuration options for the transport\n */\n constructor(config: NewRelicTransportConfig) {\n const { apiKey, endpoint, payloadTemplate, ...httpConfig } = config;\n\n super({\n ...httpConfig,\n url: endpoint ?? \"https://log-api.newrelic.com/log/v1\",\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"Api-Key\": apiKey,\n },\n payloadTemplate: payloadTemplate ?? defaultNewRelicPayload,\n // Defaults (only apply if not provided)\n compression: httpConfig.compression ?? true,\n maxRetries: httpConfig.maxRetries ?? 3,\n retryDelay: httpConfig.retryDelay ?? 1000,\n respectRateLimit: httpConfig.respectRateLimit ?? true,\n maxLogSize: httpConfig.maxLogSize ?? 1_048_576,\n maxPayloadSize: httpConfig.maxPayloadSize ?? 1_048_576,\n } as HttpTransportConfig);\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/NewRelicTransport.ts"],"sourcesContent":["import type { HttpTransportConfig } from \"@loglayer/transport-http\";\nimport { HttpTransport } from \"@loglayer/transport-http\";\n\n// Constants defining New Relic's API limits\nconst MAX_ATTRIBUTES = 255;\nconst MAX_ATTRIBUTE_NAME_LENGTH = 255;\nconst MAX_ATTRIBUTE_VALUE_LENGTH = 4094;\n\n/**\n * Error thrown when log entry validation fails.\n * This includes attribute count, attribute name length, and other New Relic API validations.\n */\nexport class ValidationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"ValidationError\";\n }\n}\n\n/**\n * Configuration options for the New Relic transport.\n * Extends HttpTransportConfig with New Relic-specific options.\n */\nexport interface NewRelicTransportConfig extends Omit<HttpTransportConfig, \"url\" | \"headers\" | \"payloadTemplate\"> {\n /**\n * The New Relic API key\n */\n apiKey: string;\n /**\n * The New Relic Log API endpoint\n * @default \"https://log-api.newrelic.com/log/v1\"\n */\n endpoint?: string;\n /**\n * Custom payload template function (optional, defaults to New Relic format).\n * Receives log level, message, and optional data (metadata).\n */\n payloadTemplate?: (params: { logLevel: string; message: string; data?: Record<string, any> }) => string;\n}\n\n/**\n * Validates attributes against New Relic's constraints.\n * - Checks number of attributes (max 255)\n * - Validates attribute name length (max 255 characters)\n * - Truncates attribute values longer than 4094 characters\n *\n * @param attributes - The attributes to validate\n * @returns The validated (and potentially modified) attributes\n * @throws {ValidationError} If validation fails\n */\nfunction validateAttributes(attributes: Record<string, any>): Record<string, any> {\n const validated: Record<string, any> = {};\n\n // Check number of attributes\n const attributeCount = Object.keys(attributes).length;\n if (attributeCount > MAX_ATTRIBUTES) {\n throw new ValidationError(\n `Log entry exceeds maximum number of attributes (${MAX_ATTRIBUTES}). Found: ${attributeCount}`,\n );\n }\n\n // Check attribute names and values\n for (const [key, value] of Object.entries(attributes)) {\n // Check attribute name length\n if (key.length > MAX_ATTRIBUTE_NAME_LENGTH) {\n throw new ValidationError(\n `Attribute name exceeds maximum length (${MAX_ATTRIBUTE_NAME_LENGTH}). Found: ${key.length}`,\n );\n }\n\n // Truncate string values that are too long\n if (typeof value === \"string\" && value.length > MAX_ATTRIBUTE_VALUE_LENGTH) {\n validated[key] = value.slice(0, MAX_ATTRIBUTE_VALUE_LENGTH);\n } else {\n validated[key] = value;\n }\n }\n\n return validated;\n}\n\n/**\n * Default payload template that formats log data for New Relic's Log API.\n * Each entry includes timestamp, level, the log message, and optional attributes.\n */\nfunction defaultNewRelicPayload(params: { logLevel: string; message: string; data?: Record<string, any> }): string {\n const logEntry: Record<string, any> = {\n timestamp: Date.now(),\n level: params.logLevel,\n log: params.message,\n };\n\n if (params.data) {\n logEntry.attributes = validateAttributes(params.data);\n }\n\n return JSON.stringify(logEntry);\n}\n\n/**\n * NewRelicTransport is responsible for sending logs to New Relic's Log API.\n * It extends HttpTransport with New Relic-specific configuration, validation,\n * and formatting.\n *\n * Features:\n * - Validates attribute count (max 255)\n * - Validates attribute name length (max 255 characters)\n * - Truncates attribute values longer than 4094 characters\n * - Gzip compression by default (via HttpTransport)\n * - Retry logic with exponential backoff (via HttpTransport)\n * - Rate limiting support (via HttpTransport)\n * - Batch sending support (via HttpTransport)\n * - Error and debug callbacks\n */\nexport class NewRelicTransport extends HttpTransport {\n /**\n * Creates a new instance of NewRelicTransport.\n *\n * @param config - Configuration options for the transport\n */\n constructor(config: NewRelicTransportConfig) {\n const { apiKey, endpoint, payloadTemplate, ...httpConfig } = config;\n\n super({\n ...httpConfig,\n url: endpoint ?? \"https://log-api.newrelic.com/log/v1\",\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"Api-Key\": apiKey,\n },\n payloadTemplate: payloadTemplate ?? defaultNewRelicPayload,\n // Defaults (only apply if not provided)\n compression: httpConfig.compression ?? true,\n maxRetries: httpConfig.maxRetries ?? 3,\n retryDelay: httpConfig.retryDelay ?? 1000,\n respectRateLimit: httpConfig.respectRateLimit ?? true,\n maxLogSize: httpConfig.maxLogSize ?? 1_048_576,\n maxPayloadSize: httpConfig.maxPayloadSize ?? 1_048_576,\n } as HttpTransportConfig);\n }\n}\n"],"mappings":";;AAIA,MAAM,iBAAiB;AACvB,MAAM,4BAA4B;AAClC,MAAM,6BAA6B;;;;;AAMnC,IAAa,kBAAb,cAAqC,MAAM;CACzC,YAAY,SAAiB;EAC3B,MAAM,OAAO;EACb,KAAK,OAAO;CACd;AACF;;;;;;;;;;;AAiCA,SAAS,mBAAmB,YAAsD;CAChF,MAAM,YAAiC,CAAC;CAGxC,MAAM,iBAAiB,OAAO,KAAK,UAAU,EAAE;CAC/C,IAAI,iBAAiB,gBACnB,MAAM,IAAI,gBACR,mDAAmD,eAAe,YAAY,gBAChF;CAIF,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,UAAU,GAAG;EAErD,IAAI,IAAI,SAAS,2BACf,MAAM,IAAI,gBACR,0CAA0C,0BAA0B,YAAY,IAAI,QACtF;EAIF,IAAI,OAAO,UAAU,YAAY,MAAM,SAAS,4BAC9C,UAAU,OAAO,MAAM,MAAM,GAAG,0BAA0B;OAE1D,UAAU,OAAO;CAErB;CAEA,OAAO;AACT;;;;;AAMA,SAAS,uBAAuB,QAAmF;CACjH,MAAM,WAAgC;EACpC,WAAW,KAAK,IAAI;EACpB,OAAO,OAAO;EACd,KAAK,OAAO;CACd;CAEA,IAAI,OAAO,MACT,SAAS,aAAa,mBAAmB,OAAO,IAAI;CAGtD,OAAO,KAAK,UAAU,QAAQ;AAChC;;;;;;;;;;;;;;;;AAiBA,IAAa,oBAAb,cAAuC,cAAc;;;;;;CAMnD,YAAY,QAAiC;EAC3C,MAAM,EAAE,QAAQ,UAAU,iBAAiB,GAAG,eAAe;EAE7D,MAAM;GACJ,GAAG;GACH,KAAK,YAAY;GACjB,QAAQ;GACR,SAAS;IACP,gBAAgB;IAChB,WAAW;GACb;GACA,iBAAiB,mBAAmB;GAEpC,aAAa,WAAW,eAAe;GACvC,YAAY,WAAW,cAAc;GACrC,YAAY,WAAW,cAAc;GACrC,kBAAkB,WAAW,oBAAoB;GACjD,YAAY,WAAW,cAAc;GACrC,gBAAgB,WAAW,kBAAkB;EAC/C,CAAwB;CAC1B;AACF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loglayer/transport-new-relic",
|
|
3
3
|
"description": "New Relic transport for the LogLayer logging library.",
|
|
4
|
-
"version": "4.0
|
|
4
|
+
"version": "4.2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.mjs",
|
|
@@ -34,19 +34,19 @@
|
|
|
34
34
|
"transport"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@loglayer/transport-http": "2.
|
|
37
|
+
"@loglayer/transport-http": "2.3.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@types/node": "25.
|
|
41
|
-
"dotenv": "17.
|
|
40
|
+
"@types/node": "25.9.1",
|
|
41
|
+
"dotenv": "17.4.2",
|
|
42
42
|
"serialize-error": "13.0.1",
|
|
43
|
-
"tsdown": "0.
|
|
44
|
-
"tsx": "4.
|
|
45
|
-
"typescript": "
|
|
46
|
-
"vitest": "4.
|
|
47
|
-
"@loglayer/transport": "3.0.3",
|
|
43
|
+
"tsdown": "0.22.1",
|
|
44
|
+
"tsx": "4.22.3",
|
|
45
|
+
"typescript": "6.0.3",
|
|
46
|
+
"vitest": "4.1.7",
|
|
48
47
|
"@internal/tsconfig": "2.1.0",
|
|
49
|
-
"loglayer": "
|
|
48
|
+
"@loglayer/transport": "3.2.0",
|
|
49
|
+
"loglayer": "9.3.0"
|
|
50
50
|
},
|
|
51
51
|
"bugs": "https://github.com/loglayer/loglayer/issues",
|
|
52
52
|
"engines": {
|