@uoa/lambda-tracing 2.2.1 → 2.3.0-beta.1
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/UoaLogger.ts +18 -16
- package/changelog.md +6 -0
- package/dist/UoaLogger.js +10 -11
- package/dist/uoaHttps.js +23 -0
- package/package.json +16 -1
- package/uoaHttps.ts +25 -0
package/UoaLogger.ts
CHANGED
|
@@ -64,26 +64,28 @@ export class UoaLogger {
|
|
|
64
64
|
public audit(auditInformation: AuditInformation, message?: string): void {
|
|
65
65
|
// Initialize logMessage with mandatory fields
|
|
66
66
|
let logMessage: string =
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
67
|
+
`application:${
|
|
68
|
+
auditInformation.application
|
|
69
|
+
? auditInformation.application.replace(/\s/g, "")
|
|
70
|
+
: "-"
|
|
71
|
+
} ` +
|
|
72
|
+
`accessedBy:${auditInformation.accessedBy.replace(/\s/g, "")} ` +
|
|
73
|
+
`action:${auditInformation.action.toString().replace(/\s/g, "")} ` +
|
|
74
|
+
`owner:${auditInformation.ownerId.replace(/\s/g, "")} ` +
|
|
75
|
+
`resourceType:${auditInformation.resourceType.replace(/\s/g, "")} ` +
|
|
76
|
+
`resourceId:${
|
|
77
|
+
auditInformation.resourceId
|
|
78
|
+
? auditInformation.resourceId.replace(/\s/g, "")
|
|
79
|
+
: "-"
|
|
80
|
+
}`;
|
|
81
|
+
|
|
80
82
|
// Append additional message if provided
|
|
81
83
|
if (message) {
|
|
82
|
-
|
|
84
|
+
logMessage += ` ${message}`;
|
|
83
85
|
}
|
|
84
|
-
|
|
86
|
+
|
|
85
87
|
this.logger.log("audit", logMessage);
|
|
86
|
-
|
|
88
|
+
}
|
|
87
89
|
|
|
88
90
|
/**
|
|
89
91
|
* Function to log warn level messages.
|
package/changelog.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.3.0
|
|
4
|
+
- Automatically decode response if Content-Encoding header is present. Supports gzip, br, and deflate encodings.
|
|
5
|
+
|
|
6
|
+
## 2.2.2
|
|
7
|
+
- Change behaviour for optional audit parameters. Instead of removing empty optional parameters, they will be present with a hyphen ("-").
|
|
8
|
+
|
|
3
9
|
## 2.2.1
|
|
4
10
|
- Fix formatting in readme
|
|
5
11
|
|
package/dist/UoaLogger.js
CHANGED
|
@@ -30,17 +30,16 @@ class UoaLogger {
|
|
|
30
30
|
*/
|
|
31
31
|
audit(auditInformation, message) {
|
|
32
32
|
// Initialize logMessage with mandatory fields
|
|
33
|
-
let logMessage = `
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
`
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
33
|
+
let logMessage = `application:${auditInformation.application
|
|
34
|
+
? auditInformation.application.replace(/\s/g, "")
|
|
35
|
+
: "-"} ` +
|
|
36
|
+
`accessedBy:${auditInformation.accessedBy.replace(/\s/g, "")} ` +
|
|
37
|
+
`action:${auditInformation.action.toString().replace(/\s/g, "")} ` +
|
|
38
|
+
`owner:${auditInformation.ownerId.replace(/\s/g, "")} ` +
|
|
39
|
+
`resourceType:${auditInformation.resourceType.replace(/\s/g, "")} ` +
|
|
40
|
+
`resourceId:${auditInformation.resourceId
|
|
41
|
+
? auditInformation.resourceId.replace(/\s/g, "")
|
|
42
|
+
: "-"}`;
|
|
44
43
|
// Append additional message if provided
|
|
45
44
|
if (message) {
|
|
46
45
|
logMessage += ` ${message}`;
|
package/dist/uoaHttps.js
CHANGED
|
@@ -26,6 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
const https = __importStar(require("https"));
|
|
27
27
|
const api_1 = require("@opentelemetry/api");
|
|
28
28
|
const fast_xml_parser_1 = require("fast-xml-parser");
|
|
29
|
+
const zlib = __importStar(require("node:zlib"));
|
|
29
30
|
function request(...args) {
|
|
30
31
|
if (args[2]) {
|
|
31
32
|
api_1.propagation.inject(api_1.context.active(), args[1].headers);
|
|
@@ -109,6 +110,11 @@ function doHttpsRequest(options, resolve, reject) {
|
|
|
109
110
|
try {
|
|
110
111
|
let body = Buffer.concat(chunks);
|
|
111
112
|
let parsedBody = body.toString();
|
|
113
|
+
//Get the response content-encoding header value so we can decode before parsing
|
|
114
|
+
const responseContentEncoding = response.headers["content-encoding"]?.toLowerCase() ?? '';
|
|
115
|
+
if (responseContentEncoding !== '') {
|
|
116
|
+
parsedBody = decodeResponse(parsedBody, responseContentEncoding);
|
|
117
|
+
}
|
|
112
118
|
//Get the response content-type header value so we can apply different parsing methods
|
|
113
119
|
const responseContentType = response.headers["content-type"]?.toLowerCase() ?? '';
|
|
114
120
|
if (responseContentType === '' || responseContentType.includes('json')) {
|
|
@@ -155,6 +161,23 @@ function setRequestBody(request, data) {
|
|
|
155
161
|
}
|
|
156
162
|
}
|
|
157
163
|
}
|
|
164
|
+
function decodeResponse(responseBody, contentEncodingHeader) {
|
|
165
|
+
const contentEncodings = contentEncodingHeader.replace(/\s/g, '').split(',');
|
|
166
|
+
contentEncodings.forEach(contentEncoding => {
|
|
167
|
+
switch (contentEncoding) {
|
|
168
|
+
case 'gzip':
|
|
169
|
+
responseBody = zlib.gunzipSync(Buffer.from(responseBody)).toString();
|
|
170
|
+
break;
|
|
171
|
+
case 'deflate':
|
|
172
|
+
responseBody = zlib.inflateSync(Buffer.from(responseBody)).toString();
|
|
173
|
+
break;
|
|
174
|
+
case 'br':
|
|
175
|
+
responseBody = zlib.brotliDecompressSync(Buffer.from(responseBody)).toString();
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
return responseBody;
|
|
180
|
+
}
|
|
158
181
|
module.exports = {
|
|
159
182
|
request,
|
|
160
183
|
doGetRequest,
|
package/package.json
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uoa/lambda-tracing",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0-beta.1",
|
|
4
4
|
"description": "Library for logging & distributed tracing in UoA Lambda projects",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+ssh://git@bitbucket.org/uoa/lambda-tracing.git"
|
|
8
8
|
},
|
|
9
9
|
"author": "Mitchell Faulconbridge <mitchell.faulconbridge@auckland.ac.nz>",
|
|
10
|
+
"contributors": [
|
|
11
|
+
{
|
|
12
|
+
"name": "Mitchell Faulconbridge",
|
|
13
|
+
"email": "mitchell.faulconbridge@auckland.ac.nz"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"name": "Wenlai Wang",
|
|
17
|
+
"email": "w.wang@auckland.ac.nz"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"name": "Osama Kashif",
|
|
21
|
+
"email": "osama.kashif@auckland.ac.nz",
|
|
22
|
+
"url": "https://www.linkedin.com/in/osamakashif"
|
|
23
|
+
}
|
|
24
|
+
],
|
|
10
25
|
"license": "MIT",
|
|
11
26
|
"homepage": "https://bitbucket.org/uoa/lambda-tracing#readme",
|
|
12
27
|
"keywords": [
|
package/uoaHttps.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {context, propagation} from "@opentelemetry/api";
|
|
|
5
5
|
import {RequestOptions} from "https";
|
|
6
6
|
import {ClientRequest} from "http";
|
|
7
7
|
import {XMLParser} from "fast-xml-parser";
|
|
8
|
+
import * as zlib from "node:zlib";
|
|
8
9
|
|
|
9
10
|
function request(options: RequestOptions | string | URL, callback?: (res: http.IncomingMessage) => void): http.ClientRequest;
|
|
10
11
|
function request(url: string | URL, options: RequestOptions, callback?: (res: http.IncomingMessage) => void): http.ClientRequest;
|
|
@@ -101,6 +102,12 @@ function doHttpsRequest(options: RequestOptions, resolve: any, reject: any): Cli
|
|
|
101
102
|
let body: Buffer = Buffer.concat(chunks);
|
|
102
103
|
let parsedBody: any = body.toString();
|
|
103
104
|
|
|
105
|
+
//Get the response content-encoding header value so we can decode before parsing
|
|
106
|
+
const responseContentEncoding: string = response.headers["content-encoding"]?.toLowerCase() ?? '';
|
|
107
|
+
if (responseContentEncoding !== '') {
|
|
108
|
+
parsedBody = decodeResponse(parsedBody, responseContentEncoding);
|
|
109
|
+
}
|
|
110
|
+
|
|
104
111
|
//Get the response content-type header value so we can apply different parsing methods
|
|
105
112
|
const responseContentType: string = response.headers["content-type"]?.toLowerCase() ?? '';
|
|
106
113
|
if (responseContentType === '' || responseContentType.includes('json')) {
|
|
@@ -146,6 +153,24 @@ function setRequestBody(request: ClientRequest, data: any) {
|
|
|
146
153
|
}
|
|
147
154
|
}
|
|
148
155
|
|
|
156
|
+
function decodeResponse(responseBody: string, contentEncodingHeader: string): string {
|
|
157
|
+
const contentEncodings: string[] = contentEncodingHeader.replace(/\s/g, '').split(',');
|
|
158
|
+
contentEncodings.forEach(contentEncoding => {
|
|
159
|
+
switch (contentEncoding) {
|
|
160
|
+
case 'gzip':
|
|
161
|
+
responseBody = zlib.gunzipSync(Buffer.from(responseBody)).toString();
|
|
162
|
+
break;
|
|
163
|
+
case 'deflate':
|
|
164
|
+
responseBody = zlib.inflateSync(Buffer.from(responseBody)).toString();
|
|
165
|
+
break;
|
|
166
|
+
case 'br':
|
|
167
|
+
responseBody = zlib.brotliDecompressSync(Buffer.from(responseBody)).toString();
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
return responseBody;
|
|
172
|
+
}
|
|
173
|
+
|
|
149
174
|
module.exports = {
|
|
150
175
|
request,
|
|
151
176
|
doGetRequest,
|