@reactionary/core 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
|
@@ -54,181 +54,38 @@ function buildClient(providers) {
|
|
|
54
54
|
return client;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
// otel/src/
|
|
58
|
-
import {
|
|
59
|
-
import { resourceFromAttributes, defaultResource } from "@opentelemetry/resources";
|
|
60
|
-
import { SEMRESATTRS_SERVICE_NAME, SEMRESATTRS_SERVICE_VERSION, SEMRESATTRS_DEPLOYMENT_ENVIRONMENT } from "@opentelemetry/semantic-conventions";
|
|
57
|
+
// otel/src/trpc-middleware.ts
|
|
58
|
+
import { TRPCError } from "@trpc/server";
|
|
61
59
|
import {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
import { ExpressInstrumentation } from "@opentelemetry/instrumentation-express";
|
|
60
|
+
SpanKind as SpanKind2,
|
|
61
|
+
SpanStatusCode as SpanStatusCode3
|
|
62
|
+
} from "@opentelemetry/api";
|
|
66
63
|
|
|
67
|
-
// otel/src/
|
|
68
|
-
import {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return typeof window !== "undefined" && typeof process === "undefined";
|
|
74
|
-
}
|
|
75
|
-
function getConfigFromEnv() {
|
|
76
|
-
if (isBrowser()) {
|
|
77
|
-
return {
|
|
78
|
-
serviceName: "browser-service",
|
|
79
|
-
serviceVersion: void 0,
|
|
80
|
-
environment: "browser",
|
|
81
|
-
otlpEndpoint: void 0,
|
|
82
|
-
otlpHeaders: void 0,
|
|
83
|
-
traceEnabled: false,
|
|
84
|
-
metricsEnabled: false,
|
|
85
|
-
metricExportIntervalMillis: 6e4
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
const tracesExporter = process.env["OTEL_TRACES_EXPORTER"] || "console";
|
|
89
|
-
const metricsExporter = process.env["OTEL_METRICS_EXPORTER"] || "console";
|
|
90
|
-
return {
|
|
91
|
-
serviceName: process.env["OTEL_SERVICE_NAME"] || "unknown_service",
|
|
92
|
-
serviceVersion: process.env["OTEL_SERVICE_VERSION"],
|
|
93
|
-
environment: process.env["DEPLOYMENT_ENVIRONMENT"] || process.env["NODE_ENV"] || "development",
|
|
94
|
-
otlpEndpoint: process.env["OTEL_EXPORTER_OTLP_ENDPOINT"],
|
|
95
|
-
otlpHeaders: process.env["OTEL_EXPORTER_OTLP_HEADERS"] ? parseHeaders(process.env["OTEL_EXPORTER_OTLP_HEADERS"]) : void 0,
|
|
96
|
-
traceEnabled: tracesExporter !== "none",
|
|
97
|
-
metricsEnabled: metricsExporter !== "none",
|
|
98
|
-
metricExportIntervalMillis: process.env["OTEL_METRIC_EXPORT_INTERVAL"] ? parseInt(process.env["OTEL_METRIC_EXPORT_INTERVAL"], 10) : 6e4
|
|
99
|
-
// Default 60 seconds per OTEL spec
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
function parseHeaders(headerString) {
|
|
103
|
-
const headers = {};
|
|
104
|
-
headerString.split(",").forEach((header) => {
|
|
105
|
-
const [key, value] = header.split("=");
|
|
106
|
-
if (key && value) {
|
|
107
|
-
headers[key.trim()] = value.trim();
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
return headers;
|
|
111
|
-
}
|
|
112
|
-
function createTraceExporter(config) {
|
|
113
|
-
if (!config.traceEnabled) {
|
|
114
|
-
return void 0;
|
|
115
|
-
}
|
|
116
|
-
const tracesExporter = process.env["OTEL_TRACES_EXPORTER"] || "console";
|
|
117
|
-
switch (tracesExporter) {
|
|
118
|
-
case "otlp":
|
|
119
|
-
case "otlp/http": {
|
|
120
|
-
if (!config.otlpEndpoint) {
|
|
121
|
-
console.warn("OTEL_EXPORTER_OTLP_ENDPOINT not set, falling back to console");
|
|
122
|
-
return new ConsoleSpanExporter();
|
|
123
|
-
}
|
|
124
|
-
const tracesEndpoint = process.env["OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"] || `${config.otlpEndpoint}/v1/traces`;
|
|
125
|
-
return new OTLPTraceExporter({
|
|
126
|
-
url: tracesEndpoint,
|
|
127
|
-
headers: config.otlpHeaders
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
case "console":
|
|
131
|
-
return new ConsoleSpanExporter();
|
|
132
|
-
case "none":
|
|
133
|
-
default:
|
|
134
|
-
return void 0;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
function createMetricReader(config) {
|
|
138
|
-
if (!config.metricsEnabled) {
|
|
139
|
-
return void 0;
|
|
140
|
-
}
|
|
141
|
-
const metricsExporter = process.env["OTEL_METRICS_EXPORTER"] || "console";
|
|
142
|
-
let exporter;
|
|
143
|
-
switch (metricsExporter) {
|
|
144
|
-
case "otlp":
|
|
145
|
-
case "otlp/http": {
|
|
146
|
-
if (!config.otlpEndpoint) {
|
|
147
|
-
console.warn("OTEL_EXPORTER_OTLP_ENDPOINT not set, falling back to console");
|
|
148
|
-
exporter = new ConsoleMetricExporter();
|
|
149
|
-
} else {
|
|
150
|
-
const metricsEndpoint = process.env["OTEL_EXPORTER_OTLP_METRICS_ENDPOINT"] || `${config.otlpEndpoint}/v1/metrics`;
|
|
151
|
-
exporter = new OTLPMetricExporter({
|
|
152
|
-
url: metricsEndpoint,
|
|
153
|
-
headers: config.otlpHeaders
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
158
|
-
case "console":
|
|
159
|
-
exporter = new ConsoleMetricExporter();
|
|
160
|
-
break;
|
|
161
|
-
case "none":
|
|
162
|
-
default:
|
|
163
|
-
return void 0;
|
|
164
|
-
}
|
|
165
|
-
return new PeriodicExportingMetricReader({
|
|
166
|
-
exporter,
|
|
167
|
-
exportIntervalMillis: config.metricExportIntervalMillis
|
|
168
|
-
});
|
|
169
|
-
}
|
|
64
|
+
// otel/src/tracer.ts
|
|
65
|
+
import {
|
|
66
|
+
trace,
|
|
67
|
+
SpanStatusCode,
|
|
68
|
+
context as otelContext
|
|
69
|
+
} from "@opentelemetry/api";
|
|
170
70
|
|
|
171
71
|
// otel/src/sdk.ts
|
|
72
|
+
import { NodeSDK } from "@opentelemetry/sdk-node";
|
|
172
73
|
var sdk = null;
|
|
173
74
|
var isInitialized = false;
|
|
174
75
|
var initializationPromise = null;
|
|
175
|
-
function
|
|
76
|
+
function isBrowser() {
|
|
176
77
|
return typeof window !== "undefined" && typeof process === "undefined";
|
|
177
78
|
}
|
|
178
79
|
function ensureInitialized() {
|
|
179
80
|
if (isInitialized || initializationPromise) {
|
|
180
81
|
return;
|
|
181
82
|
}
|
|
182
|
-
if (
|
|
83
|
+
if (isBrowser()) {
|
|
183
84
|
isInitialized = true;
|
|
184
85
|
return;
|
|
185
86
|
}
|
|
186
87
|
initializationPromise = Promise.resolve().then(() => {
|
|
187
|
-
|
|
188
|
-
if (process.env["OTEL_LOG_LEVEL"] === "debug") {
|
|
189
|
-
console.log("OpenTelemetry auto-initializing with config:", {
|
|
190
|
-
serviceName: config.serviceName,
|
|
191
|
-
environment: config.environment,
|
|
192
|
-
tracesExporter: process.env["OTEL_TRACES_EXPORTER"] || "console",
|
|
193
|
-
metricsExporter: process.env["OTEL_METRICS_EXPORTER"] || "console"
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
const attributes = {
|
|
197
|
-
[SEMRESATTRS_SERVICE_NAME]: config.serviceName
|
|
198
|
-
};
|
|
199
|
-
if (config.serviceVersion) {
|
|
200
|
-
attributes[SEMRESATTRS_SERVICE_VERSION] = config.serviceVersion;
|
|
201
|
-
}
|
|
202
|
-
if (config.environment) {
|
|
203
|
-
attributes[SEMRESATTRS_DEPLOYMENT_ENVIRONMENT] = config.environment;
|
|
204
|
-
}
|
|
205
|
-
const customResource = resourceFromAttributes(attributes);
|
|
206
|
-
const resource = defaultResource().merge(customResource);
|
|
207
|
-
const traceExporter = createTraceExporter(config);
|
|
208
|
-
const metricReader = createMetricReader(config);
|
|
209
|
-
const instrumentations = [
|
|
210
|
-
new HttpInstrumentation({
|
|
211
|
-
requestHook: (span, request) => {
|
|
212
|
-
const req = request;
|
|
213
|
-
if (req.headers) {
|
|
214
|
-
span.setAttribute("http.request.body.size", req.headers["content-length"] || 0);
|
|
215
|
-
}
|
|
216
|
-
},
|
|
217
|
-
responseHook: (span, response) => {
|
|
218
|
-
const res = response;
|
|
219
|
-
if (res.headers) {
|
|
220
|
-
span.setAttribute("http.response.body.size", res.headers["content-length"] || 0);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}),
|
|
224
|
-
new ExpressInstrumentation()
|
|
225
|
-
];
|
|
226
|
-
sdk = new NodeSDK({
|
|
227
|
-
resource,
|
|
228
|
-
spanProcessors: traceExporter ? [new BatchSpanProcessor(traceExporter)] : [],
|
|
229
|
-
metricReader,
|
|
230
|
-
instrumentations
|
|
231
|
-
});
|
|
88
|
+
sdk = new NodeSDK();
|
|
232
89
|
sdk.start();
|
|
233
90
|
isInitialized = true;
|
|
234
91
|
process.on("SIGTERM", async () => {
|
|
@@ -256,11 +113,6 @@ function isOtelInitialized() {
|
|
|
256
113
|
}
|
|
257
114
|
|
|
258
115
|
// otel/src/tracer.ts
|
|
259
|
-
import {
|
|
260
|
-
trace,
|
|
261
|
-
SpanStatusCode,
|
|
262
|
-
context as otelContext
|
|
263
|
-
} from "@opentelemetry/api";
|
|
264
116
|
import { SpanKind, SpanStatusCode as SpanStatusCode2 } from "@opentelemetry/api";
|
|
265
117
|
var TRACER_NAME = "@reactionary/otel";
|
|
266
118
|
var TRACER_VERSION = "0.0.1";
|
|
@@ -356,13 +208,6 @@ function getMetrics() {
|
|
|
356
208
|
return metricsInstance;
|
|
357
209
|
}
|
|
358
210
|
|
|
359
|
-
// otel/src/trpc-middleware.ts
|
|
360
|
-
import { TRPCError } from "@trpc/server";
|
|
361
|
-
import {
|
|
362
|
-
SpanKind as SpanKind2,
|
|
363
|
-
SpanStatusCode as SpanStatusCode3
|
|
364
|
-
} from "@opentelemetry/api";
|
|
365
|
-
|
|
366
211
|
// otel/src/provider-instrumentation.ts
|
|
367
212
|
import { SpanKind as SpanKind3 } from "@opentelemetry/api";
|
|
368
213
|
async function withProviderSpan(options, fn) {
|
|
@@ -440,9 +285,6 @@ function createProviderInstrumentation(providerName) {
|
|
|
440
285
|
};
|
|
441
286
|
}
|
|
442
287
|
|
|
443
|
-
// otel/src/index.ts
|
|
444
|
-
import { trace as trace2, context, SpanKind as SpanKind4, SpanStatusCode as SpanStatusCode4 } from "@opentelemetry/api";
|
|
445
|
-
|
|
446
288
|
// core/src/providers/base.provider.ts
|
|
447
289
|
var BaseProvider = class {
|
|
448
290
|
constructor(schema, querySchema, mutationSchema) {
|
package/package.json
CHANGED