@lokalise/fastify-extras 4.2.0 → 4.3.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/dist/index.d.ts CHANGED
@@ -6,3 +6,5 @@ export { newrelicTransactionManagerPlugin, NewRelicTransactionManager, } from '.
6
6
  export type { NewRelicTransactionManagerOptions } from './plugins/newrelicTransactionManagerPlugin';
7
7
  export { metricsPlugin } from './plugins/metricsPlugin';
8
8
  export type { ErrorObjectResolver, MetricsPluginOptions } from './plugins/metricsPlugin';
9
+ export { prismaOpenTracingPlugin } from './plugins/opentelemetry/opentelemetry/prismaOpenTracingPlugin';
10
+ export type { PrismaOpenTracingPluginConfig } from './plugins/opentelemetry/opentelemetry/prismaOpenTracingPlugin';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.metricsPlugin = exports.NewRelicTransactionManager = exports.newrelicTransactionManagerPlugin = exports.REQUEST_ID_STORE_KEY = exports.getRequestIdFastifyAppConfig = exports.requestContextProviderPlugin = exports.reportErrorToBugsnag = exports.bugsnagPlugin = void 0;
3
+ exports.prismaOpenTracingPlugin = exports.metricsPlugin = exports.NewRelicTransactionManager = exports.newrelicTransactionManagerPlugin = exports.REQUEST_ID_STORE_KEY = exports.getRequestIdFastifyAppConfig = exports.requestContextProviderPlugin = exports.reportErrorToBugsnag = exports.bugsnagPlugin = void 0;
4
4
  var bugsnagPlugin_1 = require("./plugins/bugsnagPlugin");
5
5
  Object.defineProperty(exports, "bugsnagPlugin", { enumerable: true, get: function () { return bugsnagPlugin_1.bugsnagPlugin; } });
6
6
  Object.defineProperty(exports, "reportErrorToBugsnag", { enumerable: true, get: function () { return bugsnagPlugin_1.reportErrorToBugsnag; } });
