|
1 | 1 | // @ts-expect-error not a dependency |
2 | 2 | import { defineConfig } from '@graphql-hive/gateway'; |
3 | 3 | // @ts-expect-error not a dependency |
4 | | -import { openTelemetrySetup } from '@graphql-hive/gateway/opentelemetry/setup'; |
| 4 | +import { hiveTracingSetup } from '@graphql-hive/plugin-opentelemetry/setup'; |
5 | 5 | import { AsyncLocalStorageContextManager } from '@opentelemetry/context-async-hooks'; |
6 | 6 | 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'; |
7 | 9 |
|
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 | +} |
22 | 39 |
|
23 | 40 | const defaultQuery = `# |
24 | 41 | # Welcome to the Hive Console GraphQL API. |
@@ -50,11 +67,13 @@ export const gatewayConfig = defineConfig({ |
50 | 67 | }, |
51 | 68 | disableWebsockets: true, |
52 | 69 | 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, |
58 | 77 | demandControl: { |
59 | 78 | maxCost: 1000, |
60 | 79 | includeExtensionMetadata: true, |
|
0 commit comments