@graphql-hive/plugin-opentelemetry 1.0.0-alpha-2cea6e8a62aea3e45963d47c35cb6db588d78c54

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/setup.cjs ADDED
@@ -0,0 +1,387 @@
1
+ 'use strict';
2
+
3
+ var api = require('@opentelemetry/api');
4
+ var core = require('@opentelemetry/core');
5
+ var resources = require('@opentelemetry/resources');
6
+ var sdkTraceBase = require('@opentelemetry/sdk-trace-base');
7
+ var semanticConventions = require('@opentelemetry/semantic-conventions');
8
+ var plugin = require('./plugin-BT_oWPcx.cjs');
9
+ var exporterTraceOtlpHttp = require('@opentelemetry/exporter-trace-otlp-http');
10
+ var apiLogs = require('@opentelemetry/api-logs');
11
+ var sdkLogs = require('@opentelemetry/sdk-logs');
12
+ require('@graphql-hive/gateway-runtime');
13
+ require('@graphql-mesh/utils');
14
+ require('@graphql-tools/utils');
15
+ require('@whatwg-node/promise-helpers');
16
+ require('./api.cjs');
17
+ require('@graphql-hive/core');
18
+ require('@graphql-mesh/transport-common');
19
+ require('graphql');
20
+
21
+ class HiveTracingSpanProcessor {
22
+ traceStateById = /* @__PURE__ */ new Map();
23
+ processor;
24
+ constructor(config) {
25
+ if (config.processor) {
26
+ this.processor = config.processor;
27
+ } else {
28
+ this.processor = new sdkTraceBase.BatchSpanProcessor(
29
+ new exporterTraceOtlpHttp.OTLPTraceExporter({
30
+ url: config.endpoint,
31
+ headers: {
32
+ Authorization: `Bearer ${config.accessToken}`,
33
+ "X-Hive-Target-Ref": config.target
34
+ }
35
+ }),
36
+ config.batching
37
+ );
38
+ }
39
+ }
40
+ onStart(span, parentContext) {
41
+ this.processor.onStart(span, parentContext);
42
+ const { spanId, traceId } = span.spanContext();
43
+ const parentId = span.parentSpanContext?.spanId;
44
+ if (isHttpSpan(span)) {
45
+ this.traceStateById.set(traceId, {
46
+ traceId,
47
+ rootId: spanId,
48
+ httpSpan: span,
49
+ operationRoots: /* @__PURE__ */ new Map(),
50
+ subgraphExecutions: /* @__PURE__ */ new Map()
51
+ });
52
+ return;
53
+ }
54
+ const traceState = this.traceStateById.get(traceId);
55
+ if (!traceState || !parentId) {
56
+ return;
57
+ }
58
+ if (span.name.startsWith("graphql.operation")) {
59
+ traceState?.operationRoots.set(spanId, span);
60
+ return;
61
+ }
62
+ const operationRoot = traceState.operationRoots.get(parentId);
63
+ if (operationRoot) {
64
+ traceState.operationRoots.set(spanId, operationRoot);
65
+ }
66
+ if (span.name.startsWith("subgraph.execute")) {
67
+ traceState.subgraphExecutions.set(spanId, span);
68
+ return;
69
+ }
70
+ const subgraphExecution = traceState.subgraphExecutions.get(parentId);
71
+ if (subgraphExecution) {
72
+ traceState.subgraphExecutions.set(spanId, subgraphExecution);
73
+ }
74
+ }
75
+ onEnd(span) {
76
+ const { traceId, spanId } = span.spanContext();
77
+ const traceState = this.traceStateById.get(traceId);
78
+ if (!traceState) {
79
+ return;
80
+ }
81
+ if (traceState.rootId === spanId) {
82
+ this.traceStateById.delete(traceId);
83
+ for (let operationSpan2 of new Set(traceState.operationRoots.values())) {
84
+ operationSpan2.startTime = span.startTime;
85
+ operationSpan2.endTime = span.endTime;
86
+ operationSpan2._duration = core.hrTimeDuration(
87
+ operationSpan2.startTime,
88
+ operationSpan2.endTime
89
+ );
90
+ operationSpan2.parentSpanContext = null;
91
+ for (const attr in span.attributes) {
92
+ operationSpan2.attributes[attr] ??= span.attributes[attr];
93
+ }
94
+ this.processor.onEnd(operationSpan2);
95
+ }
96
+ return;
97
+ }
98
+ const operationSpan = traceState.operationRoots.get(spanId);
99
+ if (!operationSpan) {
100
+ return;
101
+ }
102
+ if (operationSpan === span) {
103
+ return;
104
+ }
105
+ if (span.name === "graphql.execute") {
106
+ copyAttribute(span, operationSpan, plugin.SEMATTRS_HIVE_GRAPHQL_ERROR_CODES);
107
+ copyAttribute(span, operationSpan, plugin.SEMATTRS_HIVE_GRAPHQL_ERROR_COUNT);
108
+ copyAttribute(
109
+ span,
110
+ operationSpan,
111
+ plugin.SEMATTRS_HIVE_GATEWAY_OPERATION_SUBGRAPH_NAMES
112
+ );
113
+ }
114
+ const subgraphExecution = traceState.subgraphExecutions.get(spanId);
115
+ if (span.name === "http.fetch" && subgraphExecution) {
116
+ for (const attr in span.attributes) {
117
+ subgraphExecution.attributes[attr] ??= span.attributes[attr];
118
+ }
119
+ }
120
+ this.processor.onEnd(span);
121
+ }
122
+ async forceFlush() {
123
+ return this.processor.forceFlush();
124
+ }
125
+ async shutdown() {
126
+ await this.forceFlush();
127
+ this.traceStateById.clear();
128
+ return this.processor.shutdown();
129
+ }
130
+ }
131
+ function isHttpSpan(span) {
132
+ return !!span.attributes[semanticConventions.SEMATTRS_HTTP_METHOD];
133
+ }
134
+ function copyAttribute(source, target, sourceAttrName, targetAttrName = sourceAttrName) {
135
+ target.attributes[targetAttrName] = source.attributes[sourceAttrName];
136
+ }
137
+
138
+ class OpenTelemetryLogWriter {
139
+ logger;
140
+ useContextManager;
141
+ constructor(options) {
142
+ this.useContextManager = options.useContextManager ?? true;
143
+ if ("logger" in options) {
144
+ this.logger = options.logger;
145
+ return;
146
+ }
147
+ if ("provider" in options) {
148
+ if ("register" in options.provider && typeof options.provider.register === "function") {
149
+ options.provider.register();
150
+ } else {
151
+ apiLogs.logs.setGlobalLoggerProvider(options.provider);
152
+ }
153
+ } else {
154
+ const processors = options.processors ?? [];
155
+ if (options.exporter) {
156
+ if (options.batching !== false) {
157
+ processors.push(
158
+ new sdkLogs.BatchLogRecordProcessor(
159
+ options.exporter,
160
+ options.batching === true ? {} : options.batching
161
+ )
162
+ );
163
+ }
164
+ processors.push(new sdkLogs.SimpleLogRecordProcessor(options.exporter));
165
+ }
166
+ if (options.console) {
167
+ processors.push(
168
+ new sdkLogs.SimpleLogRecordProcessor(new sdkLogs.ConsoleLogRecordExporter())
169
+ );
170
+ }
171
+ apiLogs.logs.setGlobalLoggerProvider(
172
+ new sdkLogs.LoggerProvider({
173
+ ...options,
174
+ processors
175
+ })
176
+ );
177
+ }
178
+ this.logger = apiLogs.logs.getLogger("gateway");
179
+ }
180
+ flush() {
181
+ const provider = apiLogs.logs.getLoggerProvider();
182
+ if ("forceFlush" in provider && typeof provider.forceFlush === "function") {
183
+ provider.forceFlush();
184
+ }
185
+ }
186
+ write(level, attrs, msg) {
187
+ const attributes = Array.isArray(attrs) ? { ...attrs } : attrs ?? void 0;
188
+ return this.logger.emit({
189
+ body: msg,
190
+ attributes,
191
+ severityNumber: HIVE_LOG_LEVEL_NUMBERS[level],
192
+ severityText: level,
193
+ context: this.useContextManager ? api.context.active() : getContextForRequest(attributes)
194
+ });
195
+ }
196
+ }
197
+ const HIVE_LOG_LEVEL_NUMBERS = {
198
+ trace: apiLogs.SeverityNumber.TRACE,
199
+ debug: apiLogs.SeverityNumber.DEBUG,
200
+ info: apiLogs.SeverityNumber.INFO,
201
+ warn: apiLogs.SeverityNumber.WARN,
202
+ error: apiLogs.SeverityNumber.ERROR
203
+ };
204
+ function getContextForRequest(attributes) {
205
+ if (!attributes?.requestId) {
206
+ return api.ROOT_CONTEXT;
207
+ }
208
+ return plugin.otelCtxForRequestId.get(attributes.requestId) ?? api.ROOT_CONTEXT;
209
+ }
210
+
211
+ globalThis.__OTEL_PLUGIN_VERSION__ = '1.0.0-alpha-2cea6e8a62aea3e45963d47c35cb6db588d78c54';
212
+ function openTelemetrySetup(options) {
213
+ const log = options.log?.child("[OpenTelemetry] ");
214
+ if (plugin.getEnvBool("OTEL_SDK_DISABLED")) {
215
+ log?.warn(
216
+ "OpenTelemetry integration is disabled because `OTEL_SDK_DISABLED` environment variable is truthy"
217
+ );
218
+ return;
219
+ }
220
+ const logAttributes = { registrationResults: {} };
221
+ let logMessage = "OpenTelemetry integration is enabled";
222
+ if (options.traces) {
223
+ if (options.traces.tracerProvider) {
224
+ if ("register" in options.traces.tracerProvider && typeof options.traces.tracerProvider.register === "function") {
225
+ logAttributes["registrationResults"].tracer = options.traces.tracerProvider.register();
226
+ } else {
227
+ logAttributes["registrationResults"].tracer = api.trace.setGlobalTracerProvider(options.traces.tracerProvider);
228
+ }
229
+ logMessage += " and provided TracerProvider has been registered";
230
+ } else {
231
+ let spanProcessors = options.traces.processors ?? [];
232
+ if (options.traces.exporter) {
233
+ spanProcessors.push(
234
+ resolveBatchingConfig(
235
+ options.traces.exporter,
236
+ options.traces.batching
237
+ )
238
+ );
239
+ logMessage += " and exporter have been registered";
240
+ logAttributes["batching"] = options.traces.batching ?? true;
241
+ }
242
+ if (options.traces.console) {
243
+ spanProcessors.push(new sdkTraceBase.SimpleSpanProcessor(new sdkTraceBase.ConsoleSpanExporter()));
244
+ logMessage += " in addition to an stdout debug exporter";
245
+ logAttributes["console"] = true;
246
+ }
247
+ const baseResource = resources.resourceFromAttributes({
248
+ [semanticConventions.ATTR_SERVICE_NAME]: options.resource && "serviceName" in options.resource ? options.resource?.serviceName : plugin.getEnvStr("OTEL_SERVICE_NAME") || "@graphql-hive/plugin-opentelemetry",
249
+ [semanticConventions.ATTR_SERVICE_VERSION]: options.resource && "serviceVersion" in options.resource ? options.resource?.serviceVersion : plugin.getEnvStr("OTEL_SERVICE_VERSION") || globalThis.__OTEL_PLUGIN_VERSION__ || "unknown",
250
+ ["hive.gateway.version"]: globalThis.__VERSION__,
251
+ ["hive.otel.version"]: globalThis.__OTEL_PLUGIN_VERSION__ || "unknown"
252
+ });
253
+ const resource = options.resource && !("serviceName" in options.resource) ? baseResource.merge(options.resource) : baseResource;
254
+ logAttributes["resource"] = resource.attributes;
255
+ logAttributes["sampling"] = options.sampler ? "custom" : options.samplingRate;
256
+ logAttributes["registrationResults"].tracerProvider = api.trace.setGlobalTracerProvider(
257
+ new sdkTraceBase.BasicTracerProvider({
258
+ resource,
259
+ sampler: options.sampler ?? (options.samplingRate ? new sdkTraceBase.ParentBasedSampler({
260
+ root: new sdkTraceBase.TraceIdRatioBasedSampler(options.samplingRate)
261
+ }) : new sdkTraceBase.AlwaysOnSampler()),
262
+ spanProcessors,
263
+ generalLimits: options.generalLimits,
264
+ spanLimits: options.traces.spanLimits
265
+ })
266
+ );
267
+ }
268
+ }
269
+ if (options.contextManager !== null) {
270
+ logAttributes["registrationResults"].contextManager = api.context.setGlobalContextManager(options.contextManager);
271
+ }
272
+ if (!options.propagators || options.propagators.length !== 0) {
273
+ const propagators = options.propagators ?? [
274
+ new core.W3CBaggagePropagator(),
275
+ new core.W3CTraceContextPropagator()
276
+ ];
277
+ logAttributes["registrationResults"].propagators = api.propagation.setGlobalPropagator(
278
+ propagators.length === 1 ? propagators[0] : new core.CompositePropagator({ propagators })
279
+ );
280
+ }
281
+ log?.info(logAttributes, logMessage);
282
+ }
283
+ function hiveTracingSetup(config) {
284
+ const log = config.log?.child("[OpenTelemetry] ");
285
+ config.target ??= plugin.getEnvStr("HIVE_TARGET");
286
+ if (!config.target) {
287
+ throw new Error(
288
+ "You must specify the Hive Registry `target`. Either provide `target` option or `HIVE_TARGET` environment variable."
289
+ );
290
+ }
291
+ const logAttributes = { target: config.target };
292
+ if (!config.processor) {
293
+ config.accessToken ??= plugin.getEnvStr("HIVE_TRACING_ACCESS_TOKEN") ?? plugin.getEnvStr("HIVE_ACCESS_TOKEN");
294
+ if (!config.accessToken) {
295
+ throw new Error(
296
+ "You must specify the Hive Registry `accessToken`. Either provide `accessToken` option or `HIVE_ACCESS_TOKEN`/`HIVE_TRACE_ACCESS_TOKEN` environment variable."
297
+ );
298
+ }
299
+ logAttributes["endpoint"] = config.endpoint;
300
+ logAttributes["batching"] = config.batching;
301
+ }
302
+ openTelemetrySetup({
303
+ contextManager: config.contextManager,
304
+ resource: resources.resourceFromAttributes({
305
+ "hive.target_id": config.target
306
+ }),
307
+ traces: {
308
+ processors: [
309
+ new HiveTracingSpanProcessor(config)
310
+ ]
311
+ }
312
+ });
313
+ log?.info(logAttributes, "Hive Tracing integration has been enabled");
314
+ }
315
+ function resolveBatchingConfig(exporter, batchingConfig) {
316
+ const value = batchingConfig ?? true;
317
+ if (value === true) {
318
+ return new sdkTraceBase.BatchSpanProcessor(exporter);
319
+ } else if (value === false) {
320
+ return new sdkTraceBase.SimpleSpanProcessor(exporter);
321
+ } else {
322
+ return new sdkTraceBase.BatchSpanProcessor(exporter, value);
323
+ }
324
+ }
325
+
326
+ Object.defineProperty(exports, "ATTR_SERVICE_NAME", {
327
+ enumerable: true,
328
+ get: function () { return semanticConventions.ATTR_SERVICE_NAME; }
329
+ });
330
+ Object.defineProperty(exports, "ATTR_SERVICE_VERSION", {
331
+ enumerable: true,
332
+ get: function () { return semanticConventions.ATTR_SERVICE_VERSION; }
333
+ });
334
+ Object.defineProperty(exports, "SEMATTRS_HTTP_CLIENT_IP", {
335
+ enumerable: true,
336
+ get: function () { return semanticConventions.SEMATTRS_HTTP_CLIENT_IP; }
337
+ });
338
+ Object.defineProperty(exports, "SEMATTRS_HTTP_HOST", {
339
+ enumerable: true,
340
+ get: function () { return semanticConventions.SEMATTRS_HTTP_HOST; }
341
+ });
342
+ Object.defineProperty(exports, "SEMATTRS_HTTP_METHOD", {
343
+ enumerable: true,
344
+ get: function () { return semanticConventions.SEMATTRS_HTTP_METHOD; }
345
+ });
346
+ Object.defineProperty(exports, "SEMATTRS_HTTP_ROUTE", {
347
+ enumerable: true,
348
+ get: function () { return semanticConventions.SEMATTRS_HTTP_ROUTE; }
349
+ });
350
+ Object.defineProperty(exports, "SEMATTRS_HTTP_SCHEME", {
351
+ enumerable: true,
352
+ get: function () { return semanticConventions.SEMATTRS_HTTP_SCHEME; }
353
+ });
354
+ Object.defineProperty(exports, "SEMATTRS_HTTP_SERVER_NAME", {
355
+ enumerable: true,
356
+ get: function () { return semanticConventions.SEMATTRS_HTTP_SERVER_NAME; }
357
+ });
358
+ Object.defineProperty(exports, "SEMATTRS_HTTP_STATUS_CODE", {
359
+ enumerable: true,
360
+ get: function () { return semanticConventions.SEMATTRS_HTTP_STATUS_CODE; }
361
+ });
362
+ Object.defineProperty(exports, "SEMATTRS_HTTP_URL", {
363
+ enumerable: true,
364
+ get: function () { return semanticConventions.SEMATTRS_HTTP_URL; }
365
+ });
366
+ Object.defineProperty(exports, "SEMATTRS_HTTP_USER_AGENT", {
367
+ enumerable: true,
368
+ get: function () { return semanticConventions.SEMATTRS_HTTP_USER_AGENT; }
369
+ });
370
+ Object.defineProperty(exports, "SEMATTRS_NET_HOST_NAME", {
371
+ enumerable: true,
372
+ get: function () { return semanticConventions.SEMATTRS_NET_HOST_NAME; }
373
+ });
374
+ exports.SEMATTRS_GRAPHQL_DOCUMENT = plugin.SEMATTRS_GRAPHQL_DOCUMENT;
375
+ exports.SEMATTRS_GRAPHQL_OPERATION_NAME = plugin.SEMATTRS_GRAPHQL_OPERATION_NAME;
376
+ exports.SEMATTRS_GRAPHQL_OPERATION_TYPE = plugin.SEMATTRS_GRAPHQL_OPERATION_TYPE;
377
+ exports.SEMATTRS_HIVE_GATEWAY_OPERATION_SUBGRAPH_NAMES = plugin.SEMATTRS_HIVE_GATEWAY_OPERATION_SUBGRAPH_NAMES;
378
+ exports.SEMATTRS_HIVE_GATEWAY_UPSTREAM_SUBGRAPH_NAME = plugin.SEMATTRS_HIVE_GATEWAY_UPSTREAM_SUBGRAPH_NAME;
379
+ exports.SEMATTRS_HIVE_GRAPHQL_ERROR_CODES = plugin.SEMATTRS_HIVE_GRAPHQL_ERROR_CODES;
380
+ exports.SEMATTRS_HIVE_GRAPHQL_ERROR_COUNT = plugin.SEMATTRS_HIVE_GRAPHQL_ERROR_COUNT;
381
+ exports.SEMATTRS_HIVE_GRAPHQL_OPERATION_HASH = plugin.SEMATTRS_HIVE_GRAPHQL_OPERATION_HASH;
382
+ exports.HIVE_LOG_LEVEL_NUMBERS = HIVE_LOG_LEVEL_NUMBERS;
383
+ exports.HiveTracingSpanProcessor = HiveTracingSpanProcessor;
384
+ exports.OpenTelemetryLogWriter = OpenTelemetryLogWriter;
385
+ exports.getContextForRequest = getContextForRequest;
386
+ exports.hiveTracingSetup = hiveTracingSetup;
387
+ exports.openTelemetrySetup = openTelemetrySetup;
@@ -0,0 +1,128 @@
1
+ import { LogWriter, LogLevel, Attributes, Logger as Logger$1 } from '@graphql-hive/logger';
2
+ import { Context, TracerProvider, ContextManager, TextMapPropagator } from '@opentelemetry/api';
3
+ import { Resource } from '@opentelemetry/resources';
4
+ import { BufferConfig, SpanProcessor, Span, SpanLimits, SpanExporter, Sampler, GeneralLimits } from '@opentelemetry/sdk-trace-base';
5
+ export { S as SEMATTRS_GRAPHQL_DOCUMENT, b as SEMATTRS_GRAPHQL_OPERATION_NAME, a as SEMATTRS_GRAPHQL_OPERATION_TYPE, g as SEMATTRS_HIVE_GATEWAY_OPERATION_SUBGRAPH_NAMES, f as SEMATTRS_HIVE_GATEWAY_UPSTREAM_SUBGRAPH_NAME, e as SEMATTRS_HIVE_GRAPHQL_ERROR_CODES, d as SEMATTRS_HIVE_GRAPHQL_ERROR_COUNT, c as SEMATTRS_HIVE_GRAPHQL_OPERATION_HASH } from './attributes-mikIPKnv.js';
6
+ import { Logger, SeverityNumber } from '@opentelemetry/api-logs';
7
+ import { LoggerProvider, LogRecordLimits, LogRecordProcessor, LogRecordExporter } from '@opentelemetry/sdk-logs';
8
+ export { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION, SEMATTRS_HTTP_CLIENT_IP, SEMATTRS_HTTP_HOST, SEMATTRS_HTTP_METHOD, SEMATTRS_HTTP_ROUTE, SEMATTRS_HTTP_SCHEME, SEMATTRS_HTTP_SERVER_NAME, SEMATTRS_HTTP_STATUS_CODE, SEMATTRS_HTTP_URL, SEMATTRS_HTTP_USER_AGENT, SEMATTRS_NET_HOST_NAME } from '@opentelemetry/semantic-conventions';
9
+
10
+ type ProcessorOptions = {
11
+ forceFlushTimeoutMillis?: number;
12
+ logRecordLimits?: LogRecordLimits;
13
+ resource?: Resource;
14
+ console?: boolean;
15
+ };
16
+ type OpenTelemetryLogWriterSetupOptions = {
17
+ logger: Logger;
18
+ } | {
19
+ provider: LoggerProvider;
20
+ } | (ProcessorOptions & ({
21
+ processors: LogRecordProcessor[];
22
+ exporter?: never;
23
+ } | {
24
+ exporter: LogRecordExporter;
25
+ batching?: boolean | BufferConfig;
26
+ processors?: never;
27
+ } | {
28
+ console: boolean;
29
+ processors?: never;
30
+ exporter?: never;
31
+ }));
32
+ type OpenTelemetryLogWriterOptions = OpenTelemetryLogWriterSetupOptions & {
33
+ useContextManager?: boolean;
34
+ };
35
+ declare class OpenTelemetryLogWriter implements LogWriter {
36
+ private logger;
37
+ private useContextManager;
38
+ constructor(options: OpenTelemetryLogWriterOptions);
39
+ flush(): void | Promise<void>;
40
+ write(level: LogLevel, attrs: Attributes | null | undefined, msg: string | null | undefined): void | Promise<void>;
41
+ }
42
+ declare const HIVE_LOG_LEVEL_NUMBERS: {
43
+ trace: SeverityNumber;
44
+ debug: SeverityNumber;
45
+ info: SeverityNumber;
46
+ warn: SeverityNumber;
47
+ error: SeverityNumber;
48
+ };
49
+ declare function getContextForRequest(attributes?: {
50
+ requestId?: string;
51
+ }): Context;
52
+
53
+ type HiveTracingSpanProcessorOptions = {
54
+ target: string;
55
+ accessToken: string;
56
+ endpoint: string;
57
+ batching?: BufferConfig;
58
+ processor?: never;
59
+ } | {
60
+ processor: SpanProcessor;
61
+ };
62
+ declare class HiveTracingSpanProcessor implements SpanProcessor {
63
+ private traceStateById;
64
+ private processor;
65
+ constructor(config: HiveTracingSpanProcessorOptions);
66
+ onStart(span: Span, parentContext: Context): void;
67
+ onEnd(span: Span): void;
68
+ forceFlush(): Promise<void>;
69
+ shutdown(): Promise<void>;
70
+ }
71
+
72
+ type TracingOptions = {
73
+ traces?: {
74
+ tracerProvider: TracerProvider;
75
+ } | (TracerOptions & ({
76
+ processors: SpanProcessor[];
77
+ tracerProvider?: never;
78
+ exporter?: never;
79
+ } | {
80
+ exporter: SpanExporter;
81
+ batching?: BatchingConfig | boolean;
82
+ tracerProvider?: never;
83
+ processors?: never;
84
+ } | {
85
+ tracerProvider?: never;
86
+ processors?: never;
87
+ exporter?: never;
88
+ }));
89
+ };
90
+ type TracerOptions = {
91
+ console?: boolean;
92
+ spanLimits?: SpanLimits;
93
+ };
94
+ type SamplingOptions = {
95
+ sampler: Sampler;
96
+ samplingRate?: never;
97
+ } | {
98
+ sampler?: never;
99
+ samplingRate?: number;
100
+ };
101
+ type OpentelemetrySetupOptions = TracingOptions & SamplingOptions & {
102
+ resource?: Resource | {
103
+ serviceName: string;
104
+ serviceVersion: string;
105
+ };
106
+ contextManager: ContextManager | null;
107
+ propagators?: TextMapPropagator[];
108
+ generalLimits?: GeneralLimits;
109
+ log?: Logger$1;
110
+ };
111
+ declare function openTelemetrySetup(options: OpentelemetrySetupOptions): void;
112
+ type HiveTracingOptions = {
113
+ target?: string;
114
+ } & ({
115
+ accessToken?: string;
116
+ batching?: BufferConfig;
117
+ processor?: never;
118
+ endpoint?: string;
119
+ } | {
120
+ processor: SpanProcessor;
121
+ });
122
+ declare function hiveTracingSetup(config: HiveTracingOptions & {
123
+ contextManager: ContextManager | null;
124
+ log?: Logger$1;
125
+ }): void;
126
+ type BatchingConfig = boolean | BufferConfig;
127
+
128
+ export { type BatchingConfig, HIVE_LOG_LEVEL_NUMBERS, type HiveTracingOptions, HiveTracingSpanProcessor, type HiveTracingSpanProcessorOptions, OpenTelemetryLogWriter, type OpenTelemetryLogWriterOptions, type OpenTelemetryLogWriterSetupOptions, getContextForRequest, hiveTracingSetup, openTelemetrySetup };
@@ -0,0 +1,128 @@
1
+ import { LogWriter, LogLevel, Attributes, Logger as Logger$1 } from '@graphql-hive/logger';
2
+ import { Context, TracerProvider, ContextManager, TextMapPropagator } from '@opentelemetry/api';
3
+ import { Resource } from '@opentelemetry/resources';
4
+ import { BufferConfig, SpanProcessor, Span, SpanLimits, SpanExporter, Sampler, GeneralLimits } from '@opentelemetry/sdk-trace-base';
5
+ export { S as SEMATTRS_GRAPHQL_DOCUMENT, b as SEMATTRS_GRAPHQL_OPERATION_NAME, a as SEMATTRS_GRAPHQL_OPERATION_TYPE, g as SEMATTRS_HIVE_GATEWAY_OPERATION_SUBGRAPH_NAMES, f as SEMATTRS_HIVE_GATEWAY_UPSTREAM_SUBGRAPH_NAME, e as SEMATTRS_HIVE_GRAPHQL_ERROR_CODES, d as SEMATTRS_HIVE_GRAPHQL_ERROR_COUNT, c as SEMATTRS_HIVE_GRAPHQL_OPERATION_HASH } from './attributes-mikIPKnv.js';
6
+ import { Logger, SeverityNumber } from '@opentelemetry/api-logs';
7
+ import { LoggerProvider, LogRecordLimits, LogRecordProcessor, LogRecordExporter } from '@opentelemetry/sdk-logs';
8
+ export { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION, SEMATTRS_HTTP_CLIENT_IP, SEMATTRS_HTTP_HOST, SEMATTRS_HTTP_METHOD, SEMATTRS_HTTP_ROUTE, SEMATTRS_HTTP_SCHEME, SEMATTRS_HTTP_SERVER_NAME, SEMATTRS_HTTP_STATUS_CODE, SEMATTRS_HTTP_URL, SEMATTRS_HTTP_USER_AGENT, SEMATTRS_NET_HOST_NAME } from '@opentelemetry/semantic-conventions';
9
+
10
+ type ProcessorOptions = {
11
+ forceFlushTimeoutMillis?: number;
12
+ logRecordLimits?: LogRecordLimits;
13
+ resource?: Resource;
14
+ console?: boolean;
15
+ };
16
+ type OpenTelemetryLogWriterSetupOptions = {
17
+ logger: Logger;
18
+ } | {
19
+ provider: LoggerProvider;
20
+ } | (ProcessorOptions & ({
21
+ processors: LogRecordProcessor[];
22
+ exporter?: never;
23
+ } | {
24
+ exporter: LogRecordExporter;
25
+ batching?: boolean | BufferConfig;
26
+ processors?: never;
27
+ } | {
28
+ console: boolean;
29
+ processors?: never;
30
+ exporter?: never;
31
+ }));
32
+ type OpenTelemetryLogWriterOptions = OpenTelemetryLogWriterSetupOptions & {
33
+ useContextManager?: boolean;
34
+ };
35
+ declare class OpenTelemetryLogWriter implements LogWriter {
36
+ private logger;
37
+ private useContextManager;
38
+ constructor(options: OpenTelemetryLogWriterOptions);
39
+ flush(): void | Promise<void>;
40
+ write(level: LogLevel, attrs: Attributes | null | undefined, msg: string | null | undefined): void | Promise<void>;
41
+ }
42
+ declare const HIVE_LOG_LEVEL_NUMBERS: {
43
+ trace: SeverityNumber;
44
+ debug: SeverityNumber;
45
+ info: SeverityNumber;
46
+ warn: SeverityNumber;
47
+ error: SeverityNumber;
48
+ };
49
+ declare function getContextForRequest(attributes?: {
50
+ requestId?: string;
51
+ }): Context;
52
+
53
+ type HiveTracingSpanProcessorOptions = {
54
+ target: string;
55
+ accessToken: string;
56
+ endpoint: string;
57
+ batching?: BufferConfig;
58
+ processor?: never;
59
+ } | {
60
+ processor: SpanProcessor;
61
+ };
62
+ declare class HiveTracingSpanProcessor implements SpanProcessor {
63
+ private traceStateById;
64
+ private processor;
65
+ constructor(config: HiveTracingSpanProcessorOptions);
66
+ onStart(span: Span, parentContext: Context): void;
67
+ onEnd(span: Span): void;
68
+ forceFlush(): Promise<void>;
69
+ shutdown(): Promise<void>;
70
+ }
71
+
72
+ type TracingOptions = {
73
+ traces?: {
74
+ tracerProvider: TracerProvider;
75
+ } | (TracerOptions & ({
76
+ processors: SpanProcessor[];
77
+ tracerProvider?: never;
78
+ exporter?: never;
79
+ } | {
80
+ exporter: SpanExporter;
81
+ batching?: BatchingConfig | boolean;
82
+ tracerProvider?: never;
83
+ processors?: never;
84
+ } | {
85
+ tracerProvider?: never;
86
+ processors?: never;
87
+ exporter?: never;
88
+ }));
89
+ };
90
+ type TracerOptions = {
91
+ console?: boolean;
92
+ spanLimits?: SpanLimits;
93
+ };
94
+ type SamplingOptions = {
95
+ sampler: Sampler;
96
+ samplingRate?: never;
97
+ } | {
98
+ sampler?: never;
99
+ samplingRate?: number;
100
+ };
101
+ type OpentelemetrySetupOptions = TracingOptions & SamplingOptions & {
102
+ resource?: Resource | {
103
+ serviceName: string;
104
+ serviceVersion: string;
105
+ };
106
+ contextManager: ContextManager | null;
107
+ propagators?: TextMapPropagator[];
108
+ generalLimits?: GeneralLimits;
109
+ log?: Logger$1;
110
+ };
111
+ declare function openTelemetrySetup(options: OpentelemetrySetupOptions): void;
112
+ type HiveTracingOptions = {
113
+ target?: string;
114
+ } & ({
115
+ accessToken?: string;
116
+ batching?: BufferConfig;
117
+ processor?: never;
118
+ endpoint?: string;
119
+ } | {
120
+ processor: SpanProcessor;
121
+ });
122
+ declare function hiveTracingSetup(config: HiveTracingOptions & {
123
+ contextManager: ContextManager | null;
124
+ log?: Logger$1;
125
+ }): void;
126
+ type BatchingConfig = boolean | BufferConfig;
127
+
128
+ export { type BatchingConfig, HIVE_LOG_LEVEL_NUMBERS, type HiveTracingOptions, HiveTracingSpanProcessor, type HiveTracingSpanProcessorOptions, OpenTelemetryLogWriter, type OpenTelemetryLogWriterOptions, type OpenTelemetryLogWriterSetupOptions, getContextForRequest, hiveTracingSetup, openTelemetrySetup };