@graphql-hive/gateway 2.0.0-alpha-a57076229f707b5b888a8b1877e893388fcd67d6 → 2.0.0-alpha-be69ab8fa8cf618e4bf67dad92091aff852be2a4
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 +34 -91
- package/dist/bin.cjs +2 -1
- package/dist/bin.js +2 -1
- package/dist/{cli-BQ10GobO.cjs → cli-Be2W1qf0.cjs} +133 -17
- package/dist/{cli-CpJrCTMy.js → cli-eXE2psgp.js} +133 -17
- package/dist/index.cjs +2 -1
- package/dist/index.d.cts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +2 -1
- package/package.json +24 -22
@@ -15,6 +15,7 @@ var node_url = require('node:url');
|
|
15
15
|
var node_fs = require('node:fs');
|
16
16
|
var node_http = require('node:http');
|
17
17
|
var node_https = require('node:https');
|
18
|
+
var sdkTraceBase = require('@opentelemetry/sdk-trace-base');
|
18
19
|
var utils$1 = require('@graphql-tools/utils');
|
19
20
|
var codeFileLoader = require('@graphql-tools/code-file-loader');
|
20
21
|
var graphqlFileLoader = require('@graphql-tools/graphql-file-loader');
|
@@ -492,11 +493,46 @@ function handleFork(log, config) {
|
|
492
493
|
return false;
|
493
494
|
}
|
494
495
|
|
496
|
+
async function handleOpenTelemetryConfig(ctx, cliOpts) {
|
497
|
+
const accessToken = cliOpts.hiveTraceAccessToken;
|
498
|
+
const target = cliOpts.hiveTarget;
|
499
|
+
const openTelemetry = cliOpts.openTelemetry;
|
500
|
+
const exporterType = cliOpts.openTelemetryExporterType ?? "otlp-http";
|
501
|
+
if (typeof openTelemetry === "string" || accessToken) {
|
502
|
+
const { openTelemetrySetup, HiveTracingSpanProcessor } = await import('@graphql-mesh/plugin-opentelemetry/setup');
|
503
|
+
const processors = [];
|
504
|
+
if (openTelemetry) {
|
505
|
+
const { OTLPTraceExporter } = await import(`@opentelemetry/exporter-trace-${exporterType}`);
|
506
|
+
processors.push(
|
507
|
+
new sdkTraceBase.BatchSpanProcessor(new OTLPTraceExporter({ url: openTelemetry }))
|
508
|
+
);
|
509
|
+
}
|
510
|
+
if (accessToken) {
|
511
|
+
if (!target) {
|
512
|
+
ctx.log.error(
|
513
|
+
'Hive tracing needs a target. Please provide it through "--hive-target <target>"'
|
514
|
+
);
|
515
|
+
process.exit(1);
|
516
|
+
}
|
517
|
+
processors.push(
|
518
|
+
new HiveTracingSpanProcessor({
|
519
|
+
accessToken,
|
520
|
+
target
|
521
|
+
})
|
522
|
+
);
|
523
|
+
}
|
524
|
+
openTelemetrySetup({
|
525
|
+
traces: { processors },
|
526
|
+
contextManager: await import('@opentelemetry/context-async-hooks').then((module) => new module.AsyncLocalStorageContextManager()).catch(() => null)
|
527
|
+
});
|
528
|
+
}
|
529
|
+
}
|
530
|
+
|
495
531
|
function handleReportingConfig(ctx, loadedConfig, cliOpts) {
|
496
532
|
const confOpts = {
|
497
533
|
...loadedConfig.reporting?.type === "hive" ? {
|
498
534
|
hiveRegistryToken: loadedConfig.reporting.token,
|
499
|
-
|
535
|
+
hiveTarget: loadedConfig.reporting.target,
|
500
536
|
hiveUsageAccessToken: loadedConfig.reporting.token
|
501
537
|
} : {},
|
502
538
|
...loadedConfig.reporting?.type === "graphos" ? {
|
@@ -504,32 +540,42 @@ function handleReportingConfig(ctx, loadedConfig, cliOpts) {
|
|
504
540
|
apolloKey: loadedConfig.reporting.apiKey
|
505
541
|
} : {}
|
506
542
|
};
|
507
|
-
const opts = {
|
543
|
+
const opts = {
|
544
|
+
...confOpts,
|
545
|
+
...cliOpts,
|
546
|
+
hiveTarget: cliOpts.hiveTarget ?? cliOpts.hiveUsageTarget ?? confOpts.hiveTarget
|
547
|
+
};
|
508
548
|
if (cliOpts.hiveRegistryToken && cliOpts.hiveUsageAccessToken) {
|
509
549
|
ctx.log.error(
|
510
550
|
'Cannot use "--hive-registry-token" with "--hive-usage-access-token". Please use "--hive-usage-target" and "--hive-usage-access-token" or the config instead.'
|
511
551
|
);
|
512
552
|
process.exit(1);
|
513
553
|
}
|
514
|
-
if (cliOpts.
|
554
|
+
if (cliOpts.hiveUsageTarget && cliOpts.hiveTarget) {
|
555
|
+
ctx.log.error(
|
556
|
+
'Cannot use "--hive-usage-target" with "--hive-target". Please only use "--hive-target"'
|
557
|
+
);
|
558
|
+
process.exit(1);
|
559
|
+
}
|
560
|
+
if (cliOpts.hiveRegistryToken && opts.hiveTarget) {
|
515
561
|
ctx.log.error(
|
516
562
|
'Cannot use "--hive-registry-token" with a target. Please use "--hive-usage-target" and "--hive-usage-access-token" or the config instead.'
|
517
563
|
);
|
518
564
|
process.exit(1);
|
519
565
|
}
|
520
|
-
if (opts.
|
566
|
+
if (opts.hiveTarget && !opts.hiveAccessToken && !opts.hiveUsageAccessToken && !opts.hiveTraceAccessToken) {
|
521
567
|
ctx.log.error(
|
522
|
-
'Hive usage target needs an access token. Please provide it through
|
568
|
+
'Hive usage target needs an access token. Please provide it through "--hive-access-token <token>", or specific "--hive-usage-access-token <token>" and "--hive-trace-access-token" options, or the config.'
|
523
569
|
);
|
524
570
|
process.exit(1);
|
525
571
|
}
|
526
|
-
if (opts.hiveUsageAccessToken && !opts.hiveUsageTarget) {
|
572
|
+
if ((opts.hiveAccessToken || opts.hiveUsageAccessToken || opts.hiveTraceAccessToken) && !opts.hiveUsageTarget) {
|
527
573
|
ctx.log.error(
|
528
|
-
'Hive
|
574
|
+
'Hive access token needs a target. Please provide it through the "--hive-target <target>" option or the config.'
|
529
575
|
);
|
530
576
|
process.exit(1);
|
531
577
|
}
|
532
|
-
const hiveUsageAccessToken = opts.hiveUsageAccessToken || opts.hiveRegistryToken;
|
578
|
+
const hiveUsageAccessToken = opts.hiveAccessToken || opts.hiveUsageAccessToken || opts.hiveRegistryToken;
|
533
579
|
if (hiveUsageAccessToken) {
|
534
580
|
if (opts.hiveUsageTarget) {
|
535
581
|
ctx.log.info("Configuring Hive usage reporting");
|
@@ -540,7 +586,7 @@ function handleReportingConfig(ctx, loadedConfig, cliOpts) {
|
|
540
586
|
...loadedConfig.reporting,
|
541
587
|
type: "hive",
|
542
588
|
token: hiveUsageAccessToken,
|
543
|
-
target: opts.
|
589
|
+
target: opts.hiveTarget
|
544
590
|
};
|
545
591
|
}
|
546
592
|
if (opts.apolloKey) {
|
@@ -568,17 +614,28 @@ const addCommand$2 = (ctx, cli) => cli.command("proxy").description(
|
|
568
614
|
"path to the GraphQL schema file or a url from where to pull the schema"
|
569
615
|
).action(async function proxy(endpoint) {
|
570
616
|
const {
|
617
|
+
opentelemetry,
|
618
|
+
opentelemetryExporterType,
|
571
619
|
hiveCdnEndpoint,
|
572
620
|
hiveCdnKey,
|
573
621
|
hiveRegistryToken,
|
622
|
+
hiveTarget,
|
574
623
|
hiveUsageTarget,
|
624
|
+
hiveAccessToken,
|
575
625
|
hiveUsageAccessToken,
|
626
|
+
hiveTraceAccessToken,
|
576
627
|
maskedErrors,
|
577
628
|
hivePersistedDocumentsEndpoint,
|
578
629
|
hivePersistedDocumentsToken,
|
579
630
|
...opts
|
580
631
|
} = this.optsWithGlobals();
|
581
632
|
ctx.log.info(`Starting ${ctx.productName} ${ctx.version} in proxy mode`);
|
633
|
+
await handleOpenTelemetryConfig(ctx, {
|
634
|
+
openTelemetry: opentelemetry,
|
635
|
+
openTelemetryExporterType: opentelemetryExporterType,
|
636
|
+
hiveTarget,
|
637
|
+
hiveTraceAccessToken
|
638
|
+
});
|
582
639
|
const loadedConfig = await loadConfig({
|
583
640
|
log: ctx.log,
|
584
641
|
configPath: opts.configPath,
|
@@ -632,8 +689,11 @@ const addCommand$2 = (ctx, cli) => cli.command("proxy").description(
|
|
632
689
|
const registryConfig = {};
|
633
690
|
const reporting = handleReportingConfig(ctx, loadedConfig, {
|
634
691
|
hiveRegistryToken,
|
692
|
+
hiveTarget,
|
635
693
|
hiveUsageTarget,
|
694
|
+
hiveAccessToken,
|
636
695
|
hiveUsageAccessToken,
|
696
|
+
hiveTraceAccessToken,
|
637
697
|
// proxy can only do reporting to hive registry
|
638
698
|
apolloGraphRef: void 0,
|
639
699
|
apolloKey: void 0
|
@@ -654,7 +714,8 @@ const addCommand$2 = (ctx, cli) => cli.command("proxy").description(
|
|
654
714
|
const builtinPlugins = await getBuiltinPluginsFromConfig(
|
655
715
|
{
|
656
716
|
...loadedConfig,
|
657
|
-
...opts
|
717
|
+
...opts,
|
718
|
+
openTelemetry: opentelemetry ? { ...loadedConfig.openTelemetry, traces: true } : loadedConfig.openTelemetry
|
658
719
|
},
|
659
720
|
{
|
660
721
|
log: ctx.log,
|
@@ -729,15 +790,26 @@ const addCommand$1 = (ctx, cli) => cli.command("subgraph").description(
|
|
729
790
|
'path to the subgraph schema file or a url from where to pull the subgraph schema (default: "subgraph.graphql")'
|
730
791
|
).action(async function subgraph(schemaPathOrUrl) {
|
731
792
|
const {
|
793
|
+
opentelemetry,
|
794
|
+
opentelemetryExporterType,
|
732
795
|
maskedErrors,
|
733
796
|
hiveRegistryToken,
|
797
|
+
hiveTarget,
|
734
798
|
hiveUsageTarget,
|
799
|
+
hiveAccessToken,
|
735
800
|
hiveUsageAccessToken,
|
801
|
+
hiveTraceAccessToken,
|
736
802
|
hivePersistedDocumentsEndpoint,
|
737
803
|
hivePersistedDocumentsToken,
|
738
804
|
...opts
|
739
805
|
} = this.optsWithGlobals();
|
740
806
|
ctx.log.info(`Starting ${ctx.productName} ${ctx.version} as subgraph`);
|
807
|
+
await handleOpenTelemetryConfig(ctx, {
|
808
|
+
openTelemetry: opentelemetry,
|
809
|
+
openTelemetryExporterType: opentelemetryExporterType,
|
810
|
+
hiveTarget,
|
811
|
+
hiveTraceAccessToken
|
812
|
+
});
|
741
813
|
const loadedConfig = await loadConfig({
|
742
814
|
log: ctx.log,
|
743
815
|
configPath: opts.configPath,
|
@@ -753,8 +825,11 @@ const addCommand$1 = (ctx, cli) => cli.command("subgraph").description(
|
|
753
825
|
const registryConfig = {};
|
754
826
|
const reporting = handleReportingConfig(ctx, loadedConfig, {
|
755
827
|
hiveRegistryToken,
|
828
|
+
hiveTarget,
|
756
829
|
hiveUsageTarget,
|
830
|
+
hiveAccessToken,
|
757
831
|
hiveUsageAccessToken,
|
832
|
+
hiveTraceAccessToken,
|
758
833
|
// subgraph can only do reporting to hive registry
|
759
834
|
apolloGraphRef: void 0,
|
760
835
|
apolloKey: void 0
|
@@ -775,7 +850,8 @@ const addCommand$1 = (ctx, cli) => cli.command("subgraph").description(
|
|
775
850
|
const builtinPlugins = await getBuiltinPluginsFromConfig(
|
776
851
|
{
|
777
852
|
...loadedConfig,
|
778
|
-
...opts
|
853
|
+
...opts,
|
854
|
+
openTelemetry: opentelemetry ? { ...loadedConfig.openTelemetry, traces: true } : loadedConfig.openTelemetry
|
779
855
|
},
|
780
856
|
{
|
781
857
|
log: ctx.log,
|
@@ -869,11 +945,16 @@ const addCommand = (ctx, cli) => cli.command("supergraph").description(
|
|
869
945
|
).env("APOLLO_SCHEMA_CONFIG_DELIVERY_ENDPOINT")
|
870
946
|
).action(async function supergraph(schemaPathOrUrl) {
|
871
947
|
const {
|
948
|
+
opentelemetry,
|
949
|
+
opentelemetryExporterType,
|
872
950
|
hiveCdnEndpoint,
|
873
951
|
hiveCdnKey,
|
874
952
|
hiveRegistryToken,
|
875
953
|
hiveUsageTarget,
|
954
|
+
hiveTarget,
|
955
|
+
hiveAccessToken,
|
876
956
|
hiveUsageAccessToken,
|
957
|
+
hiveTraceAccessToken,
|
877
958
|
maskedErrors,
|
878
959
|
apolloGraphRef,
|
879
960
|
apolloKey,
|
@@ -885,6 +966,12 @@ const addCommand = (ctx, cli) => cli.command("supergraph").description(
|
|
885
966
|
ctx.log.info(
|
886
967
|
`Starting ${ctx.productName} ${ctx.version} with supergraph`
|
887
968
|
);
|
969
|
+
await handleOpenTelemetryConfig(ctx, {
|
970
|
+
openTelemetry: opentelemetry,
|
971
|
+
openTelemetryExporterType: opentelemetryExporterType,
|
972
|
+
hiveTarget,
|
973
|
+
hiveTraceAccessToken
|
974
|
+
});
|
888
975
|
const loadedConfig = await loadConfig({
|
889
976
|
log: ctx.log,
|
890
977
|
configPath: opts.configPath,
|
@@ -970,6 +1057,9 @@ const addCommand = (ctx, cli) => cli.command("supergraph").description(
|
|
970
1057
|
}
|
971
1058
|
const registryConfig = {};
|
972
1059
|
const reporting = handleReportingConfig(ctx, loadedConfig, {
|
1060
|
+
hiveTarget,
|
1061
|
+
hiveAccessToken,
|
1062
|
+
hiveTraceAccessToken,
|
973
1063
|
hiveRegistryToken,
|
974
1064
|
hiveUsageTarget,
|
975
1065
|
hiveUsageAccessToken,
|
@@ -992,7 +1082,8 @@ const addCommand = (ctx, cli) => cli.command("supergraph").description(
|
|
992
1082
|
const builtinPlugins = await getBuiltinPluginsFromConfig(
|
993
1083
|
{
|
994
1084
|
...loadedConfig,
|
995
|
-
...opts
|
1085
|
+
...opts,
|
1086
|
+
openTelemetry: opentelemetry ? { ...loadedConfig.openTelemetry, traces: true } : loadedConfig.openTelemetry
|
996
1087
|
},
|
997
1088
|
{
|
998
1089
|
log: ctx.log,
|
@@ -1242,27 +1333,52 @@ let cli = new extraTypings.Command().configureHelp({
|
|
1242
1333
|
// see here https://github.com/tj/commander.js/blob/970ecae402b253de691e6a9066fea22f38fe7431/lib/command.js#L655
|
1243
1334
|
// @ts-expect-error
|
1244
1335
|
null
|
1336
|
+
).addOption(
|
1337
|
+
new extraTypings.Option(
|
1338
|
+
"--opentelemetry [exporter-endpoint]",
|
1339
|
+
`Enable OpenTelemetry integration with an exporter using this option's value as endpoint. By default, it uses OTLP HTTP, use "--opentelemetry-exporter-type" to change the default.`
|
1340
|
+
).env("OPENTELEMETRY")
|
1341
|
+
).addOption(
|
1342
|
+
new extraTypings.Option(
|
1343
|
+
"--opentelemetry-exporter-type <type>",
|
1344
|
+
`OpenTelemetry exporter type to use when setting up OpenTelemetry integration. Requires "--opentelemetry" to set the endpoint.`
|
1345
|
+
).choices(["otlp-http", "otlp-grpc"]).default("otlp-http").env("OPENTELEMETRY_EXPORTER_TYPE")
|
1245
1346
|
).addOption(
|
1246
1347
|
new extraTypings.Option(
|
1247
1348
|
"--hive-registry-token <token>",
|
1248
|
-
'[DEPRECATED: please use "--hive-
|
1349
|
+
'[DEPRECATED: please use "--hive-target" and "--hive-access-token"] Hive registry token for usage metrics reporting'
|
1249
1350
|
).env("HIVE_REGISTRY_TOKEN")
|
1250
1351
|
).addOption(
|
1251
1352
|
new extraTypings.Option(
|
1252
1353
|
"--hive-usage-target <target>",
|
1253
|
-
|
1354
|
+
"[DEPRECATED] please use --hive-target instead."
|
1254
1355
|
).env("HIVE_USAGE_TARGET")
|
1356
|
+
).addOption(
|
1357
|
+
new extraTypings.Option(
|
1358
|
+
"--hive-target <target>",
|
1359
|
+
'Hive registry target to which the usage and tracing data should be reported to. Requires either "--hive-access-token <token>", "--hive-usage-access-token <token>" or "--hive-trace-access-token" option'
|
1360
|
+
).env("HIVE_TARGET")
|
1361
|
+
).addOption(
|
1362
|
+
new extraTypings.Option(
|
1363
|
+
"--hive-access-token <token>",
|
1364
|
+
'Hive registry access token for usage metrics reporting and tracing. Enables both usage reporting and tracing. Requires the "--hive-target <target>" option'
|
1365
|
+
).env("HIVE_ACCESS_TOKEN")
|
1255
1366
|
).addOption(
|
1256
1367
|
new extraTypings.Option(
|
1257
1368
|
"--hive-usage-access-token <token>",
|
1258
|
-
|
1369
|
+
`Hive registry access token for usage reporting. Enables Hive usage report. Requires the "--hive-target <target>" option. It can't be used together with "--hive-access-token"`
|
1259
1370
|
).env("HIVE_USAGE_ACCESS_TOKEN")
|
1371
|
+
).addOption(
|
1372
|
+
new extraTypings.Option(
|
1373
|
+
"--hive-trace-access-token <token>",
|
1374
|
+
`Hive registry access token for tracing. Enables Hive tracing. Requires the "--hive-target <target>" option. It can't be used together with "--hive-access-token"`
|
1375
|
+
).env("HIVE_TRACE_ACCESS_TOKEN")
|
1260
1376
|
).option(
|
1261
1377
|
"--hive-persisted-documents-endpoint <endpoint>",
|
1262
|
-
'[EXPERIMENTAL] Hive CDN endpoint for fetching the persisted documents.
|
1378
|
+
'[EXPERIMENTAL] Hive CDN endpoint for fetching the persisted documents. Requires the "--hive-persisted-documents-token <token>" option'
|
1263
1379
|
).option(
|
1264
1380
|
"--hive-persisted-documents-token <token>",
|
1265
|
-
'[EXPERIMENTAL] Hive persisted documents CDN endpoint token.
|
1381
|
+
'[EXPERIMENTAL] Hive persisted documents CDN endpoint token. Requires the "--hive-persisted-documents-endpoint <endpoint>" option'
|
1266
1382
|
).addOption(
|
1267
1383
|
new extraTypings.Option(
|
1268
1384
|
"--hive-cdn-endpoint <endpoint>",
|
@@ -13,6 +13,7 @@ import { pathToFileURL } from 'node:url';
|
|
13
13
|
import { promises } from 'node:fs';
|
14
14
|
import { createServer as createServer$1 } from 'node:http';
|
15
15
|
import { createServer } from 'node:https';
|
16
|
+
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
|
16
17
|
import { isValidPath, asArray } from '@graphql-tools/utils';
|
17
18
|
import { CodeFileLoader } from '@graphql-tools/code-file-loader';
|
18
19
|
import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader';
|
@@ -485,11 +486,46 @@ function handleFork(log, config) {
|
|
485
486
|
return false;
|
486
487
|
}
|
487
488
|
|
489
|
+
async function handleOpenTelemetryConfig(ctx, cliOpts) {
|
490
|
+
const accessToken = cliOpts.hiveTraceAccessToken;
|
491
|
+
const target = cliOpts.hiveTarget;
|
492
|
+
const openTelemetry = cliOpts.openTelemetry;
|
493
|
+
const exporterType = cliOpts.openTelemetryExporterType ?? "otlp-http";
|
494
|
+
if (typeof openTelemetry === "string" || accessToken) {
|
495
|
+
const { openTelemetrySetup, HiveTracingSpanProcessor } = await import('@graphql-mesh/plugin-opentelemetry/setup');
|
496
|
+
const processors = [];
|
497
|
+
if (openTelemetry) {
|
498
|
+
const { OTLPTraceExporter } = await import(`@opentelemetry/exporter-trace-${exporterType}`);
|
499
|
+
processors.push(
|
500
|
+
new BatchSpanProcessor(new OTLPTraceExporter({ url: openTelemetry }))
|
501
|
+
);
|
502
|
+
}
|
503
|
+
if (accessToken) {
|
504
|
+
if (!target) {
|
505
|
+
ctx.log.error(
|
506
|
+
'Hive tracing needs a target. Please provide it through "--hive-target <target>"'
|
507
|
+
);
|
508
|
+
process.exit(1);
|
509
|
+
}
|
510
|
+
processors.push(
|
511
|
+
new HiveTracingSpanProcessor({
|
512
|
+
accessToken,
|
513
|
+
target
|
514
|
+
})
|
515
|
+
);
|
516
|
+
}
|
517
|
+
openTelemetrySetup({
|
518
|
+
traces: { processors },
|
519
|
+
contextManager: await import('@opentelemetry/context-async-hooks').then((module) => new module.AsyncLocalStorageContextManager()).catch(() => null)
|
520
|
+
});
|
521
|
+
}
|
522
|
+
}
|
523
|
+
|
488
524
|
function handleReportingConfig(ctx, loadedConfig, cliOpts) {
|
489
525
|
const confOpts = {
|
490
526
|
...loadedConfig.reporting?.type === "hive" ? {
|
491
527
|
hiveRegistryToken: loadedConfig.reporting.token,
|
492
|
-
|
528
|
+
hiveTarget: loadedConfig.reporting.target,
|
493
529
|
hiveUsageAccessToken: loadedConfig.reporting.token
|
494
530
|
} : {},
|
495
531
|
...loadedConfig.reporting?.type === "graphos" ? {
|
@@ -497,32 +533,42 @@ function handleReportingConfig(ctx, loadedConfig, cliOpts) {
|
|
497
533
|
apolloKey: loadedConfig.reporting.apiKey
|
498
534
|
} : {}
|
499
535
|
};
|
500
|
-
const opts = {
|
536
|
+
const opts = {
|
537
|
+
...confOpts,
|
538
|
+
...cliOpts,
|
539
|
+
hiveTarget: cliOpts.hiveTarget ?? cliOpts.hiveUsageTarget ?? confOpts.hiveTarget
|
540
|
+
};
|
501
541
|
if (cliOpts.hiveRegistryToken && cliOpts.hiveUsageAccessToken) {
|
502
542
|
ctx.log.error(
|
503
543
|
'Cannot use "--hive-registry-token" with "--hive-usage-access-token". Please use "--hive-usage-target" and "--hive-usage-access-token" or the config instead.'
|
504
544
|
);
|
505
545
|
process.exit(1);
|
506
546
|
}
|
507
|
-
if (cliOpts.
|
547
|
+
if (cliOpts.hiveUsageTarget && cliOpts.hiveTarget) {
|
548
|
+
ctx.log.error(
|
549
|
+
'Cannot use "--hive-usage-target" with "--hive-target". Please only use "--hive-target"'
|
550
|
+
);
|
551
|
+
process.exit(1);
|
552
|
+
}
|
553
|
+
if (cliOpts.hiveRegistryToken && opts.hiveTarget) {
|
508
554
|
ctx.log.error(
|
509
555
|
'Cannot use "--hive-registry-token" with a target. Please use "--hive-usage-target" and "--hive-usage-access-token" or the config instead.'
|
510
556
|
);
|
511
557
|
process.exit(1);
|
512
558
|
}
|
513
|
-
if (opts.
|
559
|
+
if (opts.hiveTarget && !opts.hiveAccessToken && !opts.hiveUsageAccessToken && !opts.hiveTraceAccessToken) {
|
514
560
|
ctx.log.error(
|
515
|
-
'Hive usage target needs an access token. Please provide it through
|
561
|
+
'Hive usage target needs an access token. Please provide it through "--hive-access-token <token>", or specific "--hive-usage-access-token <token>" and "--hive-trace-access-token" options, or the config.'
|
516
562
|
);
|
517
563
|
process.exit(1);
|
518
564
|
}
|
519
|
-
if (opts.hiveUsageAccessToken && !opts.hiveUsageTarget) {
|
565
|
+
if ((opts.hiveAccessToken || opts.hiveUsageAccessToken || opts.hiveTraceAccessToken) && !opts.hiveUsageTarget) {
|
520
566
|
ctx.log.error(
|
521
|
-
'Hive
|
567
|
+
'Hive access token needs a target. Please provide it through the "--hive-target <target>" option or the config.'
|
522
568
|
);
|
523
569
|
process.exit(1);
|
524
570
|
}
|
525
|
-
const hiveUsageAccessToken = opts.hiveUsageAccessToken || opts.hiveRegistryToken;
|
571
|
+
const hiveUsageAccessToken = opts.hiveAccessToken || opts.hiveUsageAccessToken || opts.hiveRegistryToken;
|
526
572
|
if (hiveUsageAccessToken) {
|
527
573
|
if (opts.hiveUsageTarget) {
|
528
574
|
ctx.log.info("Configuring Hive usage reporting");
|
@@ -533,7 +579,7 @@ function handleReportingConfig(ctx, loadedConfig, cliOpts) {
|
|
533
579
|
...loadedConfig.reporting,
|
534
580
|
type: "hive",
|
535
581
|
token: hiveUsageAccessToken,
|
536
|
-
target: opts.
|
582
|
+
target: opts.hiveTarget
|
537
583
|
};
|
538
584
|
}
|
539
585
|
if (opts.apolloKey) {
|
@@ -561,17 +607,28 @@ const addCommand$2 = (ctx, cli) => cli.command("proxy").description(
|
|
561
607
|
"path to the GraphQL schema file or a url from where to pull the schema"
|
562
608
|
).action(async function proxy(endpoint) {
|
563
609
|
const {
|
610
|
+
opentelemetry,
|
611
|
+
opentelemetryExporterType,
|
564
612
|
hiveCdnEndpoint,
|
565
613
|
hiveCdnKey,
|
566
614
|
hiveRegistryToken,
|
615
|
+
hiveTarget,
|
567
616
|
hiveUsageTarget,
|
617
|
+
hiveAccessToken,
|
568
618
|
hiveUsageAccessToken,
|
619
|
+
hiveTraceAccessToken,
|
569
620
|
maskedErrors,
|
570
621
|
hivePersistedDocumentsEndpoint,
|
571
622
|
hivePersistedDocumentsToken,
|
572
623
|
...opts
|
573
624
|
} = this.optsWithGlobals();
|
574
625
|
ctx.log.info(`Starting ${ctx.productName} ${ctx.version} in proxy mode`);
|
626
|
+
await handleOpenTelemetryConfig(ctx, {
|
627
|
+
openTelemetry: opentelemetry,
|
628
|
+
openTelemetryExporterType: opentelemetryExporterType,
|
629
|
+
hiveTarget,
|
630
|
+
hiveTraceAccessToken
|
631
|
+
});
|
575
632
|
const loadedConfig = await loadConfig({
|
576
633
|
log: ctx.log,
|
577
634
|
configPath: opts.configPath,
|
@@ -625,8 +682,11 @@ const addCommand$2 = (ctx, cli) => cli.command("proxy").description(
|
|
625
682
|
const registryConfig = {};
|
626
683
|
const reporting = handleReportingConfig(ctx, loadedConfig, {
|
627
684
|
hiveRegistryToken,
|
685
|
+
hiveTarget,
|
628
686
|
hiveUsageTarget,
|
687
|
+
hiveAccessToken,
|
629
688
|
hiveUsageAccessToken,
|
689
|
+
hiveTraceAccessToken,
|
630
690
|
// proxy can only do reporting to hive registry
|
631
691
|
apolloGraphRef: void 0,
|
632
692
|
apolloKey: void 0
|
@@ -647,7 +707,8 @@ const addCommand$2 = (ctx, cli) => cli.command("proxy").description(
|
|
647
707
|
const builtinPlugins = await getBuiltinPluginsFromConfig(
|
648
708
|
{
|
649
709
|
...loadedConfig,
|
650
|
-
...opts
|
710
|
+
...opts,
|
711
|
+
openTelemetry: opentelemetry ? { ...loadedConfig.openTelemetry, traces: true } : loadedConfig.openTelemetry
|
651
712
|
},
|
652
713
|
{
|
653
714
|
log: ctx.log,
|
@@ -722,15 +783,26 @@ const addCommand$1 = (ctx, cli) => cli.command("subgraph").description(
|
|
722
783
|
'path to the subgraph schema file or a url from where to pull the subgraph schema (default: "subgraph.graphql")'
|
723
784
|
).action(async function subgraph(schemaPathOrUrl) {
|
724
785
|
const {
|
786
|
+
opentelemetry,
|
787
|
+
opentelemetryExporterType,
|
725
788
|
maskedErrors,
|
726
789
|
hiveRegistryToken,
|
790
|
+
hiveTarget,
|
727
791
|
hiveUsageTarget,
|
792
|
+
hiveAccessToken,
|
728
793
|
hiveUsageAccessToken,
|
794
|
+
hiveTraceAccessToken,
|
729
795
|
hivePersistedDocumentsEndpoint,
|
730
796
|
hivePersistedDocumentsToken,
|
731
797
|
...opts
|
732
798
|
} = this.optsWithGlobals();
|
733
799
|
ctx.log.info(`Starting ${ctx.productName} ${ctx.version} as subgraph`);
|
800
|
+
await handleOpenTelemetryConfig(ctx, {
|
801
|
+
openTelemetry: opentelemetry,
|
802
|
+
openTelemetryExporterType: opentelemetryExporterType,
|
803
|
+
hiveTarget,
|
804
|
+
hiveTraceAccessToken
|
805
|
+
});
|
734
806
|
const loadedConfig = await loadConfig({
|
735
807
|
log: ctx.log,
|
736
808
|
configPath: opts.configPath,
|
@@ -746,8 +818,11 @@ const addCommand$1 = (ctx, cli) => cli.command("subgraph").description(
|
|
746
818
|
const registryConfig = {};
|
747
819
|
const reporting = handleReportingConfig(ctx, loadedConfig, {
|
748
820
|
hiveRegistryToken,
|
821
|
+
hiveTarget,
|
749
822
|
hiveUsageTarget,
|
823
|
+
hiveAccessToken,
|
750
824
|
hiveUsageAccessToken,
|
825
|
+
hiveTraceAccessToken,
|
751
826
|
// subgraph can only do reporting to hive registry
|
752
827
|
apolloGraphRef: void 0,
|
753
828
|
apolloKey: void 0
|
@@ -768,7 +843,8 @@ const addCommand$1 = (ctx, cli) => cli.command("subgraph").description(
|
|
768
843
|
const builtinPlugins = await getBuiltinPluginsFromConfig(
|
769
844
|
{
|
770
845
|
...loadedConfig,
|
771
|
-
...opts
|
846
|
+
...opts,
|
847
|
+
openTelemetry: opentelemetry ? { ...loadedConfig.openTelemetry, traces: true } : loadedConfig.openTelemetry
|
772
848
|
},
|
773
849
|
{
|
774
850
|
log: ctx.log,
|
@@ -862,11 +938,16 @@ const addCommand = (ctx, cli) => cli.command("supergraph").description(
|
|
862
938
|
).env("APOLLO_SCHEMA_CONFIG_DELIVERY_ENDPOINT")
|
863
939
|
).action(async function supergraph(schemaPathOrUrl) {
|
864
940
|
const {
|
941
|
+
opentelemetry,
|
942
|
+
opentelemetryExporterType,
|
865
943
|
hiveCdnEndpoint,
|
866
944
|
hiveCdnKey,
|
867
945
|
hiveRegistryToken,
|
868
946
|
hiveUsageTarget,
|
947
|
+
hiveTarget,
|
948
|
+
hiveAccessToken,
|
869
949
|
hiveUsageAccessToken,
|
950
|
+
hiveTraceAccessToken,
|
870
951
|
maskedErrors,
|
871
952
|
apolloGraphRef,
|
872
953
|
apolloKey,
|
@@ -878,6 +959,12 @@ const addCommand = (ctx, cli) => cli.command("supergraph").description(
|
|
878
959
|
ctx.log.info(
|
879
960
|
`Starting ${ctx.productName} ${ctx.version} with supergraph`
|
880
961
|
);
|
962
|
+
await handleOpenTelemetryConfig(ctx, {
|
963
|
+
openTelemetry: opentelemetry,
|
964
|
+
openTelemetryExporterType: opentelemetryExporterType,
|
965
|
+
hiveTarget,
|
966
|
+
hiveTraceAccessToken
|
967
|
+
});
|
881
968
|
const loadedConfig = await loadConfig({
|
882
969
|
log: ctx.log,
|
883
970
|
configPath: opts.configPath,
|
@@ -963,6 +1050,9 @@ const addCommand = (ctx, cli) => cli.command("supergraph").description(
|
|
963
1050
|
}
|
964
1051
|
const registryConfig = {};
|
965
1052
|
const reporting = handleReportingConfig(ctx, loadedConfig, {
|
1053
|
+
hiveTarget,
|
1054
|
+
hiveAccessToken,
|
1055
|
+
hiveTraceAccessToken,
|
966
1056
|
hiveRegistryToken,
|
967
1057
|
hiveUsageTarget,
|
968
1058
|
hiveUsageAccessToken,
|
@@ -985,7 +1075,8 @@ const addCommand = (ctx, cli) => cli.command("supergraph").description(
|
|
985
1075
|
const builtinPlugins = await getBuiltinPluginsFromConfig(
|
986
1076
|
{
|
987
1077
|
...loadedConfig,
|
988
|
-
...opts
|
1078
|
+
...opts,
|
1079
|
+
openTelemetry: opentelemetry ? { ...loadedConfig.openTelemetry, traces: true } : loadedConfig.openTelemetry
|
989
1080
|
},
|
990
1081
|
{
|
991
1082
|
log: ctx.log,
|
@@ -1235,27 +1326,52 @@ let cli = new Command().configureHelp({
|
|
1235
1326
|
// see here https://github.com/tj/commander.js/blob/970ecae402b253de691e6a9066fea22f38fe7431/lib/command.js#L655
|
1236
1327
|
// @ts-expect-error
|
1237
1328
|
null
|
1329
|
+
).addOption(
|
1330
|
+
new Option(
|
1331
|
+
"--opentelemetry [exporter-endpoint]",
|
1332
|
+
`Enable OpenTelemetry integration with an exporter using this option's value as endpoint. By default, it uses OTLP HTTP, use "--opentelemetry-exporter-type" to change the default.`
|
1333
|
+
).env("OPENTELEMETRY")
|
1334
|
+
).addOption(
|
1335
|
+
new Option(
|
1336
|
+
"--opentelemetry-exporter-type <type>",
|
1337
|
+
`OpenTelemetry exporter type to use when setting up OpenTelemetry integration. Requires "--opentelemetry" to set the endpoint.`
|
1338
|
+
).choices(["otlp-http", "otlp-grpc"]).default("otlp-http").env("OPENTELEMETRY_EXPORTER_TYPE")
|
1238
1339
|
).addOption(
|
1239
1340
|
new Option(
|
1240
1341
|
"--hive-registry-token <token>",
|
1241
|
-
'[DEPRECATED: please use "--hive-
|
1342
|
+
'[DEPRECATED: please use "--hive-target" and "--hive-access-token"] Hive registry token for usage metrics reporting'
|
1242
1343
|
).env("HIVE_REGISTRY_TOKEN")
|
1243
1344
|
).addOption(
|
1244
1345
|
new Option(
|
1245
1346
|
"--hive-usage-target <target>",
|
1246
|
-
|
1347
|
+
"[DEPRECATED] please use --hive-target instead."
|
1247
1348
|
).env("HIVE_USAGE_TARGET")
|
1349
|
+
).addOption(
|
1350
|
+
new Option(
|
1351
|
+
"--hive-target <target>",
|
1352
|
+
'Hive registry target to which the usage and tracing data should be reported to. Requires either "--hive-access-token <token>", "--hive-usage-access-token <token>" or "--hive-trace-access-token" option'
|
1353
|
+
).env("HIVE_TARGET")
|
1354
|
+
).addOption(
|
1355
|
+
new Option(
|
1356
|
+
"--hive-access-token <token>",
|
1357
|
+
'Hive registry access token for usage metrics reporting and tracing. Enables both usage reporting and tracing. Requires the "--hive-target <target>" option'
|
1358
|
+
).env("HIVE_ACCESS_TOKEN")
|
1248
1359
|
).addOption(
|
1249
1360
|
new Option(
|
1250
1361
|
"--hive-usage-access-token <token>",
|
1251
|
-
|
1362
|
+
`Hive registry access token for usage reporting. Enables Hive usage report. Requires the "--hive-target <target>" option. It can't be used together with "--hive-access-token"`
|
1252
1363
|
).env("HIVE_USAGE_ACCESS_TOKEN")
|
1364
|
+
).addOption(
|
1365
|
+
new Option(
|
1366
|
+
"--hive-trace-access-token <token>",
|
1367
|
+
`Hive registry access token for tracing. Enables Hive tracing. Requires the "--hive-target <target>" option. It can't be used together with "--hive-access-token"`
|
1368
|
+
).env("HIVE_TRACE_ACCESS_TOKEN")
|
1253
1369
|
).option(
|
1254
1370
|
"--hive-persisted-documents-endpoint <endpoint>",
|
1255
|
-
'[EXPERIMENTAL] Hive CDN endpoint for fetching the persisted documents.
|
1371
|
+
'[EXPERIMENTAL] Hive CDN endpoint for fetching the persisted documents. Requires the "--hive-persisted-documents-token <token>" option'
|
1256
1372
|
).option(
|
1257
1373
|
"--hive-persisted-documents-token <token>",
|
1258
|
-
'[EXPERIMENTAL] Hive persisted documents CDN endpoint token.
|
1374
|
+
'[EXPERIMENTAL] Hive persisted documents CDN endpoint token. Requires the "--hive-persisted-documents-endpoint <endpoint>" option'
|
1259
1375
|
).addOption(
|
1260
1376
|
new Option(
|
1261
1377
|
"--hive-cdn-endpoint <endpoint>",
|
package/dist/index.cjs
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
var cli = require('./cli-
|
3
|
+
var cli = require('./cli-Be2W1qf0.cjs');
|
4
4
|
var logger = require('@graphql-hive/logger');
|
5
5
|
var gatewayRuntime = require('@graphql-hive/gateway-runtime');
|
6
6
|
var pubsub = require('@graphql-hive/pubsub');
|
@@ -30,6 +30,7 @@ require('node:url');
|
|
30
30
|
require('node:fs');
|
31
31
|
require('node:http');
|
32
32
|
require('node:https');
|
33
|
+
require('@opentelemetry/sdk-trace-base');
|
33
34
|
require('@graphql-tools/utils');
|
34
35
|
require('@graphql-tools/code-file-loader');
|
35
36
|
require('@graphql-tools/graphql-file-loader');
|