@reactionary/provider-commercetools 0.0.29 → 0.0.30
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/index.js +15 -173
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -152,181 +152,38 @@ var RedisCache = class {
|
|
|
152
152
|
}
|
|
153
153
|
};
|
|
154
154
|
|
|
155
|
-
// otel/src/
|
|
156
|
-
import {
|
|
157
|
-
import { resourceFromAttributes, defaultResource } from "@opentelemetry/resources";
|
|
158
|
-
import { SEMRESATTRS_SERVICE_NAME, SEMRESATTRS_SERVICE_VERSION, SEMRESATTRS_DEPLOYMENT_ENVIRONMENT } from "@opentelemetry/semantic-conventions";
|
|
155
|
+
// otel/src/trpc-middleware.ts
|
|
156
|
+
import { TRPCError } from "@trpc/server";
|
|
159
157
|
import {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
import { ExpressInstrumentation } from "@opentelemetry/instrumentation-express";
|
|
158
|
+
SpanKind as SpanKind2,
|
|
159
|
+
SpanStatusCode as SpanStatusCode3
|
|
160
|
+
} from "@opentelemetry/api";
|
|
164
161
|
|
|
165
|
-
// otel/src/
|
|
166
|
-
import {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
return typeof window !== "undefined" && typeof process === "undefined";
|
|
172
|
-
}
|
|
173
|
-
function getConfigFromEnv() {
|
|
174
|
-
if (isBrowser()) {
|
|
175
|
-
return {
|
|
176
|
-
serviceName: "browser-service",
|
|
177
|
-
serviceVersion: void 0,
|
|
178
|
-
environment: "browser",
|
|
179
|
-
otlpEndpoint: void 0,
|
|
180
|
-
otlpHeaders: void 0,
|
|
181
|
-
traceEnabled: false,
|
|
182
|
-
metricsEnabled: false,
|
|
183
|
-
metricExportIntervalMillis: 6e4
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
const tracesExporter = process.env["OTEL_TRACES_EXPORTER"] || "console";
|
|
187
|
-
const metricsExporter = process.env["OTEL_METRICS_EXPORTER"] || "console";
|
|
188
|
-
return {
|
|
189
|
-
serviceName: process.env["OTEL_SERVICE_NAME"] || "unknown_service",
|
|
190
|
-
serviceVersion: process.env["OTEL_SERVICE_VERSION"],
|
|
191
|
-
environment: process.env["DEPLOYMENT_ENVIRONMENT"] || process.env["NODE_ENV"] || "development",
|
|
192
|
-
otlpEndpoint: process.env["OTEL_EXPORTER_OTLP_ENDPOINT"],
|
|
193
|
-
otlpHeaders: process.env["OTEL_EXPORTER_OTLP_HEADERS"] ? parseHeaders(process.env["OTEL_EXPORTER_OTLP_HEADERS"]) : void 0,
|
|
194
|
-
traceEnabled: tracesExporter !== "none",
|
|
195
|
-
metricsEnabled: metricsExporter !== "none",
|
|
196
|
-
metricExportIntervalMillis: process.env["OTEL_METRIC_EXPORT_INTERVAL"] ? parseInt(process.env["OTEL_METRIC_EXPORT_INTERVAL"], 10) : 6e4
|
|
197
|
-
// Default 60 seconds per OTEL spec
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
function parseHeaders(headerString) {
|
|
201
|
-
const headers = {};
|
|
202
|
-
headerString.split(",").forEach((header) => {
|
|
203
|
-
const [key, value] = header.split("=");
|
|
204
|
-
if (key && value) {
|
|
205
|
-
headers[key.trim()] = value.trim();
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
return headers;
|
|
209
|
-
}
|
|
210
|
-
function createTraceExporter(config) {
|
|
211
|
-
if (!config.traceEnabled) {
|
|
212
|
-
return void 0;
|
|
213
|
-
}
|
|
214
|
-
const tracesExporter = process.env["OTEL_TRACES_EXPORTER"] || "console";
|
|
215
|
-
switch (tracesExporter) {
|
|
216
|
-
case "otlp":
|
|
217
|
-
case "otlp/http": {
|
|
218
|
-
if (!config.otlpEndpoint) {
|
|
219
|
-
console.warn("OTEL_EXPORTER_OTLP_ENDPOINT not set, falling back to console");
|
|
220
|
-
return new ConsoleSpanExporter();
|
|
221
|
-
}
|
|
222
|
-
const tracesEndpoint = process.env["OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"] || `${config.otlpEndpoint}/v1/traces`;
|
|
223
|
-
return new OTLPTraceExporter({
|
|
224
|
-
url: tracesEndpoint,
|
|
225
|
-
headers: config.otlpHeaders
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
case "console":
|
|
229
|
-
return new ConsoleSpanExporter();
|
|
230
|
-
case "none":
|
|
231
|
-
default:
|
|
232
|
-
return void 0;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
function createMetricReader(config) {
|
|
236
|
-
if (!config.metricsEnabled) {
|
|
237
|
-
return void 0;
|
|
238
|
-
}
|
|
239
|
-
const metricsExporter = process.env["OTEL_METRICS_EXPORTER"] || "console";
|
|
240
|
-
let exporter;
|
|
241
|
-
switch (metricsExporter) {
|
|
242
|
-
case "otlp":
|
|
243
|
-
case "otlp/http": {
|
|
244
|
-
if (!config.otlpEndpoint) {
|
|
245
|
-
console.warn("OTEL_EXPORTER_OTLP_ENDPOINT not set, falling back to console");
|
|
246
|
-
exporter = new ConsoleMetricExporter();
|
|
247
|
-
} else {
|
|
248
|
-
const metricsEndpoint = process.env["OTEL_EXPORTER_OTLP_METRICS_ENDPOINT"] || `${config.otlpEndpoint}/v1/metrics`;
|
|
249
|
-
exporter = new OTLPMetricExporter({
|
|
250
|
-
url: metricsEndpoint,
|
|
251
|
-
headers: config.otlpHeaders
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
break;
|
|
255
|
-
}
|
|
256
|
-
case "console":
|
|
257
|
-
exporter = new ConsoleMetricExporter();
|
|
258
|
-
break;
|
|
259
|
-
case "none":
|
|
260
|
-
default:
|
|
261
|
-
return void 0;
|
|
262
|
-
}
|
|
263
|
-
return new PeriodicExportingMetricReader({
|
|
264
|
-
exporter,
|
|
265
|
-
exportIntervalMillis: config.metricExportIntervalMillis
|
|
266
|
-
});
|
|
267
|
-
}
|
|
162
|
+
// otel/src/tracer.ts
|
|
163
|
+
import {
|
|
164
|
+
trace,
|
|
165
|
+
SpanStatusCode,
|
|
166
|
+
context as otelContext
|
|
167
|
+
} from "@opentelemetry/api";
|
|
268
168
|
|
|
269
169
|
// otel/src/sdk.ts
|
|
170
|
+
import { NodeSDK } from "@opentelemetry/sdk-node";
|
|
270
171
|
var sdk = null;
|
|
271
172
|
var isInitialized = false;
|
|
272
173
|
var initializationPromise = null;
|
|
273
|
-
function
|
|
174
|
+
function isBrowser() {
|
|
274
175
|
return typeof window !== "undefined" && typeof process === "undefined";
|
|
275
176
|
}
|
|
276
177
|
function ensureInitialized() {
|
|
277
178
|
if (isInitialized || initializationPromise) {
|
|
278
179
|
return;
|
|
279
180
|
}
|
|
280
|
-
if (
|
|
181
|
+
if (isBrowser()) {
|
|
281
182
|
isInitialized = true;
|
|
282
183
|
return;
|
|
283
184
|
}
|
|
284
185
|
initializationPromise = Promise.resolve().then(() => {
|
|
285
|
-
|
|
286
|
-
if (process.env["OTEL_LOG_LEVEL"] === "debug") {
|
|
287
|
-
console.log("OpenTelemetry auto-initializing with config:", {
|
|
288
|
-
serviceName: config.serviceName,
|
|
289
|
-
environment: config.environment,
|
|
290
|
-
tracesExporter: process.env["OTEL_TRACES_EXPORTER"] || "console",
|
|
291
|
-
metricsExporter: process.env["OTEL_METRICS_EXPORTER"] || "console"
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
const attributes = {
|
|
295
|
-
[SEMRESATTRS_SERVICE_NAME]: config.serviceName
|
|
296
|
-
};
|
|
297
|
-
if (config.serviceVersion) {
|
|
298
|
-
attributes[SEMRESATTRS_SERVICE_VERSION] = config.serviceVersion;
|
|
299
|
-
}
|
|
300
|
-
if (config.environment) {
|
|
301
|
-
attributes[SEMRESATTRS_DEPLOYMENT_ENVIRONMENT] = config.environment;
|
|
302
|
-
}
|
|
303
|
-
const customResource = resourceFromAttributes(attributes);
|
|
304
|
-
const resource = defaultResource().merge(customResource);
|
|
305
|
-
const traceExporter = createTraceExporter(config);
|
|
306
|
-
const metricReader = createMetricReader(config);
|
|
307
|
-
const instrumentations = [
|
|
308
|
-
new HttpInstrumentation({
|
|
309
|
-
requestHook: (span, request) => {
|
|
310
|
-
const req = request;
|
|
311
|
-
if (req.headers) {
|
|
312
|
-
span.setAttribute("http.request.body.size", req.headers["content-length"] || 0);
|
|
313
|
-
}
|
|
314
|
-
},
|
|
315
|
-
responseHook: (span, response) => {
|
|
316
|
-
const res = response;
|
|
317
|
-
if (res.headers) {
|
|
318
|
-
span.setAttribute("http.response.body.size", res.headers["content-length"] || 0);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}),
|
|
322
|
-
new ExpressInstrumentation()
|
|
323
|
-
];
|
|
324
|
-
sdk = new NodeSDK({
|
|
325
|
-
resource,
|
|
326
|
-
spanProcessors: traceExporter ? [new BatchSpanProcessor(traceExporter)] : [],
|
|
327
|
-
metricReader,
|
|
328
|
-
instrumentations
|
|
329
|
-
});
|
|
186
|
+
sdk = new NodeSDK();
|
|
330
187
|
sdk.start();
|
|
331
188
|
isInitialized = true;
|
|
332
189
|
process.on("SIGTERM", async () => {
|
|
@@ -354,11 +211,6 @@ function isOtelInitialized() {
|
|
|
354
211
|
}
|
|
355
212
|
|
|
356
213
|
// otel/src/tracer.ts
|
|
357
|
-
import {
|
|
358
|
-
trace,
|
|
359
|
-
SpanStatusCode,
|
|
360
|
-
context as otelContext
|
|
361
|
-
} from "@opentelemetry/api";
|
|
362
214
|
import { SpanKind, SpanStatusCode as SpanStatusCode2 } from "@opentelemetry/api";
|
|
363
215
|
var TRACER_NAME = "@reactionary/otel";
|
|
364
216
|
var TRACER_VERSION = "0.0.1";
|
|
@@ -454,13 +306,6 @@ function getMetrics() {
|
|
|
454
306
|
return metricsInstance;
|
|
455
307
|
}
|
|
456
308
|
|
|
457
|
-
// otel/src/trpc-middleware.ts
|
|
458
|
-
import { TRPCError } from "@trpc/server";
|
|
459
|
-
import {
|
|
460
|
-
SpanKind as SpanKind2,
|
|
461
|
-
SpanStatusCode as SpanStatusCode3
|
|
462
|
-
} from "@opentelemetry/api";
|
|
463
|
-
|
|
464
309
|
// otel/src/provider-instrumentation.ts
|
|
465
310
|
import { SpanKind as SpanKind3 } from "@opentelemetry/api";
|
|
466
311
|
async function withProviderSpan(options, fn) {
|
|
@@ -538,9 +383,6 @@ function createProviderInstrumentation(providerName) {
|
|
|
538
383
|
};
|
|
539
384
|
}
|
|
540
385
|
|
|
541
|
-
// otel/src/index.ts
|
|
542
|
-
import { trace as trace2, context, SpanKind as SpanKind4, SpanStatusCode as SpanStatusCode4 } from "@opentelemetry/api";
|
|
543
|
-
|
|
544
386
|
// core/src/providers/base.provider.ts
|
|
545
387
|
var BaseProvider = class {
|
|
546
388
|
constructor(schema, querySchema, mutationSchema) {
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/provider-commercetools",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.30",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@reactionary/core": "0.0.
|
|
5
|
+
"@reactionary/core": "0.0.30",
|
|
6
6
|
"zod": "4.0.0-beta.20250430T185432",
|
|
7
7
|
"@commercetools/ts-client": "^3.2.2",
|
|
8
8
|
"@commercetools/platform-sdk": "^8.8.0"
|