@gitpod/gitpod-protocol 0.1.5-test.9 → 0.1.5-tweak-workspaceconfig-origin-docs-fork.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/data/builtin-theia-plugins.json +28 -18
- package/data/gitpod-schema.json +17 -17
- package/lib/accounting-protocol.d.ts +155 -0
- package/lib/accounting-protocol.d.ts.map +1 -0
- package/lib/accounting-protocol.js +109 -0
- package/lib/accounting-protocol.js.map +1 -0
- package/lib/admin-protocol.d.ts +22 -5
- package/lib/admin-protocol.d.ts.map +1 -1
- package/lib/admin-protocol.js +16 -1
- package/lib/admin-protocol.js.map +1 -1
- package/lib/analytics.d.ts +45 -0
- package/lib/analytics.d.ts.map +1 -0
- package/lib/analytics.js +10 -0
- package/lib/analytics.js.map +1 -0
- package/lib/auth.d.ts +25 -0
- package/lib/auth.d.ts.map +1 -0
- package/lib/auth.js +16 -0
- package/lib/auth.js.map +1 -0
- package/lib/context-url.d.ts +18 -0
- package/lib/context-url.d.ts.map +1 -0
- package/lib/context-url.js +49 -0
- package/lib/context-url.js.map +1 -0
- package/lib/context-url.spec.d.ts +12 -0
- package/lib/context-url.spec.d.ts.map +1 -0
- package/lib/context-url.spec.js +73 -0
- package/lib/context-url.spec.js.map +1 -0
- package/lib/email-protocol.d.ts +2 -2
- package/lib/email-protocol.d.ts.map +1 -1
- package/lib/email-protocol.js +6 -5
- package/lib/email-protocol.js.map +1 -1
- package/lib/encryption/container-module.d.ts +1 -1
- package/lib/encryption/container-module.js +7 -5
- package/lib/encryption/container-module.js.map +1 -1
- package/lib/encryption/encryption-engine.d.ts +1 -1
- package/lib/encryption/encryption-engine.js +21 -21
- package/lib/encryption/encryption-engine.js.map +1 -1
- package/lib/encryption/encryption-engine.spec.d.ts +2 -2
- package/lib/encryption/encryption-engine.spec.d.ts.map +1 -1
- package/lib/encryption/encryption-engine.spec.js +31 -37
- package/lib/encryption/encryption-engine.spec.js.map +1 -1
- package/lib/encryption/encryption-service.d.ts +1 -1
- package/lib/encryption/encryption-service.js +31 -44
- package/lib/encryption/encryption-service.js.map +1 -1
- package/lib/encryption/key-provider.d.ts +2 -2
- package/lib/encryption/key-provider.d.ts.map +1 -1
- package/lib/encryption/key-provider.js +27 -31
- package/lib/encryption/key-provider.js.map +1 -1
- package/lib/env.d.ts +2 -3
- package/lib/env.d.ts.map +1 -1
- package/lib/env.js +21 -21
- package/lib/env.js.map +1 -1
- package/lib/gitpod-file-parser.d.ts +1 -1
- package/lib/gitpod-file-parser.js +27 -42
- package/lib/gitpod-file-parser.js.map +1 -1
- package/lib/gitpod-file-parser.spec.d.ts +1 -1
- package/lib/gitpod-file-parser.spec.js +117 -117
- package/lib/gitpod-file-parser.spec.js.map +1 -1
- package/lib/gitpod-service.d.ts +186 -34
- package/lib/gitpod-service.d.ts.map +1 -1
- package/lib/gitpod-service.js +239 -116
- package/lib/gitpod-service.js.map +1 -1
- package/lib/headless-workspace-log.d.ts +9 -12
- package/lib/headless-workspace-log.d.ts.map +1 -1
- package/lib/headless-workspace-log.js +5 -7
- package/lib/headless-workspace-log.js.map +1 -1
- package/lib/ide-frontend-service.d.ts +26 -0
- package/lib/ide-frontend-service.d.ts.map +1 -0
- package/lib/ide-frontend-service.js +8 -0
- package/lib/ide-frontend-service.js.map +1 -0
- package/lib/ide-protocol.d.ts +81 -0
- package/lib/ide-protocol.d.ts.map +1 -0
- package/lib/{util/without.js → ide-protocol.js} +2 -2
- package/lib/ide-protocol.js.map +1 -0
- package/lib/index.d.ts +5 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +25 -12
- package/lib/index.js.map +1 -1
- package/lib/license-protocol.d.ts +1 -1
- package/lib/license-protocol.js +2 -1
- package/lib/license-protocol.js.map +1 -1
- package/lib/messaging/browser/connection.d.ts +6 -4
- package/lib/messaging/browser/connection.d.ts.map +1 -1
- package/lib/messaging/browser/connection.js +188 -48
- package/lib/messaging/browser/connection.js.map +1 -1
- package/lib/messaging/browser/window-connection.d.ts +26 -0
- package/lib/messaging/browser/window-connection.d.ts.map +1 -0
- package/lib/messaging/browser/window-connection.js +68 -0
- package/lib/messaging/browser/window-connection.js.map +1 -0
- package/lib/messaging/client-call-metrics.d.ts +35 -0
- package/lib/messaging/client-call-metrics.d.ts.map +1 -0
- package/lib/messaging/client-call-metrics.js +83 -0
- package/lib/messaging/client-call-metrics.js.map +1 -0
- package/lib/messaging/connection-error-handler.js +12 -23
- package/lib/messaging/connection-error-handler.js.map +1 -1
- package/lib/messaging/error.d.ts +6 -2
- package/lib/messaging/error.d.ts.map +1 -1
- package/lib/messaging/error.js +13 -4
- package/lib/messaging/error.js.map +1 -1
- package/lib/messaging/handler.d.ts +10 -0
- package/lib/messaging/handler.d.ts.map +1 -1
- package/lib/messaging/handler.js +1 -0
- package/lib/messaging/handler.js.map +1 -1
- package/lib/messaging/node/connection.js +23 -22
- package/lib/messaging/node/connection.js.map +1 -1
- package/lib/messaging/proxy-factory.d.ts +2 -0
- package/lib/messaging/proxy-factory.d.ts.map +1 -1
- package/lib/messaging/proxy-factory.js +75 -169
- package/lib/messaging/proxy-factory.js.map +1 -1
- package/lib/payment-protocol.d.ts +18 -0
- package/lib/payment-protocol.d.ts.map +1 -0
- package/lib/payment-protocol.js +13 -0
- package/lib/payment-protocol.js.map +1 -0
- package/lib/permission.d.ts +14 -12
- package/lib/permission.d.ts.map +1 -1
- package/lib/permission.js +21 -19
- package/lib/permission.js.map +1 -1
- package/lib/plans.d.ts +210 -0
- package/lib/plans.d.ts.map +1 -0
- package/lib/plans.js +570 -0
- package/lib/plans.js.map +1 -0
- package/lib/protocol.d.ts +123 -30
- package/lib/protocol.d.ts.map +1 -1
- package/lib/protocol.js +121 -117
- package/lib/protocol.js.map +1 -1
- package/lib/snapshot-url.d.ts +14 -0
- package/lib/snapshot-url.d.ts.map +1 -0
- package/lib/snapshot-url.js +26 -0
- package/lib/snapshot-url.js.map +1 -0
- package/{src/util/without.ts → lib/snapshot-url.spec.d.ts} +3 -4
- package/lib/snapshot-url.spec.d.ts.map +1 -0
- package/lib/snapshot-url.spec.js +41 -0
- package/lib/snapshot-url.spec.js.map +1 -0
- package/lib/team-subscription-protocol.d.ts +73 -0
- package/lib/team-subscription-protocol.d.ts.map +1 -0
- package/lib/team-subscription-protocol.js +63 -0
- package/lib/team-subscription-protocol.js.map +1 -0
- package/lib/teams-projects-protocol.d.ts +103 -0
- package/lib/teams-projects-protocol.d.ts.map +1 -0
- package/lib/teams-projects-protocol.js +23 -0
- package/lib/teams-projects-protocol.js.map +1 -0
- package/lib/theia-plugins.d.ts +1 -1
- package/lib/theia-plugins.js +1 -1
- package/lib/typings/globals.d.ts +12 -0
- package/lib/typings/globals.d.ts.map +1 -0
- package/lib/typings/globals.js +7 -0
- package/lib/typings/globals.js.map +1 -0
- package/lib/util/analytics.d.ts +8 -0
- package/lib/util/analytics.d.ts.map +1 -0
- package/lib/util/analytics.js +79 -0
- package/lib/util/analytics.js.map +1 -0
- package/lib/util/async-iterator.d.ts +1 -1
- package/lib/util/async-iterator.js +57 -134
- package/lib/util/async-iterator.js.map +1 -1
- package/lib/util/cancelable.d.ts +1 -1
- package/lib/util/cancelable.js +19 -60
- package/lib/util/cancelable.js.map +1 -1
- package/lib/util/date-time.d.ts +1 -1
- package/lib/util/date-time.js +10 -9
- package/lib/util/date-time.js.map +1 -1
- package/lib/util/deep-partial.d.ts +1 -1
- package/lib/util/deep-partial.js +1 -1
- package/lib/util/deferred.d.ts +1 -1
- package/lib/util/deferred.js +12 -13
- package/lib/util/deferred.js.map +1 -1
- package/lib/util/disposable.d.ts +2 -2
- package/lib/util/disposable.d.ts.map +1 -1
- package/lib/util/disposable.js +27 -39
- package/lib/util/disposable.js.map +1 -1
- package/lib/util/event.d.ts +1 -1
- package/lib/util/event.d.ts.map +1 -1
- package/lib/util/event.js +59 -74
- package/lib/util/event.js.map +1 -1
- package/lib/util/garbage-collected-cache.d.ts +1 -1
- package/lib/util/garbage-collected-cache.js +24 -47
- package/lib/util/garbage-collected-cache.js.map +1 -1
- package/lib/util/generate-workspace-id.d.ts +4 -0
- package/lib/util/generate-workspace-id.d.ts.map +1 -0
- package/lib/util/generate-workspace-id.js +470 -0
- package/lib/util/generate-workspace-id.js.map +1 -0
- package/lib/util/generate-workspace-id.spec.d.ts +7 -0
- package/lib/util/generate-workspace-id.spec.d.ts.map +1 -0
- package/lib/util/generate-workspace-id.spec.js +63 -0
- package/lib/util/generate-workspace-id.spec.js.map +1 -0
- package/lib/util/gitpod-cookie.d.ts +20 -0
- package/lib/util/gitpod-cookie.d.ts.map +1 -0
- package/lib/util/gitpod-cookie.js +44 -0
- package/lib/util/gitpod-cookie.js.map +1 -0
- package/lib/util/gitpod-host-url.d.ts +8 -3
- package/lib/util/gitpod-host-url.d.ts.map +1 -1
- package/lib/util/gitpod-host-url.js +106 -76
- package/lib/util/gitpod-host-url.js.map +1 -1
- package/lib/util/gitpod-host-url.spec.d.ts +16 -0
- package/lib/util/gitpod-host-url.spec.d.ts.map +1 -0
- package/lib/util/gitpod-host-url.spec.js +124 -0
- package/lib/util/gitpod-host-url.spec.js.map +1 -0
- package/lib/util/grpc.d.ts +15 -0
- package/lib/util/grpc.d.ts.map +1 -0
- package/lib/util/grpc.js +18 -0
- package/lib/util/grpc.js.map +1 -0
- package/lib/util/logging.d.ts +57 -34
- package/lib/util/logging.d.ts.map +1 -1
- package/lib/util/logging.js +119 -110
- package/lib/util/logging.js.map +1 -1
- package/lib/util/make-link.d.ts +1 -1
- package/lib/util/make-link.js +4 -3
- package/lib/util/make-link.js.map +1 -1
- package/lib/util/parse-workspace-id.d.ts +14 -4
- package/lib/util/parse-workspace-id.d.ts.map +1 -1
- package/lib/util/parse-workspace-id.js +39 -8
- package/lib/util/parse-workspace-id.js.map +1 -1
- package/lib/util/parse-workspace-id.spec.d.ts +9 -1
- package/lib/util/parse-workspace-id.spec.d.ts.map +1 -1
- package/lib/util/parse-workspace-id.spec.js +129 -48
- package/lib/util/parse-workspace-id.spec.js.map +1 -1
- package/lib/util/queue.d.ts +1 -1
- package/lib/util/queue.js +18 -56
- package/lib/util/queue.js.map +1 -1
- package/lib/util/queue.spec.d.ts +1 -1
- package/lib/util/queue.spec.js +145 -287
- package/lib/util/queue.spec.js.map +1 -1
- package/lib/util/repeater.d.ts +1 -1
- package/lib/util/repeater.js +37 -89
- package/lib/util/repeater.js.map +1 -1
- package/lib/util/safe-promise.d.ts +1 -1
- package/lib/util/safe-promise.js +11 -13
- package/lib/util/safe-promise.js.map +1 -1
- package/lib/util/semaphore.d.ts +1 -1
- package/lib/util/semaphore.js +17 -47
- package/lib/util/semaphore.js.map +1 -1
- package/lib/util/skip-if.d.ts +1 -1
- package/lib/util/skip-if.js +8 -7
- package/lib/util/skip-if.js.map +1 -1
- package/lib/util/timeutil.d.ts +1 -1
- package/lib/util/timeutil.d.ts.map +1 -1
- package/lib/util/timeutil.js +30 -17
- package/lib/util/timeutil.js.map +1 -1
- package/lib/util/timeutil.spec.d.ts +1 -1
- package/lib/util/timeutil.spec.js +23 -25
- package/lib/util/timeutil.spec.js.map +1 -1
- package/lib/util/tracing.d.ts +15 -2
- package/lib/util/tracing.d.ts.map +1 -1
- package/lib/util/tracing.js +86 -51
- package/lib/util/tracing.js.map +1 -1
- package/lib/util/workspace-port-authentication.d.ts +1 -1
- package/lib/util/workspace-port-authentication.d.ts.map +1 -1
- package/lib/util/workspace-port-authentication.js +5 -3
- package/lib/util/workspace-port-authentication.js.map +1 -1
- package/lib/workspace-cluster.d.ts +74 -0
- package/lib/workspace-cluster.d.ts.map +1 -0
- package/lib/workspace-cluster.js +16 -0
- package/lib/workspace-cluster.js.map +1 -0
- package/lib/workspace-instance.d.ts +10 -4
- package/lib/workspace-instance.d.ts.map +1 -1
- package/lib/workspace-instance.js +1 -1
- package/lib/wsready.d.ts +1 -1
- package/lib/wsready.js +3 -2
- package/lib/wsready.js.map +1 -1
- package/package.json +32 -16
- package/pkg-yarn.lock +18 -9
- package/src/accounting-protocol.ts +229 -0
- package/src/admin-protocol.ts +41 -6
- package/src/analytics.ts +54 -0
- package/src/auth.ts +27 -0
- package/src/context-url.spec.ts +39 -0
- package/src/context-url.ts +51 -0
- package/src/email-protocol.ts +3 -4
- package/src/encryption/container-module.ts +1 -1
- package/src/encryption/encryption-engine.spec.ts +1 -1
- package/src/encryption/encryption-engine.ts +1 -1
- package/src/encryption/encryption-service.ts +1 -1
- package/src/encryption/key-provider.ts +1 -1
- package/src/env.ts +11 -11
- package/src/gitpod-file-parser.spec.ts +1 -1
- package/src/gitpod-file-parser.ts +1 -1
- package/src/gitpod-service.ts +386 -52
- package/src/headless-workspace-log.ts +8 -12
- package/src/ide-frontend-service.ts +28 -0
- package/src/ide-protocol.ts +92 -0
- package/src/index.ts +6 -2
- package/src/license-protocol.ts +1 -1
- package/src/messaging/browser/connection.ts +201 -23
- package/src/messaging/browser/window-connection.ts +72 -0
- package/src/messaging/client-call-metrics.ts +97 -0
- package/src/messaging/error.ts +16 -4
- package/src/messaging/handler.ts +12 -0
- package/src/messaging/node/connection.ts +2 -2
- package/src/messaging/proxy-factory.ts +16 -14
- package/src/payment-protocol.ts +20 -0
- package/src/permission.ts +9 -8
- package/src/plans.ts +632 -0
- package/src/protocol.ts +204 -61
- package/src/snapshot-url.spec.ts +25 -0
- package/src/snapshot-url.ts +27 -0
- package/src/team-subscription-protocol.ts +113 -0
- package/src/teams-projects-protocol.ts +132 -0
- package/src/theia-plugins.ts +1 -1
- package/src/typings/globals.ts +12 -0
- package/src/util/analytics.ts +87 -0
- package/src/util/async-iterator.ts +1 -1
- package/src/util/cancelable.ts +1 -1
- package/src/util/date-time.ts +1 -1
- package/src/util/deep-partial.ts +1 -1
- package/src/util/deferred.ts +2 -2
- package/src/util/garbage-collected-cache.ts +3 -3
- package/src/util/generate-workspace-id.spec.ts +31 -0
- package/src/util/generate-workspace-id.ts +457 -0
- package/src/util/gitpod-cookie.ts +39 -0
- package/src/util/gitpod-host-url.spec.ts +49 -0
- package/src/util/gitpod-host-url.ts +58 -14
- package/src/util/grpc.ts +15 -0
- package/src/util/jaeger-client.d.ts +1 -1
- package/src/util/logging.ts +111 -39
- package/src/util/make-link.ts +1 -1
- package/src/util/parse-workspace-id.spec.ts +46 -5
- package/src/util/parse-workspace-id.ts +39 -8
- package/src/util/queue.spec.ts +2 -2
- package/src/util/queue.ts +1 -1
- package/src/util/repeater.ts +1 -1
- package/src/util/safe-promise.ts +1 -1
- package/src/util/semaphore.ts +3 -3
- package/src/util/skip-if.ts +2 -2
- package/src/util/timeutil.spec.ts +1 -1
- package/src/util/timeutil.ts +5 -5
- package/src/util/tracing.ts +66 -4
- package/src/util/workspace-port-authentication.ts +1 -1
- package/src/workspace-cluster.ts +96 -0
- package/src/workspace-instance.ts +38 -16
- package/src/wsready.ts +2 -2
- package/lib/util/without.d.ts +0 -7
- package/lib/util/without.d.ts.map +0 -1
- package/lib/util/without.js.map +0 -1
package/src/util/logging.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c) 2020
|
|
2
|
+
* Copyright (c) 2020 Gitpod GmbH. All rights reserved.
|
|
3
3
|
* Licensed under the GNU Affero General Public License (AGPL).
|
|
4
4
|
* See License-AGPL.txt in the project root for license information.
|
|
5
5
|
*/
|
|
@@ -16,72 +16,80 @@ export interface LogContext {
|
|
|
16
16
|
userId?: string;
|
|
17
17
|
workspaceId?: string;
|
|
18
18
|
};
|
|
19
|
+
export namespace LogContext {
|
|
20
|
+
export function from(params : { userId?: string, user?: any, request?: any } ) {
|
|
21
|
+
return <LogContext>{
|
|
22
|
+
sessionId: params.request?.requestID,
|
|
23
|
+
userId: params.userId || params.user?.id
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
19
27
|
|
|
20
28
|
export interface LogPayload {
|
|
21
29
|
// placeholder to indicate that only dictionary-style objects should be passed as payload
|
|
22
30
|
};
|
|
23
31
|
|
|
24
32
|
export namespace log {
|
|
25
|
-
export function error(context: LogContext, message: string, error:
|
|
26
|
-
export function error(context: LogContext, message: string, error:
|
|
33
|
+
export function error(context: LogContext, message: string, error: any, payload: LogPayload): void;
|
|
34
|
+
export function error(context: LogContext, message: string, error: any): void;
|
|
27
35
|
export function error(context: LogContext, message: string, payload: LogPayload): void;
|
|
28
36
|
export function error(context: LogContext, message: string): void;
|
|
29
|
-
export function error(context: LogContext, error:
|
|
30
|
-
export function error(context: LogContext, error:
|
|
31
|
-
export function error(message: string, error:
|
|
32
|
-
export function error(message: string, error:
|
|
37
|
+
export function error(context: LogContext, error: any, payload: LogPayload): void;
|
|
38
|
+
export function error(context: LogContext, error: any): void;
|
|
39
|
+
export function error(message: string, error: any, payload: LogPayload): void;
|
|
40
|
+
export function error(message: string, error: any): void;
|
|
33
41
|
export function error(message: string, payload: LogPayload): void;
|
|
34
42
|
export function error(message: string): void;
|
|
35
|
-
export function error(error:
|
|
36
|
-
export function error(error:
|
|
43
|
+
export function error(error: any, payload: LogPayload): void;
|
|
44
|
+
export function error(error: any): void;
|
|
37
45
|
export function error(...args: any[]): void {
|
|
38
46
|
errorLog(false, args);
|
|
39
47
|
}
|
|
40
48
|
|
|
41
|
-
export function warn(context: LogContext, message: string, error:
|
|
42
|
-
export function warn(context: LogContext, message: string, error:
|
|
49
|
+
export function warn(context: LogContext, message: string, error: any, payload: LogPayload): void;
|
|
50
|
+
export function warn(context: LogContext, message: string, error: any): void;
|
|
43
51
|
export function warn(context: LogContext, message: string, payload: LogPayload): void;
|
|
44
52
|
export function warn(context: LogContext, message: string): void;
|
|
45
|
-
export function warn(context: LogContext, error:
|
|
46
|
-
export function warn(context: LogContext, error:
|
|
47
|
-
export function warn(message: string, error:
|
|
48
|
-
export function warn(message: string, error:
|
|
53
|
+
export function warn(context: LogContext, error: any, payload: LogPayload): void;
|
|
54
|
+
export function warn(context: LogContext, error: any): void;
|
|
55
|
+
export function warn(message: string, error: any, payload: LogPayload): void;
|
|
56
|
+
export function warn(message: string, error: any): void;
|
|
49
57
|
export function warn(message: string, payload: LogPayload): void;
|
|
50
58
|
export function warn(message: string): void;
|
|
51
|
-
export function warn(error:
|
|
52
|
-
export function warn(error:
|
|
59
|
+
export function warn(error: any, payload: LogPayload): void;
|
|
60
|
+
export function warn(error: any): void;
|
|
53
61
|
export function warn(...args: any[]): void {
|
|
54
62
|
warnLog(false, args);
|
|
55
63
|
}
|
|
56
64
|
|
|
57
|
-
export function info(context: LogContext, message: string, error:
|
|
58
|
-
export function info(context: LogContext, message: string, error:
|
|
65
|
+
export function info(context: LogContext, message: string, error: any, payload: LogPayload): void;
|
|
66
|
+
export function info(context: LogContext, message: string, error: any): void;
|
|
59
67
|
export function info(context: LogContext, message: string, payload: LogPayload): void;
|
|
60
68
|
export function info(context: LogContext, message: string): void;
|
|
61
|
-
export function info(context: LogContext, error:
|
|
62
|
-
export function info(context: LogContext, error:
|
|
63
|
-
export function info(message: string, error:
|
|
64
|
-
export function info(message: string, error:
|
|
69
|
+
export function info(context: LogContext, error: any, payload: LogPayload): void;
|
|
70
|
+
export function info(context: LogContext, error: any): void;
|
|
71
|
+
export function info(message: string, error: any, payload: LogPayload): void;
|
|
72
|
+
export function info(message: string, error: any): void;
|
|
65
73
|
export function info(message: string, payload: LogPayload): void;
|
|
66
74
|
export function info(message: string): void;
|
|
67
|
-
export function info(error:
|
|
68
|
-
export function info(error:
|
|
75
|
+
export function info(error: any, payload: LogPayload): void;
|
|
76
|
+
export function info(error: any): void;
|
|
69
77
|
export function info(...args: any[]): void {
|
|
70
78
|
infoLog(false, args);
|
|
71
79
|
}
|
|
72
80
|
|
|
73
|
-
export function debug(context: LogContext, message: string, error:
|
|
74
|
-
export function debug(context: LogContext, message: string, error:
|
|
81
|
+
export function debug(context: LogContext, message: string, error: any, payload: LogPayload): void;
|
|
82
|
+
export function debug(context: LogContext, message: string, error: any): void;
|
|
75
83
|
export function debug(context: LogContext, message: string, payload: LogPayload): void;
|
|
76
84
|
export function debug(context: LogContext, message: string): void;
|
|
77
|
-
export function debug(context: LogContext, error:
|
|
78
|
-
export function debug(context: LogContext, error:
|
|
79
|
-
export function debug(message: string, error:
|
|
80
|
-
export function debug(message: string, error:
|
|
85
|
+
export function debug(context: LogContext, error: any, payload: LogPayload): void;
|
|
86
|
+
export function debug(context: LogContext, error: any): void;
|
|
87
|
+
export function debug(message: string, error: any, payload: LogPayload): void;
|
|
88
|
+
export function debug(message: string, error: any): void;
|
|
81
89
|
export function debug(message: string, payload: LogPayload): void;
|
|
82
90
|
export function debug(message: string): void;
|
|
83
|
-
export function debug(error:
|
|
84
|
-
export function debug(error:
|
|
91
|
+
export function debug(error: any, payload: LogPayload): void;
|
|
92
|
+
export function debug(error: any): void;
|
|
85
93
|
export function debug(...args: any[]): void {
|
|
86
94
|
debugLog(false, args);
|
|
87
95
|
}
|
|
@@ -89,10 +97,14 @@ export namespace log {
|
|
|
89
97
|
/**
|
|
90
98
|
* Do not use in frontend.
|
|
91
99
|
*/
|
|
92
|
-
export function enableJSONLogging(componentArg: string, versionArg: string | undefined): void {
|
|
100
|
+
export function enableJSONLogging(componentArg: string, versionArg: string | undefined, logLevel?: LogrusLogLevel): void {
|
|
93
101
|
component = componentArg;
|
|
94
102
|
version = versionArg;
|
|
95
103
|
|
|
104
|
+
setLogLevel(logLevel);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function setLogLevel(logLevel: LogrusLogLevel | undefined) {
|
|
96
108
|
jsonLogging = true;
|
|
97
109
|
|
|
98
110
|
console.error = function (...args: any[]): void {
|
|
@@ -107,8 +119,20 @@ export namespace log {
|
|
|
107
119
|
console.debug = function (...args: any[]): void {
|
|
108
120
|
debugLog(true, args);
|
|
109
121
|
}
|
|
122
|
+
|
|
110
123
|
console.log = console.info;
|
|
111
124
|
// FIXME wrap also other console methods (e.g. trace())
|
|
125
|
+
|
|
126
|
+
// set/unset log functions based on loglevel so we only have to evaluate once, not every call
|
|
127
|
+
const noop = () => {};
|
|
128
|
+
const setLog = (logFunc: DoLogFunction, funcLevel: LogrusLogLevel): DoLogFunction => {
|
|
129
|
+
return LogrusLogLevel.isGreatherOrEqual(funcLevel, logLevel) ? logFunc : noop;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
errorLog = setLog(doErrorLog, "error");
|
|
133
|
+
warnLog = setLog(doWarnLog, "warning");
|
|
134
|
+
infoLog = setLog(doInfoLog, "info");
|
|
135
|
+
debugLog = setLog(doDebugLog, "debug");
|
|
112
136
|
}
|
|
113
137
|
|
|
114
138
|
export function resetToDefaultLogging(): void {
|
|
@@ -120,24 +144,73 @@ export namespace log {
|
|
|
120
144
|
console.info = infoConsoleLog;
|
|
121
145
|
console.debug = debugConsoleLog;
|
|
122
146
|
}
|
|
147
|
+
|
|
148
|
+
export function setVersion(versionArg: string) {
|
|
149
|
+
version = versionArg;
|
|
150
|
+
}
|
|
123
151
|
}
|
|
124
152
|
|
|
125
|
-
|
|
153
|
+
type DoLogFunction = (calledViaConsole: boolean, args: any[]) => void;
|
|
154
|
+
|
|
155
|
+
let errorLog = doErrorLog;
|
|
156
|
+
function doErrorLog(calledViaConsole: boolean, args: any[]): void {
|
|
126
157
|
doLog(calledViaConsole, errorConsoleLog, 'ERROR', args);
|
|
127
158
|
}
|
|
128
159
|
|
|
129
|
-
|
|
160
|
+
let warnLog = doWarnLog;
|
|
161
|
+
function doWarnLog(calledViaConsole: boolean, args: any[]): void {
|
|
130
162
|
doLog(calledViaConsole, warnConsoleLog, 'WARNING', args);
|
|
131
163
|
}
|
|
132
164
|
|
|
133
|
-
|
|
165
|
+
let infoLog = doInfoLog;
|
|
166
|
+
function doInfoLog(calledViaConsole: boolean, args: any[]): void {
|
|
134
167
|
doLog(calledViaConsole, infoConsoleLog, 'INFO', args);
|
|
135
168
|
}
|
|
136
169
|
|
|
137
|
-
|
|
170
|
+
let debugLog = doDebugLog;
|
|
171
|
+
function doDebugLog(calledViaConsole: boolean, args: any[]): void {
|
|
138
172
|
doLog(calledViaConsole, debugConsoleLog, 'DEBUG', args);
|
|
139
173
|
}
|
|
140
174
|
|
|
175
|
+
// Ref: https://github.com/sirupsen/logrus#level-logging
|
|
176
|
+
export type LogrusLogLevel = keyof (typeof LogrusLogLevels);
|
|
177
|
+
export const LogrusLogLevels = {
|
|
178
|
+
trace: true,
|
|
179
|
+
debug: true,
|
|
180
|
+
info: true,
|
|
181
|
+
warning: true,
|
|
182
|
+
error: true,
|
|
183
|
+
fatal: true,
|
|
184
|
+
panic: true,
|
|
185
|
+
}
|
|
186
|
+
export namespace LogrusLogLevel {
|
|
187
|
+
export function isGreatherOrEqual(lvl: LogrusLogLevel | undefined, ref: LogrusLogLevel | undefined): boolean {
|
|
188
|
+
if (lvl === undefined) {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
if (ref === undefined) {
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
return getLevelArity(lvl) >= getLevelArity(ref);
|
|
195
|
+
}
|
|
196
|
+
function getLevelArity(lvl: LogrusLogLevel): number {
|
|
197
|
+
return Object.keys(LogrusLogLevels)
|
|
198
|
+
.findIndex((l) => l === lvl);
|
|
199
|
+
}
|
|
200
|
+
export function getFromEnv(): LogrusLogLevel | undefined {
|
|
201
|
+
const lvlStr = process.env.LOG_LEVEL;
|
|
202
|
+
if (!lvlStr) {
|
|
203
|
+
return undefined;
|
|
204
|
+
}
|
|
205
|
+
const lvl = lvlStr as LogrusLogLevel;
|
|
206
|
+
const exists = LogrusLogLevels[lvl]
|
|
207
|
+
if (!exists) {
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
return lvl;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
141
214
|
// Source: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogSeverity
|
|
142
215
|
type GoogleLogSeverity = 'EMERGENCY' | 'ALERT' | 'CRITICAL' | 'ERROR' | 'WARNING' | 'INFO' | 'DEBUG';
|
|
143
216
|
namespace GoogleLogSeverity {
|
|
@@ -235,7 +308,6 @@ function makeLogItem(severity: GoogleLogSeverity, context: LogContext | undefine
|
|
|
235
308
|
severity,
|
|
236
309
|
time: new Date().toISOString(),
|
|
237
310
|
environment: process.env.KUBE_STAGE,
|
|
238
|
-
region: process.env.GITPOD_REGION,
|
|
239
311
|
context,
|
|
240
312
|
message,
|
|
241
313
|
error,
|
package/src/util/make-link.ts
CHANGED
|
@@ -1,35 +1,76 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c) 2020
|
|
2
|
+
* Copyright (c) 2020 Gitpod GmbH. All rights reserved.
|
|
3
3
|
* Licensed under the GNU Affero General Public License (AGPL).
|
|
4
4
|
* See License-AGPL.txt in the project root for license information.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import * as chai from 'chai';
|
|
8
8
|
import { suite, test } from 'mocha-typescript';
|
|
9
|
-
import { parseWorkspaceIdFromHostname } from './parse-workspace-id';
|
|
9
|
+
import { matchesInstanceIdOrLegacyWorkspaceIdExactly, matchesNewWorkspaceIdExactly, parseWorkspaceIdFromHostname } from './parse-workspace-id';
|
|
10
10
|
const expect = chai.expect;
|
|
11
11
|
|
|
12
12
|
@suite
|
|
13
13
|
export class ParseWorkspaceIdTest {
|
|
14
14
|
|
|
15
15
|
@test public parseWorkspaceIdFromHostname_fromWorkspaceLocation() {
|
|
16
|
+
const actual = parseWorkspaceIdFromHostname("moccasin-ferret-155799b3.ws-eu01.gitpod.io");
|
|
17
|
+
expect(actual).to.equal("moccasin-ferret-155799b3");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@test public parseWorkspaceIdFromHostname_fromWorkspacePortLocation() {
|
|
21
|
+
const actual = parseWorkspaceIdFromHostname("3000-moccasin-ferret-155799b3.ws-eu01.gitpod.io");
|
|
22
|
+
expect(actual).to.equal("moccasin-ferret-155799b3");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@test public parseWorkspaceIdFromHostname_fromWorkspacePortLocationWithWebviewPrefix() {
|
|
26
|
+
const actual = parseWorkspaceIdFromHostname("webview-3000-moccasin-ferret-155799b3.ws-eu01.gitpod.io");
|
|
27
|
+
expect(actual).to.equal("moccasin-ferret-155799b3");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@test public parseWorkspaceIdFromHostname_fromWorkspacePortLocationWithWebviewPrefixCustomHost() {
|
|
31
|
+
const actual = parseWorkspaceIdFromHostname("webview-3000-moccasin-ferret-155799b3.ws-eu01.some.subdomain.somehost.com");
|
|
32
|
+
expect(actual).to.equal("moccasin-ferret-155799b3");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// legacy mode
|
|
36
|
+
@test public parseLegacyWorkspaceIdFromHostname_fromWorkspaceLocation() {
|
|
16
37
|
const actual = parseWorkspaceIdFromHostname("b7e0eaf8-ec73-44ec-81ea-04859263b656.ws-eu01.gitpod.io");
|
|
17
38
|
expect(actual).to.equal("b7e0eaf8-ec73-44ec-81ea-04859263b656");
|
|
18
39
|
}
|
|
19
40
|
|
|
20
|
-
@test public
|
|
41
|
+
@test public parseLegacyWorkspaceIdFromHostname_fromWorkspacePortLocation() {
|
|
21
42
|
const actual = parseWorkspaceIdFromHostname("3000-b7e0eaf8-ec73-44ec-81ea-04859263b656.ws-eu01.gitpod.io");
|
|
22
43
|
expect(actual).to.equal("b7e0eaf8-ec73-44ec-81ea-04859263b656");
|
|
23
44
|
}
|
|
24
45
|
|
|
25
|
-
@test public
|
|
46
|
+
@test public parseLegacyWorkspaceIdFromHostname_fromWorkspacePortLocationWithWebviewPrefix() {
|
|
26
47
|
const actual = parseWorkspaceIdFromHostname("webview-3000-b7e0eaf8-ec73-44ec-81ea-04859263b656.ws-eu01.gitpod.io");
|
|
27
48
|
expect(actual).to.equal("b7e0eaf8-ec73-44ec-81ea-04859263b656");
|
|
28
49
|
}
|
|
29
50
|
|
|
30
|
-
@test public
|
|
51
|
+
@test public parseLegacyWorkspaceIdFromHostname_fromWorkspacePortLocationWithWebviewPrefixCustomHost() {
|
|
31
52
|
const actual = parseWorkspaceIdFromHostname("webview-3000-ca81a50f-09d7-465c-acd9-264a747d5351.ws-eu01.some.subdomain.somehost.com");
|
|
32
53
|
expect(actual).to.equal("ca81a50f-09d7-465c-acd9-264a747d5351");
|
|
33
54
|
}
|
|
55
|
+
|
|
56
|
+
// match - instance ID
|
|
57
|
+
@test public matchesInstanceIdOrLegacyWorkspaceIdExactly_positive() {
|
|
58
|
+
const actual = matchesInstanceIdOrLegacyWorkspaceIdExactly("b7e0eaf8-ec73-44ec-81ea-04859263b656");
|
|
59
|
+
expect(actual).to.be.true;
|
|
60
|
+
}
|
|
61
|
+
@test public matchesInstanceIdOrLegacyWorkspaceIdExactly_negative() {
|
|
62
|
+
const actual = matchesInstanceIdOrLegacyWorkspaceIdExactly("b7e0eaf8-ec73-44ec-81a-04859263b656");
|
|
63
|
+
expect(actual).to.be.false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// match - new workspace ID
|
|
67
|
+
@test public matchesWorkspaceIdExactly_new_positive() {
|
|
68
|
+
const actual = matchesNewWorkspaceIdExactly("moccasin-ferret-155799b3");
|
|
69
|
+
expect(actual).to.be.true;
|
|
70
|
+
}
|
|
71
|
+
@test public matchesWorkspaceIdExactly_new_negative() {
|
|
72
|
+
const actual = matchesNewWorkspaceIdExactly("moccasin-ferret-15599b3");
|
|
73
|
+
expect(actual).to.be.false;
|
|
74
|
+
}
|
|
34
75
|
}
|
|
35
76
|
module.exports = new ParseWorkspaceIdTest()
|
|
@@ -1,24 +1,55 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c) 2020
|
|
2
|
+
* Copyright (c) 2020 Gitpod GmbH. All rights reserved.
|
|
3
3
|
* Licensed under the GNU Affero General Public License (AGPL).
|
|
4
4
|
* See License-AGPL.txt in the project root for license information.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
const REGEX_WORKSPACE_ID = /[0-9a-z]{2,16}-[0-9a-z]{2,16}-[0-9a-z]{8}/;
|
|
8
|
+
const REGEX_WORKSPACE_ID_EXACT = new RegExp(`^${REGEX_WORKSPACE_ID.source}$`);
|
|
9
|
+
// We need to parse the workspace id precisely here to get the case '<some-str>-<port>-<wsid>.ws.' right
|
|
10
|
+
const REGEX_WORKSPACE_ID_FROM_HOSTNAME = new RegExp(`(${REGEX_WORKSPACE_ID.source})\.ws`);
|
|
11
|
+
|
|
12
|
+
const REGEX_WORKSPACE_ID_LEGACY = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/;
|
|
13
|
+
const REGEX_WORKSPACE_ID_LEGACY_EXACT = new RegExp(`^${REGEX_WORKSPACE_ID_LEGACY.source}$`);
|
|
14
|
+
const REGEX_WORKSPACE_ID_LEGACY_FROM_HOSTNAME = new RegExp(`(${REGEX_WORKSPACE_ID_LEGACY.source})\.ws`);
|
|
7
15
|
|
|
8
16
|
/**
|
|
9
17
|
* Hostname may be of the form:
|
|
10
|
-
* -
|
|
11
|
-
* - 1234-
|
|
12
|
-
* - webview-1234-
|
|
18
|
+
* - moccasin-ferret-155799b3.ws-eu01.gitpod.io
|
|
19
|
+
* - 1234-moccasin-ferret-155799b3.ws-eu01.gitpod.io
|
|
20
|
+
* - webview-1234-moccasin-ferret-155799b3.ws-eu01.gitpod.io (or any other string replacing webview)
|
|
13
21
|
* @param hostname The hostname the request is headed to
|
|
14
22
|
*/
|
|
15
23
|
export const parseWorkspaceIdFromHostname = function(hostname: string) {
|
|
16
|
-
|
|
17
|
-
const wsIdExpression = /([a-z][0-9a-z]+\-([0-9a-z]+\-){3}[0-9a-z]+)\.ws/g;
|
|
18
|
-
const match = wsIdExpression.exec(hostname);
|
|
24
|
+
const match = REGEX_WORKSPACE_ID_FROM_HOSTNAME.exec(hostname);
|
|
19
25
|
if (match && match.length >= 2) {
|
|
20
26
|
return match[1];
|
|
21
27
|
} else {
|
|
28
|
+
const legacyMatch = REGEX_WORKSPACE_ID_LEGACY_FROM_HOSTNAME.exec(hostname);
|
|
29
|
+
if (legacyMatch && legacyMatch.length >= 2) {
|
|
30
|
+
return legacyMatch[1];
|
|
31
|
+
}
|
|
22
32
|
return undefined;
|
|
23
33
|
}
|
|
24
|
-
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/** Equalls UUIDv4 (and REGEX_WORKSPACE_ID_LEGACY!) */
|
|
37
|
+
const REGEX_INSTANCE_ID = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/;
|
|
38
|
+
const REGEX_INSTANCE_ID_EXACT = new RegExp(`^${REGEX_INSTANCE_ID.source}$`);
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param maybeId
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
export const matchesInstanceIdOrLegacyWorkspaceIdExactly = function(maybeId: string): boolean {
|
|
45
|
+
return REGEX_INSTANCE_ID_EXACT.test(maybeId)
|
|
46
|
+
|| REGEX_WORKSPACE_ID_LEGACY_EXACT.test(maybeId);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @param maybeWorkspaceId
|
|
51
|
+
* @returns
|
|
52
|
+
*/
|
|
53
|
+
export const matchesNewWorkspaceIdExactly = function(maybeWorkspaceId: string): boolean {
|
|
54
|
+
return REGEX_WORKSPACE_ID_EXACT.test(maybeWorkspaceId);
|
|
55
|
+
};
|
package/src/util/queue.spec.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c) 2020
|
|
2
|
+
* Copyright (c) 2020 Gitpod GmbH. All rights reserved.
|
|
3
3
|
* Licensed under the GNU Affero General Public License (AGPL).
|
|
4
4
|
* See License-AGPL.txt in the project root for license information.
|
|
5
5
|
*/
|
|
@@ -32,7 +32,7 @@ const expect = chai.expect
|
|
|
32
32
|
return new Promise((resolve) => {
|
|
33
33
|
setTimeout(() => {
|
|
34
34
|
this.seq.push(seqNr);
|
|
35
|
-
resolve();
|
|
35
|
+
resolve(undefined);
|
|
36
36
|
}, sleep);
|
|
37
37
|
});
|
|
38
38
|
else
|
package/src/util/queue.ts
CHANGED
package/src/util/repeater.ts
CHANGED
package/src/util/safe-promise.ts
CHANGED
package/src/util/semaphore.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c) 2020
|
|
2
|
+
* Copyright (c) 2020 Gitpod GmbH. All rights reserved.
|
|
3
3
|
* Licensed under the GNU Affero General Public License (AGPL).
|
|
4
4
|
* See License-AGPL.txt in the project root for license information.
|
|
5
5
|
*/
|
|
@@ -9,7 +9,7 @@ export class Semaphore {
|
|
|
9
9
|
protected queue: (() => void)[] = [];
|
|
10
10
|
protected used: number;
|
|
11
11
|
|
|
12
|
-
constructor(protected readonly capacity: number) {
|
|
12
|
+
constructor(protected readonly capacity: number) {
|
|
13
13
|
if(capacity < 1) {
|
|
14
14
|
throw new Error("Capacity cannot be less than 1");
|
|
15
15
|
}
|
|
@@ -17,7 +17,7 @@ export class Semaphore {
|
|
|
17
17
|
|
|
18
18
|
public release() {
|
|
19
19
|
if(this.used == 0) return;
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
const queued = this.queue.shift();
|
|
22
22
|
if (queued) {
|
|
23
23
|
queued();
|
package/src/util/skip-if.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c) 2020
|
|
2
|
+
* Copyright (c) 2020 Gitpod GmbH. All rights reserved.
|
|
3
3
|
* Licensed under the GNU Affero General Public License (AGPL).
|
|
4
4
|
* See License-AGPL.txt in the project root for license information.
|
|
5
5
|
*/
|
|
@@ -27,7 +27,7 @@ export function skipIf(doSkip: (suite: TestSuiteContext) => boolean): MochaTypeS
|
|
|
27
27
|
}
|
|
28
28
|
})
|
|
29
29
|
};
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
// Mark as "trait": mimics the behavior of https://github.com/testdeck/testdeck/blob/9d2dd6a458c2c86c945f6f2999b8278b7528a7a7/index.ts#L433
|
|
32
32
|
(trait as any)["__mts_isTrait"] = true;
|
|
33
33
|
return trait;
|
package/src/util/timeutil.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c) 2020
|
|
2
|
+
* Copyright (c) 2020 Gitpod GmbH. All rights reserved.
|
|
3
3
|
* Licensed under the GNU Affero General Public License (AGPL).
|
|
4
4
|
* See License-AGPL.txt in the project root for license information.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Returns the <code>day</code>th of the next month from <code>formDate</code>.
|
|
9
|
-
* If the next month does not have a <code>day</code>th, the last day of that
|
|
9
|
+
* If the next month does not have a <code>day</code>th, the last day of that
|
|
10
10
|
* month is taken.
|
|
11
11
|
* The time is copied from <code>fromDate</code>.
|
|
12
|
-
*
|
|
13
|
-
* @param fromDate
|
|
14
|
-
* @param day
|
|
12
|
+
*
|
|
13
|
+
* @param fromDate
|
|
14
|
+
* @param day
|
|
15
15
|
*/
|
|
16
16
|
export function oneMonthLater(fromDate: string, day?: number): string {
|
|
17
17
|
const later = new Date(fromDate);
|
package/src/util/tracing.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c) 2020
|
|
2
|
+
* Copyright (c) 2020 Gitpod GmbH. All rights reserved.
|
|
3
3
|
* Licensed under the GNU Affero General Public License (AGPL).
|
|
4
4
|
* See License-AGPL.txt in the project root for license information.
|
|
5
5
|
*/
|
|
@@ -9,19 +9,29 @@ import * as opentracing from 'opentracing';
|
|
|
9
9
|
import { TracingConfig, initTracerFromEnv, Sampler, SamplingDecision } from 'jaeger-client';
|
|
10
10
|
import { initGlobalTracer } from 'opentracing';
|
|
11
11
|
import { injectable } from 'inversify';
|
|
12
|
+
import { ResponseError } from 'vscode-jsonrpc';
|
|
12
13
|
|
|
13
14
|
export interface TraceContext {
|
|
14
15
|
span?: opentracing.Span
|
|
15
16
|
}
|
|
17
|
+
export type TraceContextWithSpan = TraceContext & {
|
|
18
|
+
span: opentracing.Span
|
|
19
|
+
}
|
|
20
|
+
|
|
16
21
|
|
|
17
22
|
export namespace TraceContext {
|
|
18
|
-
export function startSpan(operation: string,
|
|
23
|
+
export function startSpan(operation: string, parentCtx: TraceContext): opentracing.Span {
|
|
19
24
|
const options: opentracing.SpanOptions = {
|
|
20
|
-
childOf:
|
|
25
|
+
childOf: parentCtx.span
|
|
21
26
|
}
|
|
22
27
|
return opentracing.globalTracer().startSpan(operation, options);
|
|
23
28
|
}
|
|
24
29
|
|
|
30
|
+
export function childContextWithSpan(operation: string, parentCtx: TraceContext): TraceContextWithSpan {
|
|
31
|
+
const span = startSpan(operation, parentCtx);
|
|
32
|
+
return { span };
|
|
33
|
+
}
|
|
34
|
+
|
|
25
35
|
export function startAsyncSpan(operation: string, ctx: TraceContext): opentracing.Span {
|
|
26
36
|
const options: opentracing.SpanOptions = {};
|
|
27
37
|
if (!!ctx.span) {
|
|
@@ -39,7 +49,42 @@ export namespace TraceContext {
|
|
|
39
49
|
"error": err.message,
|
|
40
50
|
"stacktrace": err.stack
|
|
41
51
|
})
|
|
42
|
-
ctx.span.setTag("error", true)
|
|
52
|
+
ctx.span.setTag("error", true);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function logJsonRPCError(ctx: TraceContext, method: string, err: ResponseError<any>) {
|
|
56
|
+
if (!ctx.span) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
logError(ctx, err);
|
|
60
|
+
|
|
61
|
+
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/rpc.md#json-rpc
|
|
62
|
+
ctx.span.addTags({
|
|
63
|
+
rpc: {
|
|
64
|
+
system: "jsonrpc",
|
|
65
|
+
method,
|
|
66
|
+
jsonrpc: {
|
|
67
|
+
error_code: err.code,
|
|
68
|
+
error_message: err.message,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function addJsonRPCParameters(ctx: TraceContext, method: string, args: any[]) {
|
|
75
|
+
if (!ctx.span) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
ctx.span.addTags({
|
|
80
|
+
rpc: {
|
|
81
|
+
system: "jsonrpc",
|
|
82
|
+
method,
|
|
83
|
+
jsonrpc: {
|
|
84
|
+
parameters: args.slice(),
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
});
|
|
43
88
|
}
|
|
44
89
|
}
|
|
45
90
|
|
|
@@ -132,3 +177,20 @@ export class PerOperationSampler implements Sampler {
|
|
|
132
177
|
}
|
|
133
178
|
}
|
|
134
179
|
}
|
|
180
|
+
|
|
181
|
+
// Augment interfaces with an leading parameter "TraceContext" on every method
|
|
182
|
+
type IsValidArg<T> = T extends object ? keyof T extends never ? false : true : true;
|
|
183
|
+
type AddTraceContext<T> =
|
|
184
|
+
T extends (a: infer A, b: infer B, c: infer C, d: infer D, e: infer E, f: infer F) => infer R ? (
|
|
185
|
+
IsValidArg<F> extends true ? (ctx: TraceContextWithSpan, a: A, b: B, c: C, d: D, e: E, f: F) => R :
|
|
186
|
+
IsValidArg<E> extends true ? (ctx: TraceContextWithSpan, a: A, b: B, c: C, d: D, e: E) => R :
|
|
187
|
+
IsValidArg<D> extends true ? (ctx: TraceContextWithSpan, a: A, b: B, c: C, d: D) => R :
|
|
188
|
+
IsValidArg<C> extends true ? (ctx: TraceContextWithSpan, a: A, b: B, c: C) => R :
|
|
189
|
+
IsValidArg<B> extends true ? (ctx: TraceContextWithSpan, a: A, b: B) => R :
|
|
190
|
+
IsValidArg<A> extends true ? (ctx: TraceContextWithSpan, a: A) => R :
|
|
191
|
+
(ctx: TraceContextWithSpan) => Promise<R>
|
|
192
|
+
) : never;
|
|
193
|
+
|
|
194
|
+
export type InterfaceWithTraceContext<T> = {
|
|
195
|
+
[P in keyof T]: AddTraceContext<T[P]>
|
|
196
|
+
};
|