@faststore/api 3.35.0 → 3.38.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/api",
3
- "version": "3.33.3",
3
+ "version": "3.35.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/cjs/src/index.js",
6
6
  "typings": "dist/esm/src/index.d.ts",
@@ -37,17 +37,9 @@
37
37
  "generate": "graphql-codegen --config codegen.yml"
38
38
  },
39
39
  "dependencies": {
40
- "@envelop/on-resolve": "^4.1.1",
41
40
  "@graphql-tools/load-files": "^7.0.0",
42
41
  "@graphql-tools/schema": "^9.0.0",
43
42
  "@graphql-tools/utils": "^10.2.0",
44
- "@opentelemetry/api": "^1.4.1",
45
- "@opentelemetry/api-logs": "^0.39.1",
46
- "@opentelemetry/exporter-logs-otlp-grpc": "^0.39.1",
47
- "@opentelemetry/exporter-trace-otlp-grpc": "^0.39.1",
48
- "@opentelemetry/resources": "^1.13.0",
49
- "@opentelemetry/sdk-logs": "^0.39.1",
50
- "@opentelemetry/sdk-trace-base": "^1.13.0",
51
43
  "@rollup/plugin-graphql": "^1.0.0",
52
44
  "cookie": "^0.7.0",
53
45
  "dataloader": "^2.1.0",
@@ -57,7 +49,6 @@
57
49
  "sanitize-html": "^2.11.0"
58
50
  },
59
51
  "devDependencies": {
60
- "@envelop/core": "^5.0.2",
61
52
  "@graphql-codegen/cli": "2.2.0",
62
53
  "@graphql-codegen/typescript": "2.2.2",
63
54
  "@parcel/watcher": "^2.4.0",
@@ -77,7 +68,6 @@
77
68
  "tsx": "^4.6.2"
78
69
  },
79
70
  "peerDependencies": {
80
- "@envelop/core": "^5",
81
71
  "graphql": "^15.6.0"
82
72
  },
