Skip to content

Commit 140d402

Browse files
committed
feat: use hive console in addition to additional trace collector
1 parent 0bc185d commit 140d402

File tree

1 file changed

+39
-20
lines changed

1 file changed

+39
-20
lines changed

deployment/config/public-graphql-api-gateway/gateway.config.ts

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,41 @@
11
// @ts-expect-error not a dependency
22
import { defineConfig } from '@graphql-hive/gateway';
33
// @ts-expect-error not a dependency
4-
import { openTelemetrySetup } from '@graphql-hive/gateway/opentelemetry/setup';
4+
import { hiveTracingSetup } from '@graphql-hive/plugin-opentelemetry/setup';
55
import { AsyncLocalStorageContextManager } from '@opentelemetry/context-async-hooks';
66
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
7+
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
8+
import { MultiSpanProcessor } from '@opentelemetry/sdk-trace-base/build/src/MultiSpanProcessor';
79

8-
openTelemetrySetup({
9-
// Mandatory: It depends on the available API in your runtime.
10-
// We recommend AsyncLocalStorage based manager when possible.
11-
// `@opentelemetry/context-zone` is also available for other runtimes.
12-
// Pass `false` to disable context manager usage.
13-
contextManager: new AsyncLocalStorageContextManager(),
14-
15-
traces: {
16-
// Define your exporter, most of the time the OTLP HTTP one. Traces are batched by default.
17-
exporter: new OTLPTraceExporter({ url: process.env['OPENTELEMETRY_COLLECTOR_ENDPOINT']! }),
18-
// You can easily enable a console exporter for quick debug
19-
console: process.env['DEBUG_TRACES'] === '1',
20-
},
21-
});
10+
if (process.env['OPENTELEMETRY_COLLECTOR_ENDPOINT'] || process.env['HIVE_TRACING_ACCESS_TOKEN']) {
11+
hiveTracingSetup({
12+
contextManager: new AsyncLocalStorageContextManager(),
13+
processor: new MultiSpanProcessor([
14+
...(process.env['HIVE_TRACING_ACCESS_TOKEN']
15+
? [
16+
new BatchSpanProcessor(
17+
new OTLPTraceExporter({
18+
url: 'hive tracing endpoint',
19+
headers: {
20+
Authorization: `Bearer {process.env.['HIVE_TRACING_ACCESS_TOKEN']}`,
21+
'X-Hive-Target-Ref': process.env.HIVE_TRACING_TARGET!,
22+
},
23+
}),
24+
),
25+
]
26+
: []),
27+
...(process.env['OPENTELEMETRY_COLLECTOR_ENDPOINT']
28+
? [
29+
new BatchSpanProcessor(
30+
new OTLPTraceExporter({
31+
url: process.env['OPENTELEMETRY_COLLECTOR_ENDPOINT']!,
32+
}),
33+
),
34+
]
35+
: []),
36+
]),
37+
});
38+
}
2239

2340
const defaultQuery = `#
2441
# Welcome to the Hive Console GraphQL API.
@@ -50,11 +67,13 @@ export const gatewayConfig = defineConfig({
5067
},
5168
disableWebsockets: true,
5269
prometheus: true,
53-
openTelemetry: process.env['OPENTELEMETRY_COLLECTOR_ENDPOINT']
54-
? {
55-
serviceName: 'public-graphql-api-gateway',
56-
}
57-
: false,
70+
openTelemetry:
71+
process.env['OPENTELEMETRY_COLLECTOR_ENDPOINT'] || process.env['HIVE_TRACING_ACCESS_TOKEN']
72+
? {
73+
traces: true,
74+
serviceName: 'public-graphql-api-gateway',
75+
}
76+
: undefined,
5877
demandControl: {
5978
maxCost: 1000,
6079
includeExtensionMetadata: true,

0 commit comments

Comments
 (0)