@faststore/api 3.33.3 → 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,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,kEA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gBAEF,OAAO,SAAS,CAAA;YAClB,CAAC;SACF,CAAA;IACH,CAAC,CAAA;AACH,CAAC,CAAA;AAtMY,QAAA,2BAA2B,+BAsMvC"}
@@ -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,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.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/telemetry/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAA;AAC3E,OAAO,EACL,cAAc,EACd,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAA;AAGzE,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAA;AACrE,OAAO,WAAW,MAAM,oBAAoB,CAAA;AAO5C,MAAM,qBAAqB,GAAG,WAAW,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,MAAM,UAAU,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,mBAAmB,CAAC;QAC7C,QAAQ,E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AM,kBAAkB,GAAG,IAAI,wBAAwB,EAAE,CAAA;QACzD,MAAM,uBAAuB,GAAG,IAAI,wBAAwB,CAC1D,kBAAkB,CACnB,CAAA;QAED,cAAc,CAAC,gBAAgB,CAAC,qBAAqB,CAAC,CAAA;QACtD,cAAc,CAAC,qBAAqB,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,0DAAy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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
- }