Skip to content

Commit d932bb9

Browse files
authored
Merge pull request #577 from vtex/update/logs-instrumentation
Update logging instrumentation
2 parents 23321f3 + 9841d3a commit d932bb9

23 files changed

Lines changed: 264 additions & 64 deletions

File tree

package.json

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"dependencies": {
5050
"@types/koa": "^2.11.0",
5151
"@types/koa-compose": "^3.2.3",
52+
"@vtex/diagnostics-nodejs": "0.1.0-beta.8",
5253
"@vtex/node-error-report": "^0.0.3",
5354
"@wry/equality": "^0.1.9",
5455
"agentkeepalive": "^4.0.2",
@@ -121,7 +122,28 @@
121122
"tslint-config-vtex": "^2.1.0",
122123
"tslint-eslint-rules": "^5.4.0",
123124
"typemoq": "^2.1.0",
124-
"typescript": "^3.8.3",
125+
"typescript": "^4.4.4",
125126
"typescript-json-schema": "^0.40.0"
127+
},
128+
"resolutions": {
129+
"@opentelemetry/core": "1.30.1",
130+
"@opentelemetry/exporter-metrics-otlp-grpc": "0.57.2",
131+
"@opentelemetry/exporter-metrics-otlp-http": "0.57.2",
132+
"@opentelemetry/exporter-logs-otlp-grpc": "0.57.2",
133+
"@opentelemetry/exporter-logs-otlp-http": "0.57.2",
134+
"@opentelemetry/exporter-trace-otlp-grpc": "0.57.2",
135+
"@opentelemetry/exporter-trace-otlp-http": "0.57.2",
136+
"@opentelemetry/instrumentation": "0.57.2",
137+
"@opentelemetry/instrumentation-http": "0.57.2",
138+
"@opentelemetry/instrumentation-grpc": "0.57.2",
139+
"@opentelemetry/instrumentation-net": "0.43.1",
140+
"@opentelemetry/propagator-b3": "1.30.1",
141+
"@opentelemetry/resource-detector-aws": "1.12.0",
142+
"@opentelemetry/resources": "1.30.1",
143+
"@opentelemetry/sdk-node": "0.57.2",
144+
"@opentelemetry/sdk-logs": "0.57.2",
145+
"@opentelemetry/sdk-metrics": "1.30.1",
146+
"@opentelemetry/sdk-trace-base": "1.30.1",
147+
"@opentelemetry/sdk-trace-node": "1.30.1"
126148
}
127149
}

src/HttpClient/middlewares/cache.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ export const cacheMiddleware = ({ type, storage, asyncSet }: CacheOptions) => {
109109

110110

111111
const cacheReadSpan = createCacheSpan(cacheType, 'read', tracer, span)
112-
let cached: void | Cached
112+
let cached: void | Cached = undefined
113113
try {
114114
const cacheHasWithSegment = await storage.has(keyWithSegment)
115115
cached = cacheHasWithSegment ? await storage.get(keyWithSegment) : await storage.get(key)
116-
} catch (error) {
116+
} catch (error: any) {
117117
ErrorReport.create({ originalError: error }).injectOnSpan(cacheReadSpan)
118118
logger?.warn({ message: 'Error reading from the HttpClient cache', error })
119119
} finally {
@@ -247,7 +247,7 @@ export const cacheMiddleware = ({ type, storage, asyncSet }: CacheOptions) => {
247247
[HttpCacheLogFields.RESPONSE_TYPE]: responseType,
248248
})
249249
}
250-
} catch (error) {
250+
} catch (error: any) {
251251
ErrorReport.create({ originalError: error }).injectOnSpan(cacheWriteSpan)
252252
logger?.warn({ message: 'Error writing to the HttpClient cache', error })
253253
} finally {

src/HttpClient/middlewares/metrics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const metricsMiddleware = ({metrics, serverTiming, name}: MetricsOpts) =>
4343
if (ctx.config.metric && ctx.response && ctx.response.status) {
4444
status = statusLabel(ctx.response.status)
4545
}
46-
} catch (err) {
46+
} catch (err: any) {
4747
const isCancelled = (err.message === cancelMessage)
4848
if (ctx.config.metric) {
4949
errorCode = err.code

src/HttpClient/middlewares/recorder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const recorderMiddleware = (recorder: Recorder) =>
1515
if (ctx.response) {
1616
(recorder as Recorder).record(ctx.response.headers)
1717
}
18-
} catch (err) {
18+
} catch (err: any) {
1919
if (err.response && err.response.headers && err.response.status === 404) {
2020
(recorder as Recorder).record(err.response.headers)
2121
}

src/HttpClient/middlewares/tracing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const createHttpClientTracingMiddleware = ({
6262
try {
6363
await next()
6464
response = ctx.response
65-
} catch (err) {
65+
} catch (err: any) {
6666
response = err.response
6767
if(ctx.tracing?.isSampled) {
6868
ErrorReport.create({ originalError: err }).injectOnSpan(span, logger)

src/caches/DiskCache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class DiskCache<V> implements CacheLayer<string, V>{
4343
resolve(fileData)
4444
} catch (e) {
4545
release()
46-
resolve(undefined)
46+
resolve(null as unknown as V)
4747
}
4848
})
4949
})

src/caches/LRUDiskCache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class LRUDiskCache<V> implements CacheLayer<string, V>{
7979
resolve(fileData)
8080
} catch (e) {
8181
release()
82-
resolve(undefined)
82+
resolve(null as unknown as V)
8383
}
8484
})
8585
})