83
73
  "volta": {
@@ -1,7 +1,6 @@
1
1
  import type { Options as OptionsVTEX } from './platforms/vtex';
2
2
  export * from './__generated__/schema';
3
3
  export * from './platforms/errors';
4
- export * from './telemetry';
5
4
  export { stringify as stringifyCacheControl } from './directives/cacheControl';
6
5
  export type { CacheControl } from './directives/cacheControl';
7
6
  export type Options = OptionsVTEX;
@@ -8,7 +8,6 @@ const typeDefs_1 = require("./typeDefs");
8
8
  const cacheControl_1 = tslib_1.__importDefault(require("./directives/cacheControl"));
9
9
  tslib_1.__exportStar(require("./__generated__/schema"), exports);
10
10
  tslib_1.__exportStar(require("./platforms/errors"), exports);
11
- tslib_1.__exportStar(require("./telemetry"), exports);
12
11
  var cacheControl_2 = require("./directives/cacheControl");
13
12
  Object.defineProperty(exports, "stringifyCacheControl", { enumerable: true, get: function () { return cacheControl_2.stringify; } });
14
13
  const platforms = {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":";;;;AAAA,kDAA4D;AAE5D,2CAGyB;AACzB,yCAAqC;AACrC,qFAA6D;AAI7D,iEAAsC;AACtC,6DAAkC;AAClC,sDAA2B;AAC3B,0DAA8E;AAArE,qHAAA,SAAS,OAAyB;AAK3C,MAAM,SAAS,GAAG;IAChB,IAAI,EAAE;QACJ,YAAY,EAAE,mBAAgB;QAC9B,iBAAiB,EAAE,wBAAqB;KACzC;CACF,CAAA;AAED,MAAM,UAAU,GAAgB,CAAC,sBAAqB,CAAC,CAAA;AAEhD,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC;IAC/B,mBAAQ;IACR,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;CACrC,CAAA;AAHY,QAAA,WAAW,eAGvB;AAEM,MAAM,YAAY,GAAG,CAAC,OAAgB,EAAE,EAAE,CAC/C,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,CAAA;AADtC,QAAA,YAAY,gBAC0B;AAE5C,MAAM,iBAAiB,GAAG,CAAC,OAAgB,EAAE,EAAE,CACpD,SAAS,CAAC,OAAO,CAAC,QA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,EAAE,EAAE,CACpD,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAA;AAD3C,QAAA,iBAAiB,qBAC0B;AAEjD,MAAM,SAAS,GAAG,KAAK,EAAE,OAAgB,EAAE,EAAE;IAClD,MAAM,MAAM,GAAG,IAAA,6BAAoB,EAAC;QAClC,SAAS,EAAE,IAAA,oBAAY,EAAC,OAAO,CAAC;QAChC,QAAQ,EAAE,IAAA,mBAAW,GAAE;KACxB,CAAC,CAAA;IAEF,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;AAC9D,CAAC,CAAA;AAPY,QAAA,SAAS,aAOrB;AAED,0EAA+C"}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/api",
3
- "version": "3.33.3",
3
+ "version": "3.35.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/cjs/src/index.js",
6
6
  "typings": "dist/esm/src/index.d.ts",
@@ -37,17 +37,9 @@
37
37
  "generate": "graphql-codegen --config codegen.yml"
38
38
  },
39
39
  "dependencies": {
40
- "@envelop/on-resolve": "^4.1.1",
41
40
  "@graphql-tools/load-files": "^7.0.0",
42
41
  "@graphql-tools/schema": "^9.0.0",
43
42
  "@graphql-tools/utils": "^10.2.0",
44
- "@opentelemetry/api": "^1.4.1",
45
- "@opentelemetry/api-logs": "^0.39.1",
46
- "@opentelemetry/exporter-logs-otlp-grpc": "^0.39.1",
47
- "@opentelemetry/exporter-trace-otlp-grpc": "^0.39.1",
48
- "@opentelemetry/resources": "^1.13.0",
49
- "@opentelemetry/sdk-logs": "^0.39.1",
50
- "@opentelemetry/sdk-trace-base": "^1.13.0",
51
43
  "@rollup/plugin-graphql": "^1.0.0",
52
44
  "cookie": "^0.7.0",
53
45
  "dataloader": "^2.1.0",
@@ -57,7 +49,6 @@
57
49
  "sanitize-html": "^2.11.0"
58
50
  },
59
51
  "devDependencies": {
60
- "@envelop/core": "^5.0.2",
61
52
  "@graphql-codegen/cli": "2.2.0",
62
53
  "@graphql-codegen/typescript": "2.2.2",
63
54
  "@parcel/watcher": "^2.4.0",
@@ -77,7 +68,6 @@
77
68
  "tsx": "^4.6.2"
78
69
  },
79
70
  "peerDependencies": {
80
- "@envelop/core": "^5",
81
71
  "graphql": "^15.6.0"
82
72
  },
83
73
  "volta": {
@@ -1,7 +1,6 @@
1
1
  import type { Options as OptionsVTEX } from './platforms/vtex';
2
2
  export * from './__generated__/schema';
3
3
  export * from './platforms/errors';
4
- export * from './telemetry';
5
4
  export { stringify as stringifyCacheControl } from './directives/cacheControl';
6
5
  export type { CacheControl } from './directives/cacheControl';
7
6
  export type Options = OptionsVTEX;
@@ -4,7 +4,6 @@ import { typeDefs } from './typeDefs';
4
4
  import cacheControlDirective from './directives/cacheControl';
5
5
  export * from './__generated__/schema';
6
6
  export * from './platforms/errors';
7
- export * from './telemetry';
8
7
  export { stringify as stringifyCacheControl } from './directives/cacheControl';
9
8
  const platforms = {
10
9
  vtex: {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAE5D,OAAO,EACL,iBAAiB,IAAI,qBAAqB,EAC1C,YAAY,IAAI,gBAAgB,GACjC,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,qBAAqB,MAAM,2BAA2B,CAAA;AAI7D,cAAc,wBAAwB,CAAA;AACtC,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,OAAO,EAAE,SAAS,IAAI,qBAAqB,EAAE,MAAM,2BAA2B,CAAA;AAK9E,MAAM,SAAS,GAAG;IAChB,IAAI,EAAE;QACJ,YAAY,EAAE,gBA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.38.1",
4
4
  "license": "MIT",
5
5
  "main": "dist/cjs/src/index.js",
6
6
  "typings": "dist/esm/src/index.d.ts",
@@ -37,17 +37,9 @@
37
37
  "generate": "graphql-codegen --config codegen.yml"
38
38
  },
39
39
  "dependencies": {
40
- "@envelop/on-resolve": "^4.1.1",
41
40
  "@graphql-tools/load-files": "^7.0.0",
42
41
  "@graphql-tools/schema": "^9.0.0",
43
42
  "@graphql-tools/utils": "^10.2.0",
44
- "@opentelemetry/api": "^1.4.1",
45
- "@opentelemetry/api-logs": "^0.39.1",
46
- "@opentelemetry/exporter-logs-otlp-grpc": "^0.39.1",
47
- "@opentelemetry/exporter-trace-otlp-grpc": "^0.39.1",
48
- "@opentelemetry/resources": "^1.13.0",
49
- "@opentelemetry/sdk-logs": "^0.39.1",
50
- "@opentelemetry/sdk-trace-base": "^1.13.0",
51
43
  "@rollup/plugin-graphql": "^1.0.0",
52
44
  "cookie": "^0.7.0",
53
45
  "dataloader": "^2.1.0",
@@ -57,7 +49,6 @@
57
49
  "sanitize-html": "^2.11.0"
58
50
  },
59
51
  "devDependencies": {
60
- "@envelop/core": "^5.0.2",
61
52
  "@graphql-codegen/cli": "2.2.0",
62
53
  "@graphql-codegen/typescript": "2.2.2",
63
54
  "@parcel/watcher": "^2.4.0",
@@ -77,11 +68,10 @@
77
68
  "tsx": "^4.6.2"
78
69
  },
79
70
  "peerDependencies": {
80
- "@envelop/core": "^5",
81
71
  "graphql": "^15.6.0"
82
72
  },
83
73
  "volta": {
84
74
  "extends": "../../package.json"
85
75
  },
86
- "gitHead": "d7888ccc4f9e5511cc18a483d5d0014fdf15f6ab"
76
+ "gitHead": "3d76b44ce14b7b9c4df57bec7b886c382b5f720c"
87
77
  }
package/src/index.ts CHANGED
@@ -11,7 +11,6 @@ import type { Options as OptionsVTEX } from './platforms/vtex'
11
11
 
12
12
  export * from './__generated__/schema'
13
13
  export * from './platforms/errors'
14
- export * from './telemetry'
15
14
  export { stringify as stringifyCacheControl } from './directives/cacheControl'
16
15
  export type { CacheControl } from './directives/cacheControl'
17
16
 
@@ -1,8 +0,0 @@
1
- import type { Options } from '../';
2
- export type GetTelemetryOptions = {
3
- mode?: 'verbose' | 'dev';
4
- experimentalSendLogs?: boolean;
5
- };
6
- export declare function getTelemetry(APIOptions: Options, telemetryOptions?: GetTelemetryOptions): {
7
- useFaststoreTelemetry: () => import("@envelop/core").Plugin<import("./useFaststoreTelemetry").PluginContext>;
8
- };
@@ -1,77 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTelemetry = void 0;
4
- const tslib_1 = require("tslib");
5
- const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
6
- const resources_1 = require("@opentelemetry/resources");
7
- const exporter_trace_otlp_grpc_1 = require("@opentelemetry/exporter-trace-otlp-grpc");
8
- const sdk_logs_1 = require("@opentelemetry/sdk-logs");
9
- const exporter_logs_otlp_grpc_1 = require("@opentelemetry/exporter-logs-otlp-grpc");
10
- const useFaststoreTelemetry_1 = require("./useFaststoreTelemetry");
11
- const package_json_1 = tslib_1.__importDefault(require("../../package.json"));
12
- const FASTSTORE_API_VERSION = package_json_1.default.version;
13
- // TODO: These urls are hardcoded for now, but they should be configurable via ENV variables
14
- // They are only acessible from within the VTEX network, so they are not a security risk
15
- const TRACE_COLLECTOR_URL = 'opentelemetry-collector.vtex.systems';
16
- const TRACE_COLLECTOR_URL_DEV = 'opentelemetry-collector-beta.vtex.systems';
17
- const LOG_COLLECTOR_URL = 'opentelemetry-collector.vtex.systems';
18
- function getTelemetry(APIOptions, telemetryOptions) {
19
- const honeycombCollectorOptions = {
20
- url: telemetryOptions?.mode === 'dev'
21
- ? TRACE_COLLECTOR_URL_DEV
22
- : TRACE_COLLECTOR_URL,
23
- };
24
- const openSearchCollectorOptions = {
25
- url: LOG_COLLECTOR_URL,
26
- };
27
- // Create a new tracer provider
28
- const tracerProvider = new sdk_trace_base_1.BasicTracerProvider({
29
- resource: new resources_1.Resource({
30
- 'service.name': 'faststore-api',
31
- 'service.version': FASTSTORE_API_VERSION,
32
- 'service.name_and_version': `faststore-api@${FASTSTORE_API_VERSION}`,
33
- platform: APIOptions.platform,
34
- [`${APIOptions.platform}.account`]: APIOptions.account,
35
- [`${APIOptions.platform}.environment`]: APIOptions.environment,
36
- // TODO: include the following properties in the logs
37
- // [`${APIOptions.platform}.options.hideUnavailableItems`]:
38
- // APIOptions.hideUnavailableItems,
39
- // [`${APIOptions.platform}.flags.enableOrderFormSync`]:
40
- // APIOptions.flags?.enableOrderFormSync,
41
- // channel: APIOptions.channel,
42
- locale: APIOptions.locale,
43
- }),
44
- });
45
- const loggerProvider = new sdk_logs_1.LoggerProvider();
46
- // Create trace exporter
47
- const honeycombExporter = new exporter_trace_otlp_grpc_1.OTLPTraceExporter(honeycombCollectorOptions);
48
- // Create log exporter
49
- const openSearchExporter = new exporter_logs_otlp_grpc_1.OTLPLogsExporter(openSearchCollectorOptions);
50
- // Set up a span processor to export spans to Honeycomb
51
- const honeyCombSpanProcessor = new sdk_trace_base_1.SimpleSpanProcessor(honeycombExporter);
52
- // Set up a log record processor to export spans to OpenSearch
53
- const openSearchLogProcessor = new sdk_logs_1.SimpleLogRecordProcessor(openSearchExporter);
54
- // Register the span processor with the tracer provider
55
- tracerProvider.addSpanProcessor(honeyCombSpanProcessor);
56
- // Register the log record processor with the log provider
57
- loggerProvider.addLogRecordProcessor(openSearchLogProcessor);
58
- if (telemetryOptions?.mode === 'verbose' ||
59
- telemetryOptions?.mode === 'dev') {
60
- // Set up a console exporter for verbose mode
61
- const consoleExporter = new sdk_trace_base_1.ConsoleSpanExporter();
62
- const verboseTraceProcessor = new sdk_trace_base_1.SimpleSpanProcessor(consoleExporter);
63
- // Set up processors for verbose mode
64
- const consoleLogExporter = new sdk_logs_1.ConsoleLogRecordExporter();
65
- const veboseLogRecordExporter = new sdk_logs_1.SimpleLogRecordProcessor(consoleLogExporter);
66
- tracerProvider.addSpanProcessor(verboseTraceProcessor);
67
- loggerProvider.addLogRecordProcessor(veboseLogRecordExporter);
68
- }
69
- const useFaststoreTelemetry = (0, useFaststoreTelemetry_1.getFaststoreTelemetryPlugin)(
70
- // The @opentelemetry/sdk-trace-base was renamed from @opentelemetry/tracing but the
71
- // envelop plugin doesn't support this change yet. This causes the class type to be incompatible,
72
- // even if they are the same. https://github.com/n1ru4l/envelop/issues/1610
73
- tracerProvider, loggerProvider, 'faststore-api', telemetryOptions?.experimentalSendLogs ?? false);
74
- return { useFaststoreTelemetry };
75
- }
76
- exports.getTelemetry = getTelemetry;
77
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/telemetry/index.ts"],"names":[],"mappings":";;;;AAAA,kEAIsC;AACtC,wDAAmD;AACnD,sFAA2E;AAC3E,sDAIgC;AAChC,oFAAyE;AAGzE,mEAAqE;AACrE,8EAA4C;AAO5C,MAAM,qBAAqB,GAAG,sBAAW,CAAC,OAAO,CAAA;AAEjD,4FAA4F;AAC5F,wFAAwF;AACxF,MAAM,mBAAmB,GAAG,sCAAsC,CAAA;AAClE,MAAM,uBAAuB,GAAG,2CAA2C,CAAA;AAC3E,MAAM,iBAAiB,GAAG,sCAAsC,CAAA;AAEhE,SAAgB,YAAY,CAC1B,UAAmB,EACnB,gBAAsC;IAEtC,MAAM,yBAAyB,GAAG;QAChC,GAAG,EACD,gBAAgB,EAAE,IAAI,KAAK,KAAK;YAC9B,CAAC,CAAC,uBAAuB;YACzB,CAAC,CAAC,mBAAmB;KAC1B,CAAA;IAED,MAAM,0BAA0B,GAAG;QACjC,GAAG,EAAE,iBAAiB;KACvB,CAAA;IAED,+BAA+B;IAC/B,MAAM,cAAc,GAAG,IAAI,oCAAmB,CAAC;QAC7C,QAAQ,EAAE,IAAI,oBAAQ,CAAC;YACrB,cAAc,EAAE,eAAe;YAC/B,iBAAiB,EAAE,qBAAqB;YACxC,0BAA0B,EAAE,iBAAiB,qBAAqB,EAAE;YACpE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AAC,gBAAgB,CAAC,qBAAqB,CAAC,CAAA;QACtD,cAAc,CAAC,qBAAqB,CAAC,uBAAuB,CAAC,CAAA;IAC/D,CAAC;IAED,MAAM,qBAAqB,GAAG,IAAA,mDAA2B;IACvD,oFAAoF;IACpF,iGAAiG;IACjG,2EAA2E;IAC3E,cAAqB,EACrB,cAAc,EACd,eAAe,EACf,gBAAgB,EAAE,oBAAoB,IAAI,KAAK,CAChD,CAAA;IAED,OAAO,EAAE,qBAAqB,EAAE,CAAA;AAClC,CAAC;AArFD,oCAqFC"}
@@ -1,24 +0,0 @@
1
- import type { Plugin } from '@envelop/core';
2
- import { type Span } from '@opentelemetry/api';
3
- import type { LoggerProvider } from '@opentelemetry/sdk-logs';
4
- import type { BasicTracerProvider } from '@opentelemetry/sdk-trace-base';
5
- export declare enum AttributeName {
6
- EXECUTION_ERROR = "graphql.error",
7
- EXECUTION_RESULT = "graphql.result",
8
- RESOLVER_EXECUTION_ERROR = "graphql.resolver.error",
9
- RESOLVER_EXCEPTION = "graphql.resolver.exception",
10
- RESOLVER_FIELD_NAME = "graphql.resolver.fieldName",
11
- RESOLVER_TYPE_NAME = "graphql.resolver.typeName",
12
- RESOLVER_RESULT_TYPE = "graphql.resolver.resultType",
13
- RESOLVER_ARGS = "graphql.resolver.args",
14
- EXECUTION_OPERATION_NAME = "graphql.operation.name",
15
- EXECUTION_OPERATION_TYPE = "graphql.operation.type",
16
- EXECUTION_OPERATION_DOCUMENT = "graphql.document",
17
- EXECUTION_VARIABLES = "graphql.variables"
18
- }
19
- declare const tracingSpanSymbol: unique symbol;
20
- export type PluginContext = {
21
- [tracingSpanSymbol]: Span;
22
- };
23
- export declare const getFaststoreTelemetryPlugin: (tracingProvider: BasicTracerProvider, loggerProvider: LoggerProvider, serviceName: string, experimentalSendLogs: boolean) => (() => Plugin<PluginContext>);
24
- export {};
@@ -1,170 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFaststoreTelemetryPlugin = exports.AttributeName = void 0;
4
- const core_1 = require("@envelop/core");
5
- const on_resolve_1 = require("@envelop/on-resolve");
6
- const api_1 = require("@opentelemetry/api");
7
- const api_logs_1 = require("@opentelemetry/api-logs");
8
- const graphql_1 = require("graphql");
9
- var AttributeName;
10
- (function (AttributeName) {
11
- AttributeName["EXECUTION_ERROR"] = "graphql.error";
12
- AttributeName["EXECUTION_RESULT"] = "graphql.result";
13
- AttributeName["RESOLVER_EXECUTION_ERROR"] = "graphql.resolver.error";
14
- AttributeName["RESOLVER_EXCEPTION"] = "graphql.resolver.exception";
15
- AttributeName["RESOLVER_FIELD_NAME"] = "graphql.resolver.fieldName";
16
- AttributeName["RESOLVER_TYPE_NAME"] = "graphql.resolver.typeName";
17
- AttributeName["RESOLVER_RESULT_TYPE"] = "graphql.resolver.resultType";
18
- AttributeName["RESOLVER_ARGS"] = "graphql.resolver.args";
19
- AttributeName["EXECUTION_OPERATION_NAME"] = "graphql.operation.name";
20
- AttributeName["EXECUTION_OPERATION_TYPE"] = "graphql.operation.type";
21
- AttributeName["EXECUTION_OPERATION_DOCUMENT"] = "graphql.document";
22
- AttributeName["EXECUTION_VARIABLES"] = "graphql.variables";
23
- })(AttributeName || (exports.AttributeName = AttributeName = {}));
24
- const tracingSpanSymbol = Symbol('OPEN_TELEMETRY_GRAPHQL');
25
- function getResolverSpanKey(path) {
26
- const nodes = [];
27
- // If the first node (after reversed, it will be the last one) is an integer, that is, identifies a list,
28
- // we don't want to include it in the key. Note that this will only happen when analysing .prev paths in
29
- // a list of elements. We just want to remove the initial node that is a integer, not all of them.
30
- //
31
- // Nodes with keys 6bc73341b2a183fc::product::image::0::url would not be able to find
32
- // parents with key 6bc73341b2a183fc::product::image because of the "0" list index -
33
- // it would search for 6bc73341b2a183fc::product::image::0
34
- let currentPath = nodes.length === 0 && Number.isInteger(path.key) ? path.prev : path;
35
- while (currentPath) {
36
- nodes.push(currentPath.key);
37
- currentPath = currentPath.prev;
38
- }
39
- return [...nodes].reverse().join('.');
40
- }
41
- const getFaststoreTelemetryPlugin = (tracingProvider, loggerProvider, serviceName, experimentalSendLogs) => {
42
- return function useFaststoreTelemetry() {
43
- const tracer = tracingProvider.getTracer(serviceName);
44
- const logger = loggerProvider.getLogger(serviceName);
45
- const resolverContextsByRootSpans = {};
46
- return {
47
- onPluginInit({ addPlugin }) {
48
- addPlugin((0, on_resolve_1.useOnResolve)(({ info, context }) => {
49
- if (context &&
50
- typeof context === 'object' &&
51
- context[tracingSpanSymbol]) {
52
- tracer.getActiveSpanProcessor();
53
- const rootContextSpanId = context[tracingSpanSymbol].spanContext().spanId;
54
- const { fieldName, returnType, parentType, path } = info;
55
- const previousResolverSpanKey = path.prev && getResolverSpanKey(path.prev);
56
- let ctx = null;
57
- if (previousResolverSpanKey &&
58
- resolverContextsByRootSpans[rootContextSpanId][previousResolverSpanKey]) {
59
- ctx =
60
- resolverContextsByRootSpans[rootContextSpanId][previousResolverSpanKey];
61
- }
62
- else {
63
- ctx = api_1.trace.setSpan(api_1.context.active(), context[tracingSpanSymbol]);
64
- resolverContextsByRootSpans[rootContextSpanId] =
65
- resolverContextsByRootSpans[rootContextSpanId] ?? {};
66
- }
67
- const resolverIndexInList = Number.isInteger(path.prev?.key)
68
- ? `[${path.prev?.key}]`
69
- : '';
70
- const resolverSpan = tracer.startSpan(`${parentType.toString()}.${fieldName}${resolverIndexInList}`, {
71
- attributes: {
72
- [AttributeName.RESOLVER_FIELD_NAME]: fieldName,
73
- [AttributeName.RESOLVER_TYPE_NAME]: parentType.toString(),
74
- [AttributeName.RESOLVER_RESULT_TYPE]: returnType.toString(),
75
- 'meta.span.path': getResolverSpanKey(path),
76
- },
77
- }, ctx);
78
- const resolverCtx = api_1.trace.setSpan(ctx, resolverSpan);
79
- resolverContextsByRootSpans[rootContextSpanId][getResolverSpanKey(path)] = resolverCtx;
80
- return ({ result }) => {
81
- if (result instanceof Error) {
82
- resolverSpan.setAttributes({
83
- error: true,
84
- 'exception.category': AttributeName.RESOLVER_EXECUTION_ERROR,
85
- 'exception.message': result.message,
86
- 'exception.type': result.name,
87
- });
88
- resolverSpan.recordException(result);
89
- }
90
- resolverSpan.end();
91
- };
92
- }
93
- return () => { };
94
- }));
95
- },
96
- onExecute({ args, extendContext }) {
97
- const operationType = args.document.definitions
98
- .filter((def) => def.kind === graphql_1.Kind.OPERATION_DEFINITION)
99
- .map((def) => def.operation)?.[0];
100
- // Span name according to Semantic Conventions
101
- // https://github.com/open-telemetry/semantic-conventions
102
- let spanName = 'GraphQL Operation';
103
- if (operationType && args.operationName) {
104
- spanName = `${operationType} ${args.operationName}`;
105
- }
106
- else if (operationType && !args.operationName) {
107
- spanName = operationType;
108
- }
109
- const executionSpan = tracer.startSpan(spanName, {
110
- kind: api_1.SpanKind.SERVER,
111
- attributes: {
112
- [AttributeName.EXECUTION_OPERATION_NAME]: args.operationName ?? undefined,
113
- [AttributeName.EXECUTION_OPERATION_TYPE]: operationType ?? undefined,
114
- [AttributeName.EXECUTION_OPERATION_DOCUMENT]: (0, graphql_1.print)(args.document),
115
- },
116
- });
117
- const executeContext = api_1.context.active();
118
- const resultCbs = {
119
- onExecuteDone({ result }) {
120
- if ((0, core_1.isAsyncIterable)(result)) {
121
- executionSpan.end();
122
- console.warn(`Plugin "newrelic" encountered a AsyncIterator which is not supported yet, so tracing data is not available for the operation.`);
123
- return;
124
- }
125
- const logRecord = {
126
- context: executeContext,
127
- attributes: {
128
- 'service.name': 'faststore-api',
129
- 'service.version': '1.12.38',
130
- 'service.name_and_version': 'faststore-api@1.12.38',
131
- 'vtex.search_index': 'faststore_beta_api',
132
- [AttributeName.EXECUTION_OPERATION_NAME]: args.operationName ?? undefined,
133
- [AttributeName.EXECUTION_OPERATION_DOCUMENT]: (0, graphql_1.print)(args.document),
134
- [AttributeName.EXECUTION_VARIABLES]: JSON.stringify(args.variableValues ?? {}),
135
- },
136
- };
137
- if (typeof result.data !== 'undefined' &&
138
- !(result.errors && result.errors.length > 0)) {
139
- logRecord.severityNumber = api_logs_1.SeverityNumber.INFO;
140
- logRecord.severityText = 'Info';
141
- logRecord.attributes[AttributeName.EXECUTION_RESULT] =
142
- JSON.stringify(result);
143
- }
144
- if (result.errors && result.errors.length > 0) {
145
- logRecord.severityNumber = api_logs_1.SeverityNumber.ERROR;
146
- logRecord.severityText = 'Error';
147
- logRecord.attributes[AttributeName.EXECUTION_ERROR] =
148
- JSON.stringify(result.errors);
149
- executionSpan.setAttributes({
150
- error: true,
151
- 'exception.category': AttributeName.EXECUTION_ERROR,
152
- 'exception.message': JSON.stringify(result.errors),
153
- });
154
- }
155
- if (experimentalSendLogs) {
156
- logger.emit(logRecord);
157
- }
158
- executionSpan.end();
159
- },
160
- };
161
- extendContext({
162
- [tracingSpanSymbol]: executionSpan,
163
- });
164
- return resultCbs;
165
- },
166
- };
167
- };
168
- };
169
- exports.getFaststoreTelemetryPlugin = getFaststoreTelemetryPlugin;
170
- //# sourceMappingURL=useFaststoreTelemetry.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useFaststoreTelemetry.js","sourceRoot":"","sources":["../../../../src/telemetry/useFaststoreTelemetry.ts"],"names":[],"mappings":";;;AACA,wCAA+C;AAC/C,oDAAkD;AAClD,4CAM2B;AAE3B,sDAAwD;AAGxD,qCAKgB;AAGhB,IAAY,aAaX;AAbD,WAAY,aAAa;IACvB,kDAAiC,CAAA;IACjC,oDAAmC,CAAA;IACnC,oEAAmD,CAAA;IACnD,kEAAiD,CAAA;IACjD,mEAAkD,CAAA;IAClD,iEAAgD,CAAA;IAChD,qEAAoD,CAAA;IACpD,wDAAuC,CAAA;IACvC,oEAAmD,CAAA;IACnD,oEAAmD,CAAA;IACnD,kEAAiD,CAAA;IACjD,0DAAyC,CAAA;AAC3C,CAAC,EAbW,aAAa,6BAAb,aAAa,QAaxB;AAED,MAAM,iBAAiB,GAAG,MAAM,CAAC,wBAAwB,CAAC,CAAA;AAM1D,SAAS,kBAAkB,CAAC,IAAU;IACpC,MAAM,KAAK,GAA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 'dev';
4
- experimentalSendLogs?: boolean;
5
- };
6
- export declare function getTelemetry(APIOptions: Options, telemetryOptions?: GetTelemetryOptions): {
7
- useFaststoreTelemetry: () => import("@envelop/core").Plugin<import("./useFaststoreTelemetry").PluginContext>;
8
- };
@@ -1,72 +0,0 @@
1
- import { BasicTracerProvider, SimpleSpanProcessor, ConsoleSpanExporter, } from '@opentelemetry/sdk-trace-base';
2
- import { Resource } from '@opentelemetry/resources';
3
- import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';
4
- import { LoggerProvider, SimpleLogRecordProcessor, ConsoleLogRecordExporter, } from '@opentelemetry/sdk-logs';
5
- import { OTLPLogsExporter } from '@opentelemetry/exporter-logs-otlp-grpc';
6
- import { getFaststoreTelemetryPlugin } from './useFaststoreTelemetry';
7
- import packageJson from '../../package.json';
8
- const FASTSTORE_API_VERSION = packageJson.version;
9
- // TODO: These urls are hardcoded for now, but they should be configurable via ENV variables
10
- // They are only acessible from within the VTEX network, so they are not a security risk
11
- const TRACE_COLLECTOR_URL = 'opentelemetry-collector.vtex.systems';
12
- const TRACE_COLLECTOR_URL_DEV = 'opentelemetry-collector-beta.vtex.systems';
13
- const LOG_COLLECTOR_URL = 'opentelemetry-collector.vtex.systems';
14
- export function getTelemetry(APIOptions, telemetryOptions) {
15
- const honeycombCollectorOptions = {
16
- url: telemetryOptions?.mode === 'dev'
17
- ? TRACE_COLLECTOR_URL_DEV
18
- : TRACE_COLLECTOR_URL,
19
- };
20
- const openSearchCollectorOptions = {
21
- url: LOG_COLLECTOR_URL,
22
- };
23
- // Create a new tracer provider
24
- const tracerProvider = new BasicTracerProvider({
25
- resource: new Resource({
26
- 'service.name': 'faststore-api',
27
- 'service.version': FASTSTORE_API_VERSION,
28
- 'service.name_and_version': `faststore-api@${FASTSTORE_API_VERSION}`,
29
- platform: APIOptions.platform,
30
- [`${APIOptions.platform}.account`]: APIOptions.account,
31
- [`${APIOptions.platform}.environment`]: APIOptions.environment,
32
- // TODO: include the following properties in the logs
33
- // [`${APIOptions.platform}.options.hideUnavailableItems`]:
34
- // APIOptions.hideUnavailableItems,
35
- // [`${APIOptions.platform}.flags.enableOrderFormSync`]:
36
- // APIOptions.flags?.enableOrderFormSync,
37
- // channel: APIOptions.channel,
38
- locale: APIOptions.locale,
39
- }),
40
- });
41
- const loggerProvider = new LoggerProvider();
42
- // Create trace exporter
43
- const honeycombExporter = new OTLPTraceExporter(honeycombCollectorOptions);
44
- // Create log exporter
45
- const openSearchExporter = new OTLPLogsExporter(openSearchCollectorOptions);
46
- // Set up a span processor to export spans to Honeycomb
47
- const honeyCombSpanProcessor = new SimpleSpanProcessor(honeycombExporter);
48
- // Set up a log record processor to export spans to OpenSearch
49
- const openSearchLogProcessor = new SimpleLogRecordProcessor(openSearchExporter);
50
- // Register the span processor with the tracer provider
51
- tracerProvider.addSpanProcessor(honeyCombSpanProcessor);
52
- // Register the log record processor with the log provider
53
- loggerProvider.addLogRecordProcessor(openSearchLogProcessor);
54
- if (telemetryOptions?.mode === 'verbose' ||
55
- telemetryOptions?.mode === 'dev') {
56
- // Set up a console exporter for verbose mode
57
- const consoleExporter = new ConsoleSpanExporter();
58
- const verboseTraceProcessor = new SimpleSpanProcessor(consoleExporter);
59
- // Set up processors for verbose mode
60
- const consoleLogExporter = new ConsoleLogRecordExporter();
61
- const veboseLogRecordExporter = new SimpleLogRecordProcessor(consoleLogExporter);
62
- tracerProvider.addSpanProcessor(verboseTraceProcessor);
63
- loggerProvider.addLogRecordProcessor(veboseLogRecordExporter);
64
- }
65
- const useFaststoreTelemetry = getFaststoreTelemetryPlugin(
66
- // The @opentelemetry/sdk-trace-base was renamed from @opentelemetry/tracing but the
67
- // envelop plugin doesn't support this change yet. This causes the class type to be incompatible,
68
- // even if they are the same. https://github.com/n1ru4l/envelop/issues/1610
69
- tracerProvider, loggerProvider, 'faststore-api', telemetryOptions?.experimentalSendLogs ?? false);
70
- return { useFaststoreTelemetry };
71
- }
72
- //# sourceMappingURL=index.js.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,CAAC,uBAAuB,CAAC,CAAA;IAC/D,CAAC;IAED,MAAM,qBAAqB,GAAG,2BAA2B;IACvD,oFAAoF;IACpF,iGAAiG;IACjG,2EAA2E;IAC3E,cAAqB,EACrB,cAAc,EACd,eAAe,EACf,gBAAgB,EAAE,oBAAoB,IAAI,KAAK,CAChD,CAAA;IAED,OAAO,EAAE,qBAAqB,EAAE,CAAA;AAClC,CAAC"}
@@ -1,24 +0,0 @@
1
- import type { Plugin } from '@envelop/core';
2
- import { type Span } from '@opentelemetry/api';
3
- import type { LoggerProvider } from '@opentelemetry/sdk-logs';
4
- import type { BasicTracerProvider } from '@opentelemetry/sdk-trace-base';
5
- export declare enum AttributeName {
6
- EXECUTION_ERROR = "graphql.error",
7
- EXECUTION_RESULT = "graphql.result",
8
- RESOLVER_EXECUTION_ERROR = "graphql.resolver.error",
9
- RESOLVER_EXCEPTION = "graphql.resolver.exception",
10
- RESOLVER_FIELD_NAME = "graphql.resolver.fieldName",
11
- RESOLVER_TYPE_NAME = "graphql.resolver.typeName",
12
- RESOLVER_RESULT_TYPE = "graphql.resolver.resultType",
13
- RESOLVER_ARGS = "graphql.resolver.args",
14
- EXECUTION_OPERATION_NAME = "graphql.operation.name",
15
- EXECUTION_OPERATION_TYPE = "graphql.operation.type",
16
- EXECUTION_OPERATION_DOCUMENT = "graphql.document",
17
- EXECUTION_VARIABLES = "graphql.variables"
18
- }
19
- declare const tracingSpanSymbol: unique symbol;
20
- export type PluginContext = {
21
- [tracingSpanSymbol]: Span;
22
- };
23
- export declare const getFaststoreTelemetryPlugin: (tracingProvider: BasicTracerProvider, loggerProvider: LoggerProvider, serviceName: string, experimentalSendLogs: boolean) => (() => Plugin<PluginContext>);
24
- export {};
@@ -1,166 +0,0 @@
1
- import { isAsyncIterable } from '@envelop/core';
2
- import { useOnResolve } from '@envelop/on-resolve';
3
- import { context as openTelContext, SpanKind, trace as openTelTrace, } from '@opentelemetry/api';
4
- import { SeverityNumber } from '@opentelemetry/api-logs';
5
- import { Kind, print, } from 'graphql';
6
- export var AttributeName;
7
- (function (AttributeName) {
8
- AttributeName["EXECUTION_ERROR"] = "graphql.error";
9
- AttributeName["EXECUTION_RESULT"] = "graphql.result";
10
- AttributeName["RESOLVER_EXECUTION_ERROR"] = "graphql.resolver.error";
11
- AttributeName["RESOLVER_EXCEPTION"] = "graphql.resolver.exception";
12
- AttributeName["RESOLVER_FIELD_NAME"] = "graphql.resolver.fieldName";
13
- AttributeName["RESOLVER_TYPE_NAME"] = "graphql.resolver.typeName";
14
- AttributeName["RESOLVER_RESULT_TYPE"] = "graphql.resolver.resultType";
15
- AttributeName["RESOLVER_ARGS"] = "graphql.resolver.args";
16
- AttributeName["EXECUTION_OPERATION_NAME"] = "graphql.operation.name";
17
- AttributeName["EXECUTION_OPERATION_TYPE"] = "graphql.operation.type";
18
- AttributeName["EXECUTION_OPERATION_DOCUMENT"] = "graphql.document";
19
- AttributeName["EXECUTION_VARIABLES"] = "graphql.variables";
20
- })(AttributeName || (AttributeName = {}));
21
- const tracingSpanSymbol = Symbol('OPEN_TELEMETRY_GRAPHQL');
22
- function getResolverSpanKey(path) {
23
- const nodes = [];
24
- // If the first node (after reversed, it will be the last one) is an integer, that is, identifies a list,
25
- // we don't want to include it in the key. Note that this will only happen when analysing .prev paths in
26
- // a list of elements. We just want to remove the initial node that is a integer, not all of them.
27
- //
28
- // Nodes with keys 6bc73341b2a183fc::product::image::0::url would not be able to find
29
- // parents with key 6bc73341b2a183fc::product::image because of the "0" list index -
30
- // it would search for 6bc73341b2a183fc::product::image::0
31
- let currentPath = nodes.length === 0 && Number.isInteger(path.key) ? path.prev : path;
32
- while (currentPath) {
33
- nodes.push(currentPath.key);
34
- currentPath = currentPath.prev;
35
- }
36
- return [...nodes].reverse().join('.');
37
- }
38
- export const getFaststoreTelemetryPlugin = (tracingProvider, loggerProvider, serviceName, experimentalSendLogs) => {
39
- return function useFaststoreTelemetry() {
40
- const tracer = tracingProvider.getTracer(serviceName);
41
- const logger = loggerProvider.getLogger(serviceName);
42
- const resolverContextsByRootSpans = {};
43
- return {
44
- onPluginInit({ addPlugin }) {
45
- addPlugin(useOnResolve(({ info, context }) => {
46
- if (context &&
47
- typeof context === 'object' &&
48
- context[tracingSpanSymbol]) {
49
- tracer.getActiveSpanProcessor();
50
- const rootContextSpanId = context[tracingSpanSymbol].spanContext().spanId;
51
- const { fieldName, returnType, parentType, path } = info;
52
- const previousResolverSpanKey = path.prev && getResolverSpanKey(path.prev);
53
- let ctx = null;
54
- if (previousResolverSpanKey &&
55
- resolverContextsByRootSpans[rootContextSpanId][previousResolverSpanKey]) {
56
- ctx =
57
- resolverContextsByRootSpans[rootContextSpanId][previousResolverSpanKey];
58
- }
59
- else {
60
- ctx = openTelTrace.setSpan(openTelContext.active(), context[tracingSpanSymbol]);
61
- resolverContextsByRootSpans[rootContextSpanId] =
62
- resolverContextsByRootSpans[rootContextSpanId] ?? {};
63
- }
64
- const resolverIndexInList = Number.isInteger(path.prev?.key)
65
- ? `[${path.prev?.key}]`
66
- : '';
67
- const resolverSpan = tracer.startSpan(`${parentType.toString()}.${fieldName}${resolverIndexInList}`, {
68
- attributes: {
69
- [AttributeName.RESOLVER_FIELD_NAME]: fieldName,
70
- [AttributeName.RESOLVER_TYPE_NAME]: parentType.toString(),
71
- [AttributeName.RESOLVER_RESULT_TYPE]: returnType.toString(),
72
- 'meta.span.path': getResolverSpanKey(path),
73
- },
74
- }, ctx);
75
- const resolverCtx = openTelTrace.setSpan(ctx, resolverSpan);
76
- resolverContextsByRootSpans[rootContextSpanId][getResolverSpanKey(path)] = resolverCtx;
77
- return ({ result }) => {
78
- if (result instanceof Error) {
79
- resolverSpan.setAttributes({
80
- error: true,
81
- 'exception.category': AttributeName.RESOLVER_EXECUTION_ERROR,
82
- 'exception.message': result.message,
83
- 'exception.type': result.name,
84
- });
85
- resolverSpan.recordException(result);
86
- }
87
- resolverSpan.end();
88
- };
89
- }
90
- return () => { };
91
- }));
92
- },
93
- onExecute({ args, extendContext }) {
94
- const operationType = args.document.definitions
95
- .filter((def) => def.kind === Kind.OPERATION_DEFINITION)
96
- .map((def) => def.operation)?.[0];
97
- // Span name according to Semantic Conventions
98
- // https://github.com/open-telemetry/semantic-conventions
99
- let spanName = 'GraphQL Operation';
100
- if (operationType && args.operationName) {
101
- spanName = `${operationType} ${args.operationName}`;
102
- }
103
- else if (operationType && !args.operationName) {
104
- spanName = operationType;
105
- }
106
- const executionSpan = tracer.startSpan(spanName, {
107
- kind: SpanKind.SERVER,
108
- attributes: {
109
- [AttributeName.EXECUTION_OPERATION_NAME]: args.operationName ?? undefined,
110
- [AttributeName.EXECUTION_OPERATION_TYPE]: operationType ?? undefined,
111
- [AttributeName.EXECUTION_OPERATION_DOCUMENT]: print(args.document),
112
- },
113
- });
114
- const executeContext = openTelContext.active();
115
- const resultCbs = {
116
- onExecuteDone({ result }) {
117
- if (isAsyncIterable(result)) {
118
- executionSpan.end();
119
- console.warn(`Plugin "newrelic" encountered a AsyncIterator which is not supported yet, so tracing data is not available for the operation.`);
120
- return;
121
- }
122
- const logRecord = {
123
- context: executeContext,
124
- attributes: {
125
- 'service.name': 'faststore-api',
126
- 'service.version': '1.12.38',
127
- 'service.name_and_version': 'faststore-api@1.12.38',
128
- 'vtex.search_index': 'faststore_beta_api',
129
- [AttributeName.EXECUTION_OPERATION_NAME]: args.operationName ?? undefined,
130
- [AttributeName.EXECUTION_OPERATION_DOCUMENT]: print(args.document),
131
- [AttributeName.EXECUTION_VARIABLES]: JSON.stringify(args.variableValues ?? {}),
132
- },
133
- };
134
- if (typeof result.data !== 'undefined' &&
135
- !(result.errors && result.errors.length > 0)) {
136
- logRecord.severityNumber = SeverityNumber.INFO;
137
- logRecord.severityText = 'Info';
138
- logRecord.attributes[AttributeName.EXECUTION_RESULT] =
139
- JSON.stringify(result);
140
- }
141
- if (result.errors && result.errors.length > 0) {
142
- logRecord.severityNumber = SeverityNumber.ERROR;
143
- logRecord.severityText = 'Error';
144
- logRecord.attributes[AttributeName.EXECUTION_ERROR] =
145
- JSON.stringify(result.errors);
146
- executionSpan.setAttributes({
147
- error: true,
148
- 'exception.category': AttributeName.EXECUTION_ERROR,
149
- 'exception.message': JSON.stringify(result.errors),
150
- });
151
- }
152
- if (experimentalSendLogs) {
153
- logger.emit(logRecord);
154
- }
155
- executionSpan.end();
156
- },
157
- };
158
- extendContext({
159
- [tracingSpanSymbol]: executionSpan,
160
- });
161
- return resultCbs;
162
- },
163
- };
164
- };
165
- };
166
- //# sourceMappingURL=useFaststoreTelemetry.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useFaststoreTelemetry.js","sourceRoot":"","sources":["../../../../src/telemetry/useFaststoreTelemetry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAEL,OAAO,IAAI,cAAc,EAEzB,QAAQ,EACR,KAAK,IAAI,YAAY,GACtB,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAGxD,OAAO,EACL,IAAI,EAEJ,KAAK,GAEN,MAAM,SAAS,CAAA;AAGhB,MAAM,CAAN,IAAY,aAaX;AAbD,WAAY,aAAa;IACvB,kDAAiC,CAAA;IACjC,oDAAmC,CAAA;IACnC,oEAAmD,CAAA;IACnD,kEAAiD,CAAA;IACjD,mEAAkD,CAAA;IAClD,iEAAgD,CAAA;IAChD,qEAAoD,CAAA;IACpD,wDAAuC,CAAA;IACvC,oEAAmD,CAAA;IACnD,oEAAmD,CAAA;IACnD,kEAAiD,CAAA;IACjD,0DAAyC,CAAA;AAC3C,CAAC,EAbW,aAAa,KAAb,aAAa,QAaxB;AAED,MAAM,iBAAiB,GAAG,MAAM,CAAC,wBAAwB,CAAC,CAAA;AAM1D,SAAS,kBAAkB,CAAC,IAAU;IACpC,MAAM,KAAK,GAAG,EAAE,CAAA;IAEhB,yG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MAAM,GAAG,CAAC,CAAC,EAC5C,CAAC;4BACD,SAAS,CAAC,cAAc,GAAG,cAAc,CAAC,IAAI,CAAA;4BAC9C,SAAS,CAAC,YAAY,GAAG,MAAM,CAAA;4BAC/B,SAAS,CAAC,UAAW,CAAC,aAAa,CAAC,gBAAgB,CAAC;gCACnD,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;wBAC1B,CAAC;wBAED,IAAI,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;4BAC9C,SAAS,CAAC,cAAc,GAAG,cAAc,CAAC,KAAK,CAAA;4BAC/C,SAAS,CAAC,YAAY,GAAG,OAAO,CAAA;4BAChC,SAAS,CAAC,UAAW,CAAC,aAAa,CAAC,eAAe,CAAC;gCAClD,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;4BAE/B,aAAa,CAAC,aAAa,CAAC;gCAC1B,KAAK,EAAE,IAAI;gCACX,oBAAoB,EAAE,aAAa,CAAC,eAAe;gCACnD,mBAAmB,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC;6BACnD,CAAC,CAAA;wBACJ,CAAC;wBAED,IAAI,oBAAoB,EAAE,CAAC;4BACzB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;wBACxB,CAAC;wBAED,aAAa,CAAC,GAAG,EAAE,CAAA;oBACrB,CAAC;iBACF,CAAA;gBAED,aAAa,CAAC;oBACZ,CAAC,iBAAiB,CAAC,EAAE,aAAa;iBACnC,CAAC,CAAA;gBAEF,OAAO,SAAS,CAAA;YAClB,CAAC;SACF,CAAA;IACH,CAAC,CAAA;AACH,CAAC,CAAA"}
@@ -1,117 +0,0 @@
1
- import {
2
- BasicTracerProvider,
3
- SimpleSpanProcessor,
4
- ConsoleSpanExporter,
5
- } from '@opentelemetry/sdk-trace-base'
6
- import { Resource } from '@opentelemetry/resources'
7
- import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc'
8
- import {
9
- LoggerProvider,
10
- SimpleLogRecordProcessor,
11
- ConsoleLogRecordExporter,
12
- } from '@opentelemetry/sdk-logs'
13
- import { OTLPLogsExporter } from '@opentelemetry/exporter-logs-otlp-grpc'
14
-
15
- import type { Options } from '../'
16
- import { getFaststoreTelemetryPlugin } from './useFaststoreTelemetry'
17
- import packageJson from '../../package.json'
18
-
19
- export type GetTelemetryOptions = {
20
- mode?: 'verbose' | 'dev'
21
- experimentalSendLogs?: boolean
22
- }
23
-
24
- const FASTSTORE_API_VERSION = packageJson.version
25
-
26
- // TODO: These urls are hardcoded for now, but they should be configurable via ENV variables
27
- // They are only acessible from within the VTEX network, so they are not a security risk
28
- const TRACE_COLLECTOR_URL = 'opentelemetry-collector.vtex.systems'
29
- const TRACE_COLLECTOR_URL_DEV = 'opentelemetry-collector-beta.vtex.systems'
30
- const LOG_COLLECTOR_URL = 'opentelemetry-collector.vtex.systems'
31
-
32
- export function getTelemetry(
33
- APIOptions: Options,
34
- telemetryOptions?: GetTelemetryOptions
35
- ) {
36
- const honeycombCollectorOptions = {
37
- url:
38
- telemetryOptions?.mode === 'dev'
39
- ? TRACE_COLLECTOR_URL_DEV
40
- : TRACE_COLLECTOR_URL,
41
- }
42
-
43
- const openSearchCollectorOptions = {
44
- url: LOG_COLLECTOR_URL,
45
- }
46
-
47
- // Create a new tracer provider
48
- const tracerProvider = new BasicTracerProvider({
49
- resource: new Resource({
50
- 'service.name': 'faststore-api',
51
- 'service.version': FASTSTORE_API_VERSION,
52
- 'service.name_and_version': `faststore-api@${FASTSTORE_API_VERSION}`,
53
- platform: APIOptions.platform,
54
- [`${APIOptions.platform}.account`]: APIOptions.account,
55
- [`${APIOptions.platform}.environment`]: APIOptions.environment,
56
- // TODO: include the following properties in the logs
57
- // [`${APIOptions.platform}.options.hideUnavailableItems`]:
58
- // APIOptions.hideUnavailableItems,
59
- // [`${APIOptions.platform}.flags.enableOrderFormSync`]:
60
- // APIOptions.flags?.enableOrderFormSync,
61
- // channel: APIOptions.channel,
62
- locale: APIOptions.locale,
63
- }),
64
- })
65
-
66
- const loggerProvider = new LoggerProvider()
67
-
68
- // Create trace exporter
69
- const honeycombExporter = new OTLPTraceExporter(honeycombCollectorOptions)
70
-
71
- // Create log exporter
72
- const openSearchExporter = new OTLPLogsExporter(openSearchCollectorOptions)
73
-
74
- // Set up a span processor to export spans to Honeycomb
75
- const honeyCombSpanProcessor = new SimpleSpanProcessor(honeycombExporter)
76
-
77
- // Set up a log record processor to export spans to OpenSearch
78
- const openSearchLogProcessor = new SimpleLogRecordProcessor(
79
- openSearchExporter
80
- )
81
-
82
- // Register the span processor with the tracer provider
83
- tracerProvider.addSpanProcessor(honeyCombSpanProcessor)
84
-
85
- // Register the log record processor with the log provider
86
- loggerProvider.addLogRecordProcessor(openSearchLogProcessor)
87
-
88
- if (
89
- telemetryOptions?.mode === 'verbose' ||
90
- telemetryOptions?.mode === 'dev'
91
- ) {
92
- // Set up a console exporter for verbose mode
93
- const consoleExporter = new ConsoleSpanExporter()
94
- const verboseTraceProcessor = new SimpleSpanProcessor(consoleExporter)
95
-
96
- // Set up processors for verbose mode
97
- const consoleLogExporter = new ConsoleLogRecordExporter()
98
- const veboseLogRecordExporter = new SimpleLogRecordProcessor(
99
- consoleLogExporter
100
- )
101
-
102
- tracerProvider.addSpanProcessor(verboseTraceProcessor)
103
- loggerProvider.addLogRecordProcessor(veboseLogRecordExporter)
104
- }
105
-
106
- const useFaststoreTelemetry = getFaststoreTelemetryPlugin(
107
- // The @opentelemetry/sdk-trace-base was renamed from @opentelemetry/tracing but the
108
- // envelop plugin doesn't support this change yet. This causes the class type to be incompatible,
109
- // even if they are the same. https://github.com/n1ru4l/envelop/issues/1610
110
- tracerProvider as any,
111
- loggerProvider,
112
- 'faststore-api',
113
- telemetryOptions?.experimentalSendLogs ?? false
114
- )
115
-
116
- return { useFaststoreTelemetry }
117
- }
@@ -1,264 +0,0 @@
1
- import type { OnExecuteHookResult, Plugin } from '@envelop/core'
2
- import { isAsyncIterable } from '@envelop/core'
3
- import { useOnResolve } from '@envelop/on-resolve'
4
- import {
5
- type Context,
6
- context as openTelContext,
7
- type Span,
8
- SpanKind,
9
- trace as openTelTrace,
10
- } from '@opentelemetry/api'
11
- import type { LogRecord } from '@opentelemetry/api-logs'
12
- import { SeverityNumber } from '@opentelemetry/api-logs'
13
- import type { LoggerProvider } from '@opentelemetry/sdk-logs'
14
- import type { BasicTracerProvider } from '@opentelemetry/sdk-trace-base'
15
- import {
16
- Kind,
17
- type OperationDefinitionNode,
18
- print,
19
- type DefinitionNode,
20
- } from 'graphql'
21
- import type { Path } from 'graphql/jsutils/Path'
22
-
23
- export enum AttributeName {
24
- EXECUTION_ERROR = 'graphql.error',
25
- EXECUTION_RESULT = 'graphql.result',
26
- RESOLVER_EXECUTION_ERROR = 'graphql.resolver.error',
27
- RESOLVER_EXCEPTION = 'graphql.resolver.exception',
28
- RESOLVER_FIELD_NAME = 'graphql.resolver.fieldName',
29
- RESOLVER_TYPE_NAME = 'graphql.resolver.typeName',
30
- RESOLVER_RESULT_TYPE = 'graphql.resolver.resultType',
31
- RESOLVER_ARGS = 'graphql.resolver.args',
32
- EXECUTION_OPERATION_NAME = 'graphql.operation.name',
33
- EXECUTION_OPERATION_TYPE = 'graphql.operation.type',
34
- EXECUTION_OPERATION_DOCUMENT = 'graphql.document',
35
- EXECUTION_VARIABLES = 'graphql.variables',
36
- }
37
-
38
- const tracingSpanSymbol = Symbol('OPEN_TELEMETRY_GRAPHQL')
39
-
40
- export type PluginContext = {
41
- [tracingSpanSymbol]: Span
42
- }
43
-
44
- function getResolverSpanKey(path: Path) {
45
- const nodes = []
46
-
47
- // If the first node (after reversed, it will be the last one) is an integer, that is, identifies a list,
48
- // we don't want to include it in the key. Note that this will only happen when analysing .prev paths in
49
- // a list of elements. We just want to remove the initial node that is a integer, not all of them.
50
- //
51
- // Nodes with keys 6bc73341b2a183fc::product::image::0::url would not be able to find
52
- // parents with key 6bc73341b2a183fc::product::image because of the "0" list index -
53
- // it would search for 6bc73341b2a183fc::product::image::0
54
- let currentPath: Path | undefined =
55
- nodes.length === 0 && Number.isInteger(path.key) ? path.prev : path
56
-
57
- while (currentPath) {
58
- nodes.push(currentPath.key)
59
-
60
- currentPath = currentPath.prev
61
- }
62
-
63
- return [...nodes].reverse().join('.')
64
- }
65
-
66
- export const getFaststoreTelemetryPlugin = (
67
- tracingProvider: BasicTracerProvider,
68
- loggerProvider: LoggerProvider,
69
- serviceName: string,
70
- experimentalSendLogs: boolean
71
- ): (() => Plugin<PluginContext>) => {
72
- return function useFaststoreTelemetry() {
73
- const tracer = tracingProvider.getTracer(serviceName)
74
- const logger = loggerProvider.getLogger(serviceName)
75
-
76
- const resolverContextsByRootSpans: Record<
77
- string,
78
- Record<string, Context>
79
- > = {}
80
-
81
- return {
82
- onPluginInit({ addPlugin }) {
83
- addPlugin(
84
- useOnResolve(({ info, context }) => {
85
- if (
86
- context &&
87
- typeof context === 'object' &&
88
- context[tracingSpanSymbol]
89
- ) {
90
- tracer.getActiveSpanProcessor()
91
- const rootContextSpanId =
92
- context[tracingSpanSymbol].spanContext().spanId
93
-
94
- const { fieldName, returnType, parentType, path } = info
95
-
96
- const previousResolverSpanKey =
97
- path.prev && getResolverSpanKey(path.prev)
98
-
99
- let ctx: Context | null = null
100
-
101
- if (
102
- previousResolverSpanKey &&
103
- resolverContextsByRootSpans[rootContextSpanId][
104
- previousResolverSpanKey
105
- ]
106
- ) {
107
- ctx =
108
- resolverContextsByRootSpans[rootContextSpanId][
109
- previousResolverSpanKey
110
- ]
111
- } else {
112
- ctx = openTelTrace.setSpan(
113
- openTelContext.active(),
114
- context[tracingSpanSymbol]
115
- )
116
-
117
- resolverContextsByRootSpans[rootContextSpanId] =
118
- resolverContextsByRootSpans[rootContextSpanId] ?? {}
119
- }
120
-
121
- const resolverIndexInList = Number.isInteger(path.prev?.key)
122
- ? `[${path.prev?.key}]`
123
- : ''
124
-
125
- const resolverSpan = tracer.startSpan(
126
- `${parentType.toString()}.${fieldName}${resolverIndexInList}`,
127
- {
128
- attributes: {
129
- [AttributeName.RESOLVER_FIELD_NAME]: fieldName,
130
- [AttributeName.RESOLVER_TYPE_NAME]: parentType.toString(),
131
- [AttributeName.RESOLVER_RESULT_TYPE]: returnType.toString(),
132
- 'meta.span.path': getResolverSpanKey(path),
133
- },
134
- },
135
- ctx
136
- )
137
-
138
- const resolverCtx = openTelTrace.setSpan(ctx, resolverSpan)
139
-
140
- resolverContextsByRootSpans[rootContextSpanId][
141
- getResolverSpanKey(path)
142
- ] = resolverCtx
143
-
144
- return ({ result }) => {
145
- if (result instanceof Error) {
146
- resolverSpan.setAttributes({
147
- error: true,
148
- 'exception.category':
149
- AttributeName.RESOLVER_EXECUTION_ERROR,
150
- 'exception.message': result.message,
151
- 'exception.type': result.name,
152
- })
153
- resolverSpan.recordException(result)
154
- }
155
-
156
- resolverSpan.end()
157
- }
158
- }
159
-
160
- return () => {}
161
- })
162
- )
163
- },
164
- onExecute({ args, extendContext }) {
165
- const operationType = args.document.definitions
166
- .filter(
167
- (def: DefinitionNode) => def.kind === Kind.OPERATION_DEFINITION
168
- )
169
- .map(
170
- (def: DefinitionNode) => (def as OperationDefinitionNode).operation
171
- )?.[0]
172
-
173
- // Span name according to Semantic Conventions
174
- // https://github.com/open-telemetry/semantic-conventions
175
- let spanName = 'GraphQL Operation'
176
-
177
- if (operationType && args.operationName) {
178
- spanName = `${operationType} ${args.operationName}`
179
- } else if (operationType && !args.operationName) {
180
- spanName = operationType
181
- }
182
-
183
- const executionSpan = tracer.startSpan(spanName, {
184
- kind: SpanKind.SERVER,
185
- attributes: {
186
- [AttributeName.EXECUTION_OPERATION_NAME]:
187
- args.operationName ?? undefined,
188
- [AttributeName.EXECUTION_OPERATION_TYPE]:
189
- operationType ?? undefined,
190
- [AttributeName.EXECUTION_OPERATION_DOCUMENT]: print(args.document),
191
- },
192
- })
193
-
194
- const executeContext = openTelContext.active()
195
-
196
- const resultCbs: OnExecuteHookResult<PluginContext> = {
197
- onExecuteDone({ result }) {
198
- if (isAsyncIterable(result)) {
199
- executionSpan.end()
200
- console.warn(
201
- `Plugin "newrelic" encountered a AsyncIterator which is not supported yet, so tracing data is not available for the operation.`
202
- )
203
-
204
- return
205
- }
206
-
207
- const logRecord: LogRecord = {
208
- context: executeContext,
209
- attributes: {
210
- 'service.name': 'faststore-api',
211
- 'service.version': '1.12.38',
212
- 'service.name_and_version': 'faststore-api@1.12.38',
213
- 'vtex.search_index': 'faststore_beta_api',
214
- [AttributeName.EXECUTION_OPERATION_NAME]:
215
- args.operationName ?? undefined,
216
- [AttributeName.EXECUTION_OPERATION_DOCUMENT]: print(
217
- args.document
218
- ),
219
- [AttributeName.EXECUTION_VARIABLES]: JSON.stringify(
220
- args.variableValues ?? {}
221
- ),
222
- },
223
- }
224
-
225
- if (
226
- typeof result.data !== 'undefined' &&
227
- !(result.errors && result.errors.length > 0)
228
- ) {
229
- logRecord.severityNumber = SeverityNumber.INFO
230
- logRecord.severityText = 'Info'
231
- logRecord.attributes![AttributeName.EXECUTION_RESULT] =
232
- JSON.stringify(result)
233
- }
234
-
235
- if (result.errors && result.errors.length > 0) {
236
- logRecord.severityNumber = SeverityNumber.ERROR
237
- logRecord.severityText = 'Error'
238
- logRecord.attributes![AttributeName.EXECUTION_ERROR] =
239
- JSON.stringify(result.errors)
240
-
241
- executionSpan.setAttributes({
242
- error: true,
243
- 'exception.category': AttributeName.EXECUTION_ERROR,
244
- 'exception.message': JSON.stringify(result.errors),
245
- })
246
- }
247
-
248
- if (experimentalSendLogs) {
249
- logger.emit(logRecord)
250
- }
251
-
252
- executionSpan.end()
253
- },
254
- }
255
-
256
- extendContext({
257
- [tracingSpanSymbol]: executionSpan,
258
- })
259
-
260
- return resultCbs
261
- },
262
- }
263
- }
264
- }