@graphql-hive/plugin-opentelemetry 1.1.3-rc-8980f45f22c6930653a19bac8573471a73ef543a → 1.2.0-alpha-e698cb6b5b22dcd27d399fe601c95ddb992d7ca0

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/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # @graphql-hive/plugin-opentelemetry
2
2
 
3
- ## 1.1.3-rc-8980f45f22c6930653a19bac8573471a73ef543a
3
+ ## 1.2.0-alpha-e698cb6b5b22dcd27d399fe601c95ddb992d7ca0
4
+ ### Minor Changes
5
+
6
+
7
+
8
+ - [#1611](https://github.com/graphql-hive/gateway/pull/1611) [`5680d9f`](https://github.com/graphql-hive/gateway/commit/5680d9f5e2c38fe5aa5610608b1c775d07d94d22) Thanks [@EmrysMyrddin](https://github.com/EmrysMyrddin)! - It is now possible to fully configure the OpenTelemetry setup when using `hiveTracingSetup`. You can now provide a `resource` and a `samplingRate` (among other options).
9
+
10
+
4
11
  ### Patch Changes
5
12
 
6
13
 
@@ -14,10 +21,10 @@
14
21
 
15
22
  - Updated dependency [`@graphql-hive/core@^0.13.2` ↗︎](https://www.npmjs.com/package/@graphql-hive/core/v/0.13.2) (from `^0.13.1`, in `dependencies`)
16
23
  - Updated dependency [`@graphql-tools/utils@^10.10.3` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.10.3) (from `^10.10.1`, in `dependencies`)
17
- - Updated dependencies [[`4801627`](https://github.com/graphql-hive/gateway/commit/4801627ef16e963bed0052d0f071879004614a14), [`478d7e2`](https://github.com/graphql-hive/gateway/commit/478d7e25ef47fb8fb6183010a8bb61ac31688c55), [`7ecaf7e`](https://github.com/graphql-hive/gateway/commit/7ecaf7e8f658c4e4c1a91d1e8db3c1a8ceca51cb), [`a81b8b2`](https://github.com/graphql-hive/gateway/commit/a81b8b20ecdfda53fb77ae5fae3cbd508ab08936), [`7ecaf7e`](https://github.com/graphql-hive/gateway/commit/7ecaf7e8f658c4e4c1a91d1e8db3c1a8ceca51cb), [`7ecaf7e`](https://github.com/graphql-hive/gateway/commit/7ecaf7e8f658c4e4c1a91d1e8db3c1a8ceca51cb)]:
18
- - @graphql-hive/gateway-runtime@2.3.5-rc-8980f45f22c6930653a19bac8573471a73ef543a
19
- - @graphql-hive/logger@1.0.9-rc-8980f45f22c6930653a19bac8573471a73ef543a
20
- - @graphql-mesh/transport-common@1.0.12-rc-8980f45f22c6930653a19bac8573471a73ef543a
24
+ - Updated dependencies [[`4801627`](https://github.com/graphql-hive/gateway/commit/4801627ef16e963bed0052d0f071879004614a14), [`478d7e2`](https://github.com/graphql-hive/gateway/commit/478d7e25ef47fb8fb6183010a8bb61ac31688c55), [`7ecaf7e`](https://github.com/graphql-hive/gateway/commit/7ecaf7e8f658c4e4c1a91d1e8db3c1a8ceca51cb), [`a81b8b2`](https://github.com/graphql-hive/gateway/commit/a81b8b20ecdfda53fb77ae5fae3cbd508ab08936), [`ce83f35`](https://github.com/graphql-hive/gateway/commit/ce83f356cbeb2f8413689204275710e7d7a27822), [`7ecaf7e`](https://github.com/graphql-hive/gateway/commit/7ecaf7e8f658c4e4c1a91d1e8db3c1a8ceca51cb), [`7ecaf7e`](https://github.com/graphql-hive/gateway/commit/7ecaf7e8f658c4e4c1a91d1e8db3c1a8ceca51cb)]:
25
+ - @graphql-hive/gateway-runtime@2.3.5-alpha-e698cb6b5b22dcd27d399fe601c95ddb992d7ca0
26
+ - @graphql-hive/logger@1.0.9-alpha-e698cb6b5b22dcd27d399fe601c95ddb992d7ca0
27
+ - @graphql-mesh/transport-common@1.0.12-alpha-e698cb6b5b22dcd27d399fe601c95ddb992d7ca0
21
28
 
22
29
  ## 1.1.2
23
30
  ### Patch Changes
package/dist/setup.cjs CHANGED
@@ -224,17 +224,33 @@ function getContextForRequest(attributes) {
224
224
  return plugin.otelCtxForRequestId.get(attributes.requestId) ?? api.ROOT_CONTEXT;
225
225
  }
226
226
 
227
- globalThis.__OTEL_PLUGIN_VERSION__ = '1.1.3-rc-8980f45f22c6930653a19bac8573471a73ef543a';
227
+ globalThis.__OTEL_PLUGIN_VERSION__ = '1.2.0-alpha-e698cb6b5b22dcd27d399fe601c95ddb992d7ca0';
228
+ let initialized = false;
228
229
  function openTelemetrySetup(options) {
229
230
  const log = options.log || new logger.Logger();
231
+ if (initialized) {
232
+ log.error(
233
+ `${initialized.name} integration has already been initialized by ${initialized.source}`
234
+ );
235
+ throw new Error(
236
+ `${initialized.name} integration already initialized. See previous logs for more information`
237
+ );
238
+ }
239
+ initialized = options._initialization || {
240
+ name: "OpenTelemetry",
241
+ source: `\`openTelemetrySetup\` utility function call ${getStackTrace()}`
242
+ };
230
243
  if (plugin.getEnvBool("OTEL_SDK_DISABLED")) {
231
244
  log.warn(
232
- "OpenTelemetry integration is disabled because `OTEL_SDK_DISABLED` environment variable is truthy"
245
+ `${initialized.name} integration is disabled because \`OTEL_SDK_DISABLED\` environment variable is truthy`
233
246
  );
234
247
  return;
235
248
  }
236
- const logAttributes = { registrationResults: {} };
237
- let logMessage = "OpenTelemetry integration is enabled";
249
+ const logAttributes = {
250
+ ...options._initialization?.logAttributes,
251
+ registrationResults: {}
252
+ };
253
+ let logMessage = `${initialized.name} integration is enabled`;
238
254
  if (options.configureDiagLogger !== false) {
239
255
  const [diagLogLevel, hiveLogLevel] = plugin.diagLogLevelFromEnv() ?? [
240
256
  api.DiagLogLevel.VERBOSE,
@@ -273,13 +289,15 @@ function openTelemetrySetup(options) {
273
289
  logMessage += " in addition to an stdout debug exporter";
274
290
  logAttributes["console"] = true;
275
291
  }
276
- const baseResource = resources.resourceFromAttributes({
277
- [semanticConventions.ATTR_SERVICE_NAME]: options.resource && "serviceName" in options.resource ? options.resource?.serviceName : plugin.getEnvStr("OTEL_SERVICE_NAME") || "@graphql-hive/plugin-opentelemetry",
278
- [semanticConventions.ATTR_SERVICE_VERSION]: options.resource && "serviceVersion" in options.resource ? options.resource?.serviceVersion : plugin.getEnvStr("OTEL_SERVICE_VERSION") || globalThis.__OTEL_PLUGIN_VERSION__ || "unknown",
279
- ["hive.gateway.version"]: globalThis.__VERSION__,
280
- ["hive.otel.version"]: globalThis.__OTEL_PLUGIN_VERSION__ || "unknown"
281
- });
282
- const resource = options.resource && !("serviceName" in options.resource) ? baseResource.merge(options.resource) : baseResource;
292
+ const resource = createResource(
293
+ resources.resourceFromAttributes({
294
+ [semanticConventions.ATTR_SERVICE_NAME]: plugin.getEnvStr("OTEL_SERVICE_NAME") || "@graphql-hive/plugin-opentelemetry",
295
+ [semanticConventions.ATTR_SERVICE_VERSION]: plugin.getEnvStr("OTEL_SERVICE_VERSION") || globalThis.__OTEL_PLUGIN_VERSION__ || "unknown",
296
+ ["hive.gateway.version"]: globalThis.__VERSION__,
297
+ ["hive.otel.version"]: globalThis.__OTEL_PLUGIN_VERSION__ || "unknown"
298
+ }),
299
+ options.resource
300
+ );
283
301
  logAttributes["resource"] = resource.attributes;
284
302
  logAttributes["sampling"] = options.sampler ? "custom" : options.samplingRate;
285
303
  logAttributes["registrationResults"].tracerProvider = api.trace.setGlobalTracerProvider(
@@ -309,38 +327,54 @@ function openTelemetrySetup(options) {
309
327
  }
310
328
  log.info(logAttributes, logMessage);
311
329
  }
312
- function hiveTracingSetup(config) {
313
- const log = config.log || new logger.Logger();
314
- config.target ??= plugin.getEnvStr("HIVE_TARGET");
315
- if (!config.target) {
330
+ function hiveTracingSetup(options) {
331
+ const log = options.log || new logger.Logger();
332
+ options.target ??= plugin.getEnvStr("HIVE_TARGET");
333
+ if (!options.target) {
316
334
  throw new Error(
317
335
  "You must specify the Hive Registry `target`. Either provide `target` option or `HIVE_TARGET` environment variable."
318
336
  );
319
337
  }
320
- const logAttributes = { target: config.target };
321
- if (!config.processor) {
322
- config.accessToken ??= plugin.getEnvStr("HIVE_TRACING_ACCESS_TOKEN") ?? plugin.getEnvStr("HIVE_ACCESS_TOKEN");
323
- if (!config.accessToken) {
338
+ const logAttributes = {
339
+ ...options._initialization?.logAttributes,
340
+ target: options.target
341
+ };
342
+ if (!options.processor) {
343
+ options.accessToken ??= plugin.getEnvStr("HIVE_TRACING_ACCESS_TOKEN") ?? plugin.getEnvStr("HIVE_ACCESS_TOKEN");
344
+ if (!options.accessToken) {
324
345
  throw new Error(
325
346
  "You must specify the Hive Registry `accessToken`. Either provide `accessToken` option or `HIVE_ACCESS_TOKEN`/`HIVE_TRACE_ACCESS_TOKEN` environment variable."
326
347
  );
327
348
  }
328
- logAttributes["endpoint"] = config.endpoint;
329
- logAttributes["batching"] = config.batching;
349
+ logAttributes["endpoint"] = options.endpoint;
350
+ logAttributes["batching"] = options.batching;
330
351
  }
331
352
  openTelemetrySetup({
353
+ ...options,
332
354
  log,
333
- contextManager: config.contextManager,
334
- resource: resources.resourceFromAttributes({
335
- "hive.target_id": config.target
336
- }),
355
+ resource: createResource(
356
+ resources.resourceFromAttributes({
357
+ "hive.target_id": options.target,
358
+ [semanticConventions.ATTR_SERVICE_NAME]: plugin.getEnvStr("OTEL_SERVICE_NAME") || "hive-gateway",
359
+ [semanticConventions.ATTR_SERVICE_VERSION]: plugin.getEnvStr("OTEL_SERVICE_VERSION") || globalThis.__OTEL_PLUGIN_VERSION__ || "unknown"
360
+ }),
361
+ options.resource
362
+ ),
337
363
  traces: {
338
364
  processors: [
339
- new HiveTracingSpanProcessor(config)
340
- ]
365
+ new HiveTracingSpanProcessor(
366
+ options
367
+ )
368
+ ],
369
+ spanLimits: options.spanLimits,
370
+ console: options.console
371
+ },
372
+ _initialization: options._initialization || {
373
+ name: "Hive Tracing",
374
+ source: `\`hiveTracingSetup\` utility function call ${getStackTrace()}`,
375
+ logAttributes
341
376
  }
342
377
  });
343
- log.info(logAttributes, "Hive Tracing integration has been enabled");
344
378
  }
345
379
  function resolveBatchingConfig(exporter, batchingConfig) {
346
380
  const value = batchingConfig ?? true;
@@ -352,6 +386,29 @@ function resolveBatchingConfig(exporter, batchingConfig) {
352
386
  return new sdkTraceBase.BatchSpanProcessor(exporter, value);
353
387
  }
354
388
  }
389
+ function createResource(baseResource, userResource) {
390
+ if (!userResource) {
391
+ return baseResource;
392
+ }
393
+ if ("serviceName" in userResource) {
394
+ return baseResource.merge(
395
+ resources.resourceFromAttributes({
396
+ [semanticConventions.ATTR_SERVICE_NAME]: userResource.serviceName,
397
+ [semanticConventions.ATTR_SERVICE_VERSION]: userResource.serviceVersion
398
+ })
399
+ );
400
+ }
401
+ return baseResource.merge(userResource);
402
+ }
403
+ function getStackTrace() {
404
+ return (new Error().stack ?? "").split("\n").slice(3).join("\n").trim();
405
+ }
406
+ function disable() {
407
+ api.trace.disable();
408
+ api.context.disable();
409
+ api.propagation.disable();
410
+ initialized = false;
411
+ }
355
412
 
356
413
  Object.defineProperty(exports, "ATTR_SERVICE_NAME", {
357
414
  enumerable: true,
@@ -412,6 +469,7 @@ exports.SEMATTRS_HIVE_GRAPHQL_OPERATION_HASH = plugin.SEMATTRS_HIVE_GRAPHQL_OPER
412
469
  exports.HIVE_LOG_LEVEL_NUMBERS = HIVE_LOG_LEVEL_NUMBERS;
413
470
  exports.HiveTracingSpanProcessor = HiveTracingSpanProcessor;
414
471
  exports.OpenTelemetryLogWriter = OpenTelemetryLogWriter;
472
+ exports.disable = disable;
415
473
  exports.getContextForRequest = getContextForRequest;
416
474
  exports.hiveTracingSetup = hiveTracingSetup;
417
475
  exports.openTelemetrySetup = openTelemetrySetup;
package/dist/setup.d.cts CHANGED
@@ -126,7 +126,7 @@ type SamplingOptions = {
126
126
  */
127
127
  samplingRate?: number;
128
128
  };
129
- type OpentelemetrySetupOptions = TracingOptions & SamplingOptions & {
129
+ type BaseOptions = {
130
130
  /**
131
131
  * The Resource that will be used to create the Trace Provider.
132
132
  * Can be either a Resource instance, or an simple object with service name and version
@@ -162,6 +162,15 @@ type OpentelemetrySetupOptions = TracingOptions & SamplingOptions & {
162
162
  * This means that the logger will be enabled only if `OTEL_LOG_LEVEL` variable is set.
163
163
  */
164
164
  configureDiagLogger?: boolean;
165
+ /** @internal */
166
+ _initialization?: typeof initialized & {
167
+ logAttributes: Attributes;
168
+ };
169
+ };
170
+ type OpentelemetrySetupOptions = TracingOptions & SamplingOptions & BaseOptions;
171
+ declare let initialized: false | {
172
+ name: string;
173
+ source: string;
165
174
  };
166
175
  declare function openTelemetrySetup(options: OpentelemetrySetupOptions): void;
167
176
  type HiveTracingOptions = {
@@ -174,10 +183,12 @@ type HiveTracingOptions = {
174
183
  } | {
175
184
  processor: SpanProcessor;
176
185
  });
177
- declare function hiveTracingSetup(config: HiveTracingOptions & {
178
- contextManager: ContextManager | null;
179
- log?: Logger$1;
180
- }): void;
186
+ type HiveTracingSetupOptions = BaseOptions & HiveTracingOptions & SamplingOptions & TracerOptions;
187
+ declare function hiveTracingSetup(options: HiveTracingSetupOptions): void;
181
188
  type BatchingConfig = boolean | BufferConfig;
189
+ /**
190
+ * Reset OpenTelemetry setup by disabling `trace`, `context` and `propagation` OpenTelemetry APIs.
191
+ */
192
+ declare function disable(): void;
182
193
 
183
- export { type BatchingConfig, HIVE_LOG_LEVEL_NUMBERS, type HiveTracingOptions, HiveTracingSpanProcessor, type HiveTracingSpanProcessorOptions, OpenTelemetryLogWriter, type OpenTelemetryLogWriterOptions, type OpenTelemetryLogWriterSetupOptions, getContextForRequest, hiveTracingSetup, openTelemetrySetup };
194
+ export { type BatchingConfig, HIVE_LOG_LEVEL_NUMBERS, type HiveTracingOptions, type HiveTracingSetupOptions, HiveTracingSpanProcessor, type HiveTracingSpanProcessorOptions, OpenTelemetryLogWriter, type OpenTelemetryLogWriterOptions, type OpenTelemetryLogWriterSetupOptions, disable, getContextForRequest, hiveTracingSetup, openTelemetrySetup };
package/dist/setup.d.ts CHANGED
@@ -126,7 +126,7 @@ type SamplingOptions = {
126
126
  */
127
127
  samplingRate?: number;
128
128
  };
129
- type OpentelemetrySetupOptions = TracingOptions & SamplingOptions & {
129
+ type BaseOptions = {
130
130
  /**
131
131
  * The Resource that will be used to create the Trace Provider.
132
132
  * Can be either a Resource instance, or an simple object with service name and version
@@ -162,6 +162,15 @@ type OpentelemetrySetupOptions = TracingOptions & SamplingOptions & {
162
162
  * This means that the logger will be enabled only if `OTEL_LOG_LEVEL` variable is set.
163
163
  */
164
164
  configureDiagLogger?: boolean;
165
+ /** @internal */
166
+ _initialization?: typeof initialized & {
167
+ logAttributes: Attributes;
168
+ };
169
+ };
170
+ type OpentelemetrySetupOptions = TracingOptions & SamplingOptions & BaseOptions;
171
+ declare let initialized: false | {
172
+ name: string;
173
+ source: string;
165
174
  };
166
175
  declare function openTelemetrySetup(options: OpentelemetrySetupOptions): void;
167
176
  type HiveTracingOptions = {
@@ -174,10 +183,12 @@ type HiveTracingOptions = {
174
183
  } | {
175
184
  processor: SpanProcessor;
176
185
  });
177
- declare function hiveTracingSetup(config: HiveTracingOptions & {
178
- contextManager: ContextManager | null;
179
- log?: Logger$1;
180
- }): void;
186
+ type HiveTracingSetupOptions = BaseOptions & HiveTracingOptions & SamplingOptions & TracerOptions;
187
+ declare function hiveTracingSetup(options: HiveTracingSetupOptions): void;
181
188
  type BatchingConfig = boolean | BufferConfig;
189
+ /**
190
+ * Reset OpenTelemetry setup by disabling `trace`, `context` and `propagation` OpenTelemetry APIs.
191
+ */
192
+ declare function disable(): void;
182
193
 
183
- export { type BatchingConfig, HIVE_LOG_LEVEL_NUMBERS, type HiveTracingOptions, HiveTracingSpanProcessor, type HiveTracingSpanProcessorOptions, OpenTelemetryLogWriter, type OpenTelemetryLogWriterOptions, type OpenTelemetryLogWriterSetupOptions, getContextForRequest, hiveTracingSetup, openTelemetrySetup };
194
+ export { type BatchingConfig, HIVE_LOG_LEVEL_NUMBERS, type HiveTracingOptions, type HiveTracingSetupOptions, HiveTracingSpanProcessor, type HiveTracingSpanProcessorOptions, OpenTelemetryLogWriter, type OpenTelemetryLogWriterOptions, type OpenTelemetryLogWriterSetupOptions, disable, getContextForRequest, hiveTracingSetup, openTelemetrySetup };
package/dist/setup.js CHANGED
@@ -224,17 +224,33 @@ function getContextForRequest(attributes) {
224
224
  return otelCtxForRequestId.get(attributes.requestId) ?? ROOT_CONTEXT;
225
225
  }
226
226
 
227
- globalThis.__OTEL_PLUGIN_VERSION__ = '1.1.3-rc-8980f45f22c6930653a19bac8573471a73ef543a';
227
+ globalThis.__OTEL_PLUGIN_VERSION__ = '1.2.0-alpha-e698cb6b5b22dcd27d399fe601c95ddb992d7ca0';
228
+ let initialized = false;
228
229
  function openTelemetrySetup(options) {
229
230
  const log = options.log || new Logger();
231
+ if (initialized) {
232
+ log.error(
233
+ `${initialized.name} integration has already been initialized by ${initialized.source}`
234
+ );
235
+ throw new Error(
236
+ `${initialized.name} integration already initialized. See previous logs for more information`
237
+ );
238
+ }
239
+ initialized = options._initialization || {
240
+ name: "OpenTelemetry",
241
+ source: `\`openTelemetrySetup\` utility function call ${getStackTrace()}`
242
+ };
230
243
  if (getEnvBool("OTEL_SDK_DISABLED")) {
231
244
  log.warn(
232
- "OpenTelemetry integration is disabled because `OTEL_SDK_DISABLED` environment variable is truthy"
245
+ `${initialized.name} integration is disabled because \`OTEL_SDK_DISABLED\` environment variable is truthy`
233
246
  );
234
247
  return;
235
248
  }
236
- const logAttributes = { registrationResults: {} };
237
- let logMessage = "OpenTelemetry integration is enabled";
249
+ const logAttributes = {
250
+ ...options._initialization?.logAttributes,
251
+ registrationResults: {}
252
+ };
253
+ let logMessage = `${initialized.name} integration is enabled`;
238
254
  if (options.configureDiagLogger !== false) {
239
255
  const [diagLogLevel, hiveLogLevel] = diagLogLevelFromEnv() ?? [
240
256
  DiagLogLevel.VERBOSE,
@@ -273,13 +289,15 @@ function openTelemetrySetup(options) {
273
289
  logMessage += " in addition to an stdout debug exporter";
274
290
  logAttributes["console"] = true;
275
291
  }
276
- const baseResource = resourceFromAttributes({
277
- [ATTR_SERVICE_NAME]: options.resource && "serviceName" in options.resource ? options.resource?.serviceName : getEnvStr("OTEL_SERVICE_NAME") || "@graphql-hive/plugin-opentelemetry",
278
- [ATTR_SERVICE_VERSION]: options.resource && "serviceVersion" in options.resource ? options.resource?.serviceVersion : getEnvStr("OTEL_SERVICE_VERSION") || globalThis.__OTEL_PLUGIN_VERSION__ || "unknown",
279
- ["hive.gateway.version"]: globalThis.__VERSION__,
280
- ["hive.otel.version"]: globalThis.__OTEL_PLUGIN_VERSION__ || "unknown"
281
- });
282
- const resource = options.resource && !("serviceName" in options.resource) ? baseResource.merge(options.resource) : baseResource;
292
+ const resource = createResource(
293
+ resourceFromAttributes({
294
+ [ATTR_SERVICE_NAME]: getEnvStr("OTEL_SERVICE_NAME") || "@graphql-hive/plugin-opentelemetry",
295
+ [ATTR_SERVICE_VERSION]: getEnvStr("OTEL_SERVICE_VERSION") || globalThis.__OTEL_PLUGIN_VERSION__ || "unknown",
296
+ ["hive.gateway.version"]: globalThis.__VERSION__,
297
+ ["hive.otel.version"]: globalThis.__OTEL_PLUGIN_VERSION__ || "unknown"
298
+ }),
299
+ options.resource
300
+ );
283
301
  logAttributes["resource"] = resource.attributes;
284
302
  logAttributes["sampling"] = options.sampler ? "custom" : options.samplingRate;
285
303
  logAttributes["registrationResults"].tracerProvider = trace.setGlobalTracerProvider(
@@ -309,38 +327,54 @@ function openTelemetrySetup(options) {
309
327
  }
310
328
  log.info(logAttributes, logMessage);
311
329
  }
312
- function hiveTracingSetup(config) {
313
- const log = config.log || new Logger();
314
- config.target ??= getEnvStr("HIVE_TARGET");
315
- if (!config.target) {
330
+ function hiveTracingSetup(options) {
331
+ const log = options.log || new Logger();
332
+ options.target ??= getEnvStr("HIVE_TARGET");
333
+ if (!options.target) {
316
334
  throw new Error(
317
335
  "You must specify the Hive Registry `target`. Either provide `target` option or `HIVE_TARGET` environment variable."
318
336
  );
319
337
  }
320
- const logAttributes = { target: config.target };
321
- if (!config.processor) {
322
- config.accessToken ??= getEnvStr("HIVE_TRACING_ACCESS_TOKEN") ?? getEnvStr("HIVE_ACCESS_TOKEN");
323
- if (!config.accessToken) {
338
+ const logAttributes = {
339
+ ...options._initialization?.logAttributes,
340
+ target: options.target
341
+ };
342
+ if (!options.processor) {
343
+ options.accessToken ??= getEnvStr("HIVE_TRACING_ACCESS_TOKEN") ?? getEnvStr("HIVE_ACCESS_TOKEN");
344
+ if (!options.accessToken) {
324
345
  throw new Error(
325
346
  "You must specify the Hive Registry `accessToken`. Either provide `accessToken` option or `HIVE_ACCESS_TOKEN`/`HIVE_TRACE_ACCESS_TOKEN` environment variable."
326
347
  );
327
348
  }
328
- logAttributes["endpoint"] = config.endpoint;
329
- logAttributes["batching"] = config.batching;
349
+ logAttributes["endpoint"] = options.endpoint;
350
+ logAttributes["batching"] = options.batching;
330
351
  }
331
352
  openTelemetrySetup({
353
+ ...options,
332
354
  log,
333
- contextManager: config.contextManager,
334
- resource: resourceFromAttributes({
335
- "hive.target_id": config.target
336
- }),
355
+ resource: createResource(
356
+ resourceFromAttributes({
357
+ "hive.target_id": options.target,
358
+ [ATTR_SERVICE_NAME]: getEnvStr("OTEL_SERVICE_NAME") || "hive-gateway",
359
+ [ATTR_SERVICE_VERSION]: getEnvStr("OTEL_SERVICE_VERSION") || globalThis.__OTEL_PLUGIN_VERSION__ || "unknown"
360
+ }),
361
+ options.resource
362
+ ),
337
363
  traces: {
338
364
  processors: [
339
- new HiveTracingSpanProcessor(config)
340
- ]
365
+ new HiveTracingSpanProcessor(
366
+ options
367
+ )
368
+ ],
369
+ spanLimits: options.spanLimits,
370
+ console: options.console
371
+ },
372
+ _initialization: options._initialization || {
373
+ name: "Hive Tracing",
374
+ source: `\`hiveTracingSetup\` utility function call ${getStackTrace()}`,
375
+ logAttributes
341
376
  }
342
377
  });
343
- log.info(logAttributes, "Hive Tracing integration has been enabled");
344
378
  }
345
379
  function resolveBatchingConfig(exporter, batchingConfig) {
346
380
  const value = batchingConfig ?? true;
@@ -352,5 +386,28 @@ function resolveBatchingConfig(exporter, batchingConfig) {
352
386
  return new BatchSpanProcessor(exporter, value);
353
387
  }
354
388
  }
389
+ function createResource(baseResource, userResource) {
390
+ if (!userResource) {
391
+ return baseResource;
392
+ }
393
+ if ("serviceName" in userResource) {
394
+ return baseResource.merge(
395
+ resourceFromAttributes({
396
+ [ATTR_SERVICE_NAME]: userResource.serviceName,
397
+ [ATTR_SERVICE_VERSION]: userResource.serviceVersion
398
+ })
399
+ );
400
+ }
401
+ return baseResource.merge(userResource);
402
+ }
403
+ function getStackTrace() {
404
+ return (new Error().stack ?? "").split("\n").slice(3).join("\n").trim();
405
+ }
406
+ function disable() {
407
+ trace.disable();
408
+ context.disable();
409
+ propagation.disable();
410
+ initialized = false;
411
+ }
355
412
 
356
- export { HIVE_LOG_LEVEL_NUMBERS, HiveTracingSpanProcessor, OpenTelemetryLogWriter, SEMATTRS_HIVE_GATEWAY_OPERATION_SUBGRAPH_NAMES, SEMATTRS_HIVE_GRAPHQL_ERROR_CODES, SEMATTRS_HIVE_GRAPHQL_ERROR_COUNT, getContextForRequest, hiveTracingSetup, openTelemetrySetup };
413
+ export { HIVE_LOG_LEVEL_NUMBERS, HiveTracingSpanProcessor, OpenTelemetryLogWriter, SEMATTRS_HIVE_GATEWAY_OPERATION_SUBGRAPH_NAMES, SEMATTRS_HIVE_GRAPHQL_ERROR_CODES, SEMATTRS_HIVE_GRAPHQL_ERROR_COUNT, disable, getContextForRequest, hiveTracingSetup, openTelemetrySetup };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-hive/plugin-opentelemetry",
3
- "version": "1.1.3-rc-8980f45f22c6930653a19bac8573471a73ef543a",
3
+ "version": "1.2.0-alpha-e698cb6b5b22dcd27d399fe601c95ddb992d7ca0",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -63,10 +63,10 @@
63
63
  },
64
64
  "dependencies": {
65
65
  "@graphql-hive/core": "^0.13.2",
66
- "@graphql-hive/gateway-runtime": "2.3.5-rc-8980f45f22c6930653a19bac8573471a73ef543a",
67
- "@graphql-hive/logger": "1.0.9-rc-8980f45f22c6930653a19bac8573471a73ef543a",
66
+ "@graphql-hive/gateway-runtime": "2.3.5-alpha-e698cb6b5b22dcd27d399fe601c95ddb992d7ca0",
67
+ "@graphql-hive/logger": "1.0.9-alpha-e698cb6b5b22dcd27d399fe601c95ddb992d7ca0",
68
68
  "@graphql-mesh/cross-helpers": "^0.4.10",
69
- "@graphql-mesh/transport-common": "1.0.12-rc-8980f45f22c6930653a19bac8573471a73ef543a",
69
+ "@graphql-mesh/transport-common": "1.0.12-alpha-e698cb6b5b22dcd27d399fe601c95ddb992d7ca0",
70
70
  "@graphql-mesh/types": "^0.104.16",
71
71
  "@graphql-mesh/utils": "^0.104.16",
72
72
  "@graphql-tools/utils": "^10.10.3",