@@ -13,4 +13,6 @@ Object.defineProperty(exports, "newrelicTransactionManagerPlugin", { enumerable:
13
13
  Object.defineProperty(exports, "NewRelicTransactionManager", { enumerable: true, get: function () { return newrelicTransactionManagerPlugin_1.NewRelicTransactionManager; } });
14
14
  var metricsPlugin_1 = require("./plugins/metricsPlugin");
15
15
  Object.defineProperty(exports, "metricsPlugin", { enumerable: true, get: function () { return metricsPlugin_1.metricsPlugin; } });
16
+ var prismaOpenTracingPlugin_1 = require("./plugins/opentelemetry/opentelemetry/prismaOpenTracingPlugin");
17
+ Object.defineProperty(exports, "prismaOpenTracingPlugin", { enumerable: true, get: function () { return prismaOpenTracingPlugin_1.prismaOpenTracingPlugin; } });
16
18
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;AAAA,yDAA6E;AAApE,8GAAA,aAAa,OAAA;AAAE,qHAAA,oBAAoB,OAAA;AAG5C,uFAI+C;AAH7C,4IAAA,4BAA4B,OAAA;AAC5B,4IAAA,4BAA4B,OAAA;AAC5B,oIAAA,oBAAoB,OAAA;AAItB,+FAGmD;AAFjD,oJAAA,gCAAgC,OAAA;AAChC,8IAAA,0BAA0B,OAAA;AAI5B,yDAAuD;AAA9C,8GAAA,aAAa,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;AAAA,yDAA6E;AAApE,8GAAA,aAAa,OAAA;AAAE,qHAAA,oBAAoB,OAAA;AAG5C,uFAI+C;AAH7C,4IAAA,4BAA4B,OAAA;AAC5B,4IAAA,4BAA4B,OAAA;AAC5B,oIAAA,oBAAoB,OAAA;AAItB,+FAGmD;AAFjD,oJAAA,gCAAgC,OAAA;AAChC,8IAAA,0BAA0B,OAAA;AAI5B,yDAAuD;AAA9C,8GAAA,aAAa,OAAA;AAGtB,yGAAuG;AAA9F,kIAAA,uBAAuB,OAAA"}
@@ -0,0 +1,7 @@
1
+ export interface PrismaOpenTracingPluginConfig {
2
+ isEnabled: boolean;
3
+ useBatchSpans: boolean;
4
+ samplingRatio: number;
5
+ serviceName: string;
6
+ }
7
+ export declare const prismaOpenTracingPlugin: import("fastify").FastifyPluginCallback<PrismaOpenTracingPluginConfig, import("fastify").RawServerDefault, import("fastify").FastifyTypeProviderDefault, import("fastify").FastifyBaseLogger>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prismaOpenTracingPlugin = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const exporter_trace_otlp_grpc_1 = require("@opentelemetry/exporter-trace-otlp-grpc");
6
+ const instrumentation_1 = require("@opentelemetry/instrumentation");
7
+ const resources_1 = require("@opentelemetry/resources");
8
+ const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
9
+ const sdk_trace_node_1 = require("@opentelemetry/sdk-trace-node");
10
+ const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
11
+ const instrumentation_2 = require("@prisma/instrumentation");
12
+ const fastify_plugin_1 = tslib_1.__importDefault(require("fastify-plugin"));
13
+ const spanProcessors_1 = require("./spanProcessors");
14
+ function plugin(app, opts, done) {
15
+ if (opts.isEnabled) {
16
+ const provider = new sdk_trace_node_1.NodeTracerProvider({
17
+ sampler: new sdk_trace_base_1.TraceIdRatioBasedSampler(opts.samplingRatio),
18
+ resource: new resources_1.Resource({
19
+ [semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: opts.serviceName,
20
+ }),
21
+ });
22
+ // Is configured by OTEL_EXPORTER_OTLP_* env vars
23
+ const otlpExporter = new exporter_trace_otlp_grpc_1.OTLPTraceExporter();
24
+ // Production sends spans in batches
25
+ if (opts.useBatchSpans) {
26
+ provider.addSpanProcessor(new spanProcessors_1.LokaliseBatchSpanProcessor(otlpExporter));
27
+ }
28
+ else {
29
+ provider.addSpanProcessor(new spanProcessors_1.LokaliseSimpleSpanProcessor(otlpExporter));
30
+ }
31
+ (0, instrumentation_1.registerInstrumentations)({
32
+ instrumentations: [new instrumentation_2.PrismaInstrumentation()],
33
+ tracerProvider: provider,
34
+ });
35
+ provider.register();
36
+ }
37
+ done();
38
+ }
39
+ exports.prismaOpenTracingPlugin = (0, fastify_plugin_1.default)(plugin, {
40
+ fastify: '4.x',
41
+ name: 'prisma-otel-tracing-plugin',
42
+ });
43
+ //# sourceMappingURL=prismaOpenTracingPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prismaOpenTracingPlugin.js","sourceRoot":"","sources":["../../../../lib/plugins/opentelemetry/opentelemetry/prismaOpenTracingPlugin.ts"],"names":[],"mappings":";;;;AAAA,sFAA2E;AAC3E,oEAAyE;AACzE,wDAAmD;AACnD,kEAAwE;AACxE,kEAAkE;AAClE,8EAAgF;AAChF,6DAA+D;AAE/D,4EAA+B;AAE/B,qDAA0F;AAS1F,SAAS,MAAM,CAAC,GAAoB,EAAE,IAAmC,EAAE,IAAgB;IACzF,IAAI,IAAI,CAAC,SAAS,EAAE;QAClB,MAAM,QAAQ,GAAG,IAAI,mCAAkB,CAAC;YACtC,OAAO,EAAE,IAAI,yCAAwB,CAAC,IAAI,CAAC,aAAa,CAAC;YACzD,QAAQ,EAAE,IAAI,oBAAQ,CAAC;gBACrB,CAAC,iDAA0B,CAAC,YAAY,CAAC,EAAE,IAAI,CAAC,WAAW;aAC5D,CAAC;SACH,CAAC,CAAA;QAEF,iDAAiD;QACjD,MAAM,YAAY,GAAG,IAAI,4CAAiB,EAAE,CAAA;QAE5C,oCAAoC;QACpC,IAAI,IAAI,CAAC,aAAa,EAAE;YACtB,QAAQ,CAAC,gBAAgB,CAAC,IAAI,2CAA0B,CAAC,YAAY,CAAC,CAAC,CAAA;SACxE;aAAM;YACL,QAAQ,CAAC,gBAAgB,CAAC,IAAI,4CAA2B,CAAC,YAAY,CAAC,CAAC,CAAA;SACzE;QAED,IAAA,0CAAwB,EAAC;YACvB,gBAAgB,EAAE,CAAC,IAAI,uCAAqB,EAAE,CAAC;YAC/C,cAAc,EAAE,QAAQ;SACzB,CAAC,CAAA;QAEF,QAAQ,CAAC,QAAQ,EAAE,CAAA;KACpB;IAED,IAAI,EAAE,CAAA;AACR,CAAC;AAEY,QAAA,uBAAuB,GAAG,IAAA,wBAAE,EAAC,MAAM,EAAE;IAChD,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,4BAA4B;CACnC,CAAC,CAAA"}
@@ -0,0 +1,16 @@
1
+ import type { Span } from '@opentelemetry/sdk-trace-base';
2
+ import { BatchSpanProcessor, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
3
+ /**
4
+ * Extends span processor to be able to attach custom attributes request id to spans.
5
+ *
6
+ * This might be easier in the future once the opentelemetry instrumentation for prisma
7
+ * has matured a bit more.
8
+ *
9
+ * @see https://github.com/prisma/prisma/issues/14640#issuecomment-1209931862
10
+ */
11
+ export declare class LokaliseSimpleSpanProcessor extends SimpleSpanProcessor {
12
+ onStart(span: Span): void;
13
+ }
14
+ export declare class LokaliseBatchSpanProcessor extends BatchSpanProcessor {
15
+ onStart(span: Span): void;
16
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LokaliseBatchSpanProcessor = exports.LokaliseSimpleSpanProcessor = void 0;
4
+ const request_context_1 = require("@fastify/request-context");
5
+ const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
6
+ const requestContextProviderPlugin_1 = require("../../requestContextProviderPlugin");
7
+ /**
8
+ * Extends span processor to be able to attach custom attributes request id to spans.
9
+ *
10
+ * This might be easier in the future once the opentelemetry instrumentation for prisma
11
+ * has matured a bit more.
12
+ *
13
+ * @see https://github.com/prisma/prisma/issues/14640#issuecomment-1209931862
14
+ */
15
+ class LokaliseSimpleSpanProcessor extends sdk_trace_base_1.SimpleSpanProcessor {
16
+ onStart(span) {
17
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
18
+ const requestId = request_context_1.requestContext.get(requestContextProviderPlugin_1.REQUEST_ID_STORE_KEY);
19
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
20
+ span.setAttribute(requestContextProviderPlugin_1.REQUEST_ID_STORE_KEY, requestId);
21
+ }
22
+ }
23
+ exports.LokaliseSimpleSpanProcessor = LokaliseSimpleSpanProcessor;
24
+ class LokaliseBatchSpanProcessor extends sdk_trace_base_1.BatchSpanProcessor {
25
+ onStart(span) {
26
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
27
+ const requestId = request_context_1.requestContext.get(requestContextProviderPlugin_1.REQUEST_ID_STORE_KEY);
28
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
29
+ span.setAttribute(requestContextProviderPlugin_1.REQUEST_ID_STORE_KEY, requestId);
30
+ }
31
+ }
32
+ exports.LokaliseBatchSpanProcessor = LokaliseBatchSpanProcessor;
33
+ //# sourceMappingURL=spanProcessors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spanProcessors.js","sourceRoot":"","sources":["../../../../lib/plugins/opentelemetry/opentelemetry/spanProcessors.ts"],"names":[],"mappings":";;;AAAA,8DAAyD;AAEzD,kEAAuF;AAEvF,qFAAyE;AAEzE;;;;;;;GAOG;AACH,MAAa,2BAA4B,SAAQ,oCAAmB;IAClE,OAAO,CAAC,IAAU;QAChB,mEAAmE;QACnE,MAAM,SAAS,GAAG,gCAAc,CAAC,GAAG,CAAC,mDAAoB,CAAC,CAAA;QAC1D,iEAAiE;QACjE,IAAI,CAAC,YAAY,CAAC,mDAAoB,EAAE,SAAS,CAAC,CAAA;IACpD,CAAC;CACF;AAPD,kEAOC;AAED,MAAa,0BAA2B,SAAQ,mCAAkB;IAChE,OAAO,CAAC,IAAU;QAChB,mEAAmE;QACnE,MAAM,SAAS,GAAG,gCAAc,CAAC,GAAG,CAAC,mDAAoB,CAAC,CAAA;QAC1D,iEAAiE;QACjE,IAAI,CAAC,YAAY,CAAC,mDAAoB,EAAE,SAAS,CAAC,CAAA;IACpD,CAAC;CACF;AAPD,gEAOC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lokalise/fastify-extras",
3
- "version": "4.2.0",
3
+ "version": "4.3.0",
4
4
  "description": "Opinionated set of fastify plugins, commonly used in Lokalise",
5
5
  "author": {
6
6
  "name": "Lokalise",
@@ -47,6 +47,14 @@
47
47
  "peerDependencies": {
48
48
  "@bugsnag/js": "^7.18.0",
49
49
  "@fastify/request-context": "^4.2.0",
50
+ "@opentelemetry/api": "^1.3.0",
51
+ "@opentelemetry/exporter-trace-otlp-grpc": "^0.34.0",
52
+ "@opentelemetry/instrumentation": "^0.34.0",
53
+ "@opentelemetry/resources": "^1.8.0",
54
+ "@opentelemetry/sdk-trace-base": "^1.8.0",
55
+ "@opentelemetry/sdk-trace-node": "^1.8.0",
56
+ "@opentelemetry/semantic-conventions": "^1.8.0",
57
+ "@prisma/instrumentation": "^4.8.0",
50
58
  "fastify": "^4.10.2",
51
59
  "fastify-metrics": "^10.0.1",
52
60
  "newrelic": "^9.7.4",
@@ -56,6 +64,14 @@
56
64
  "@bugsnag/js": "^7.18.0",
57
65
  "@fastify/request-context": "^4.2.0",
58
66
  "@lokalise/node-core": "^2.0.1",
67
+ "@opentelemetry/api": "^1.3.0",
68
+ "@opentelemetry/exporter-trace-otlp-grpc": "^0.34.0",
69
+ "@opentelemetry/instrumentation": "^0.34.0",
70
+ "@opentelemetry/resources": "^1.8.0",
71
+ "@opentelemetry/sdk-trace-base": "^1.8.0",
72
+ "@opentelemetry/sdk-trace-node": "^1.8.0",
73
+ "@opentelemetry/semantic-conventions": "^1.8.0",
74
+ "@prisma/instrumentation": "^4.8.0",
59
75
  "@types/jest": "^29.2.5",
60
76
  "@types/newrelic": "^9.4.0",
61
77
  "@types/node": "^18.11.18",