@hatchet-dev/typescript-sdk 1.19.0 → 1.19.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/clients/event/event-client.js +15 -12
- package/opentelemetry/hatchet-exporter.js +16 -2
- package/opentelemetry/instrumentor.js +13 -0
- package/package.json +2 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -14,6 +14,7 @@ const events_1 = require("../../protoc/events/events");
|
|
|
14
14
|
const hatchet_error_1 = require("../../util/errors/hatchet-error");
|
|
15
15
|
const retrier_1 = require("../../util/retrier");
|
|
16
16
|
const apply_namespace_1 = require("../../util/apply-namespace");
|
|
17
|
+
const parent_run_context_vars_1 = require("../../v1/parent-run-context-vars");
|
|
17
18
|
var LogLevel;
|
|
18
19
|
(function (LogLevel) {
|
|
19
20
|
LogLevel["INFO"] = "INFO";
|
|
@@ -21,6 +22,13 @@ var LogLevel;
|
|
|
21
22
|
LogLevel["ERROR"] = "ERROR";
|
|
22
23
|
LogLevel["DEBUG"] = "DEBUG";
|
|
23
24
|
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
|
25
|
+
function injectSourceInfo(metadata) {
|
|
26
|
+
const ctx = parent_run_context_vars_1.parentRunContextManager.getContext();
|
|
27
|
+
if (!(ctx === null || ctx === void 0 ? void 0 : ctx.parentId) || !(ctx === null || ctx === void 0 ? void 0 : ctx.parentTaskRunExternalId)) {
|
|
28
|
+
return metadata;
|
|
29
|
+
}
|
|
30
|
+
return Object.assign(Object.assign({}, metadata), { hatchet__source_workflow_run_id: ctx.parentId, hatchet__source_step_run_id: ctx.parentTaskRunExternalId });
|
|
31
|
+
}
|
|
24
32
|
class EventClient {
|
|
25
33
|
constructor(config, channel, factory, api) {
|
|
26
34
|
this.config = config;
|
|
@@ -35,14 +43,14 @@ class EventClient {
|
|
|
35
43
|
* Keep the signature in sync with the instrumentor wrapper.
|
|
36
44
|
*/
|
|
37
45
|
push(type, input, options = {}) {
|
|
46
|
+
var _a;
|
|
38
47
|
const namespacedType = (0, apply_namespace_1.applyNamespace)(type, this.config.namespace);
|
|
48
|
+
const enhancedMetadata = injectSourceInfo((_a = options.additionalMetadata) !== null && _a !== void 0 ? _a : {});
|
|
39
49
|
const req = {
|
|
40
50
|
key: namespacedType,
|
|
41
51
|
payload: JSON.stringify(input),
|
|
42
52
|
eventTimestamp: new Date(),
|
|
43
|
-
additionalMetadata:
|
|
44
|
-
? JSON.stringify(options.additionalMetadata)
|
|
45
|
-
: undefined,
|
|
53
|
+
additionalMetadata: Object.keys(enhancedMetadata).length > 0 ? JSON.stringify(enhancedMetadata) : undefined,
|
|
46
54
|
priority: options.priority,
|
|
47
55
|
scope: options.scope,
|
|
48
56
|
};
|
|
@@ -62,19 +70,14 @@ class EventClient {
|
|
|
62
70
|
bulkPush(type, inputs, options = {}) {
|
|
63
71
|
const namespacedType = (0, apply_namespace_1.applyNamespace)(type, this.config.namespace);
|
|
64
72
|
const events = inputs.map((input) => {
|
|
73
|
+
var _a, _b;
|
|
74
|
+
const baseMeta = (_b = (_a = input.additionalMetadata) !== null && _a !== void 0 ? _a : options.additionalMetadata) !== null && _b !== void 0 ? _b : {};
|
|
75
|
+
const enhanced = injectSourceInfo(baseMeta);
|
|
65
76
|
return {
|
|
66
77
|
key: namespacedType,
|
|
67
78
|
payload: JSON.stringify(input.payload),
|
|
68
79
|
eventTimestamp: new Date(),
|
|
69
|
-
additionalMetadata: (()
|
|
70
|
-
if (input.additionalMetadata) {
|
|
71
|
-
return JSON.stringify(input.additionalMetadata);
|
|
72
|
-
}
|
|
73
|
-
if (options.additionalMetadata) {
|
|
74
|
-
return JSON.stringify(options.additionalMetadata);
|
|
75
|
-
}
|
|
76
|
-
return undefined;
|
|
77
|
-
})(),
|
|
80
|
+
additionalMetadata: Object.keys(enhanced).length > 0 ? JSON.stringify(enhanced) : undefined,
|
|
78
81
|
priority: input.priority,
|
|
79
82
|
scope: input.scope,
|
|
80
83
|
};
|
|
@@ -96,9 +96,19 @@ class HatchetExporterWrapper {
|
|
|
96
96
|
*/
|
|
97
97
|
class HatchetAttributeSpanProcessor extends BatchSpanProcessor {
|
|
98
98
|
onStart(span) {
|
|
99
|
+
var _a;
|
|
99
100
|
const attrs = hatchet_span_context_1.hatchetSpanAttributes.getStore();
|
|
100
101
|
if (attrs) {
|
|
101
|
-
span.
|
|
102
|
+
const existing = (_a = span.attributes) !== null && _a !== void 0 ? _a : {};
|
|
103
|
+
const filtered = {};
|
|
104
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
105
|
+
if (!(key in existing)) {
|
|
106
|
+
filtered[key] = value;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (Object.keys(filtered).length > 0) {
|
|
110
|
+
span.setAttributes(filtered);
|
|
111
|
+
}
|
|
102
112
|
}
|
|
103
113
|
super.onStart(span, undefined);
|
|
104
114
|
}
|
|
@@ -108,10 +118,14 @@ class HatchetAttributeSpanProcessor extends BatchSpanProcessor {
|
|
|
108
118
|
}
|
|
109
119
|
function createHatchetExporter(config) {
|
|
110
120
|
const insecure = config.tls_config.tls_strategy === 'none';
|
|
121
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
122
|
+
const grpc = require('@grpc/grpc-js');
|
|
123
|
+
const metadata = new grpc.Metadata();
|
|
124
|
+
metadata.set('authorization', `Bearer ${config.token}`);
|
|
111
125
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
112
126
|
const opts = {
|
|
113
127
|
url: `${insecure ? 'http' : 'https'}://${config.host_port}`,
|
|
114
|
-
metadata
|
|
128
|
+
metadata,
|
|
115
129
|
};
|
|
116
130
|
if (!insecure && config.tls_config.ca_file) {
|
|
117
131
|
try {
|
|
@@ -46,6 +46,17 @@ function extractContext(carrier) {
|
|
|
46
46
|
function injectContext(carrier) {
|
|
47
47
|
propagation.inject(context.active(), carrier);
|
|
48
48
|
}
|
|
49
|
+
function injectSourceInfo(carrier) {
|
|
50
|
+
const store = hatchet_span_context_1.hatchetSpanAttributes.getStore();
|
|
51
|
+
if (!store)
|
|
52
|
+
return;
|
|
53
|
+
const wfRunId = store['hatchet.workflow_run_id'];
|
|
54
|
+
const stepRunId = store['hatchet.step_run_id'];
|
|
55
|
+
if (typeof wfRunId === 'string' && typeof stepRunId === 'string') {
|
|
56
|
+
carrier['hatchet__source_workflow_run_id'] = wfRunId;
|
|
57
|
+
carrier['hatchet__source_step_run_id'] = stepRunId;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
49
60
|
function getActionOtelAttributes(action, excludedAttributes = [], workerId) {
|
|
50
61
|
const attributes = {
|
|
51
62
|
[opentelemetry_1.OTelAttribute.TENANT_ID]: action.tenantId,
|
|
@@ -215,6 +226,7 @@ class HatchetInstrumentor extends InstrumentationBase {
|
|
|
215
226
|
var _a;
|
|
216
227
|
const enhancedMetadata = Object.assign({}, ((_a = options.additionalMetadata) !== null && _a !== void 0 ? _a : {}));
|
|
217
228
|
injectContext(enhancedMetadata);
|
|
229
|
+
injectSourceInfo(enhancedMetadata);
|
|
218
230
|
const enhancedOptions = Object.assign(Object.assign({}, options), { additionalMetadata: enhancedMetadata });
|
|
219
231
|
const result = original.call(this, type, input, enhancedOptions);
|
|
220
232
|
return result.finally(() => {
|
|
@@ -247,6 +259,7 @@ class HatchetInstrumentor extends InstrumentationBase {
|
|
|
247
259
|
var _a;
|
|
248
260
|
const enhancedMetadata = Object.assign({}, ((_a = input.additionalMetadata) !== null && _a !== void 0 ? _a : {}));
|
|
249
261
|
injectContext(enhancedMetadata);
|
|
262
|
+
injectSourceInfo(enhancedMetadata);
|
|
250
263
|
return Object.assign(Object.assign({}, input), { additionalMetadata: enhancedMetadata });
|
|
251
264
|
});
|
|
252
265
|
const result = original.call(this, type, enhancedInputs, options);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hatchet-dev/typescript-sdk",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.1",
|
|
4
4
|
"description": "Background task orchestration & visibility for developers",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
"zod-to-json-schema": "^3.24.1"
|
|
62
62
|
},
|
|
63
63
|
"optionalDependencies": {
|
|
64
|
+
"@grpc/grpc-js": "^1.14.3",
|
|
64
65
|
"@opentelemetry/api": "^1.9.0",
|
|
65
66
|
"@opentelemetry/core": "^2.0.0",
|
|
66
67
|
"@opentelemetry/exporter-trace-otlp-grpc": "^0.208.0",
|
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const HATCHET_VERSION = "1.19.
|
|
1
|
+
export declare const HATCHET_VERSION = "1.19.1";
|
package/version.js
CHANGED