src/clients/infra/Apps.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ export class Apps extends InfraClient {
116116
return this.installRuntime(descriptor, tracingConfig)
117117
}
118118

119-
const metric = 'apps-install'
119+
const metric = 'apps-install'
120120
return this.http.post<AppInstallResponse>(
121121
this.routes.Apps(),
122122
{ id: descriptor },
123-
{
123+
{
124124
metric,
125125
tracing: {
126126
requestSpanNameSuffix: metric,
@@ -131,9 +131,9 @@ export class Apps extends InfraClient {
131131
}
132132

133133
public uninstallApp = (app: string, tracingConfig?: RequestTracingConfig) => {
134-
const metric = 'apps-uninstall'
135-
return this.http.delete(this.routes.App(app), {
136-
metric,
134+
const metric = 'apps-uninstall'
135+
return this.http.delete(this.routes.App(app), {
136+
metric,
137137
tracing: {
138138
requestSpanNameSuffix: metric,
139139
...tracingConfig?.tracing,
@@ -142,9 +142,9 @@ export class Apps extends InfraClient {
142142
}
143143

144144
public acknowledgeApp = (app: string, service: string, tracingConfig?: RequestTracingConfig) => {
145-
const metric = 'apps-ack'
146-
return this.http.put(this.routes.Acknowledge(app, service), null, {
147-
metric,
145+
const metric = 'apps-ack'
146+
return this.http.put(this.routes.Acknowledge(app, service), null, {
147+
metric,
148148
tracing: {
149149
requestSpanNameSuffix: metric,
150150
...tracingConfig?.tracing,
@@ -189,7 +189,7 @@ export class Apps extends InfraClient {
189189
const [response] = await Promise.all([request, finalize])
190190
response.bundleSize = zip.pointer()
191191
return response
192-
} catch (e) {
192+
} catch (e: any) {
193193
e.bundleSize = zip.pointer()
194194
throw e
195195
}
@@ -212,7 +212,7 @@ export class Apps extends InfraClient {
212212
throw e
213213
})
214214

215-
const metric = 'apps-patch'
215+
const metric = 'apps-patch'
216216
const request = this.http.patch(this.routes.Link(app), zip, {
217217
headers: { 'Content-Type': 'application/zip' },
218218
metric,
@@ -252,8 +252,8 @@ export class Apps extends InfraClient {
252252
const headers = {'Content-Type': 'application/json'}
253253
const metric = 'apps-save'
254254
return this.http.put(this.routes.Settings(app), settings, {
255-
headers,
256-
metric,
255+
headers,
256+
metric,
257257
tracing: {
258258
requestSpanNameSuffix: metric,
259259
...tracingConfig?.tracing,
@@ -302,7 +302,7 @@ export class Apps extends InfraClient {
302302

303303
public listLinks = (tracingConfig?: RequestTracingConfig) => {
304304
const inflightKey = inflightURL
305-
const metric = 'apps-list-links'
305+
const metric = 'apps-list-links'
306306
return this.http.get<string[]>(this.routes.Links(), {
307307
inflightKey,
308308
metric,
@@ -363,7 +363,7 @@ export class Apps extends InfraClient {
363363

364364
public getFileFromApps = <T extends object | null>(app: string, path: string, nullIfNotFound?: boolean, tracingConfig?: RequestTracingConfig) => {
365365
const inflightKey = inflightURL
366-
const metric = 'get-file-from-apps'
366+
const metric = 'get-file-from-apps'
367367
return this.http.get<T>(this.routes.FileFromApps(app, path), {
368368
cacheable: CacheType.Memory,
369369
inflightKey,
@@ -519,7 +519,7 @@ export class Apps extends InfraClient {
519519
}
520520

521521
public updateDependencies = (tracingConfig?: RequestTracingConfig) => {
522-
const metric = 'apps-update-deps'
522+
const metric = 'apps-update-deps'
523523
return this.http.put<Record<string, string[]>>(this.routes.Dependencies(), null, {
524524
metric,
525525
tracing: {
@@ -530,7 +530,7 @@ export class Apps extends InfraClient {
530530
}
531531

532532
public updateDependency = (name: string, version: string, registry: string, tracingConfig?: RequestTracingConfig) => {
533-
const metric = 'apps-update-dep'
533+
const metric = 'apps-update-dep'
534534
return this.http.patch(this.routes.Apps(), [{name, version, registry}], {
535535
metric,
536536
tracing: {

src/clients/infra/Registry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ export class Registry extends InfraClient {
231231
const [response] = await Promise.all([request, finalize])
232232
response.bundleSize = zip.pointer()
233233
return response
234-
} catch (e) {
234+
} catch (e: any) {
235235
e.bundleSize = zip.pointer()
236236
throw e
237237
}

src/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,5 @@ export const PRODUCTION = process.env.VTEX_PRODUCTION === 'true'
7272
export const INSPECT_DEBUGGER_PORT = 5858
7373

7474
export const cancellableMethods = new Set(['GET', 'OPTIONS', 'HEAD'])
75+
76+
export const LOG_CLIENT_INIT_TIMEOUT_MS = 5000

0 commit comments

Comments
 (0)