-
If I want to use Bun runtime - and that is a requirement we have - then we have to use this programmatic approach: https://the-guild.dev/graphql/hive/docs/gateway/deployment/runtimes/bun But then we have a problem: OTEL tracing wont work.
import 'apm/index.ts' // This is where we initialize our global opentelemetry instance
// Consumed by CLI: `yarn hive-gateway supergraph`
export const gatewayConfig: GatewayCLIConfig = {
port: 3000,
supergraph: './supergraph.graphql',
graphiql: false,
logging: log,
openTelemetry: {
initializeNodeSDK: false, // Already done by `import 'apm/index.ts'` above
inheritContext: true,
propagateContext: true,
spans: {
http: true,
graphqlParse: false,
graphqlValidate: false,
graphqlExecute: false,
subgraphExecute: false,
upstreamFetch: true,
},
}
}; If I start the app using But if I use the programmatic approach suggested in the link above then it doesn't work. This is true for both The only way I can make it work is by exporting a factory method: // Consumed by `index.ts`: This will make opentelemetry tracing work:
export const generateGatewayConfig = async (): Promise<GatewayCLIConfig> => {
// Cache creation is only part of config when using for serve-cli, see node_modules/@graphql-mesh/serve-cli/esm/config.js
const cacheConfig = {
type: 'redis' as const,
host: config.REDIS_HOST ?? 'localhost',
port: config.REDIS_PORT ?? '6379',
password: config.REDIS_PASSWORD ?? '',
};
const pubsub = new PubSub();
const cache = await getCacheInstanceFromConfig(
{ cache: cacheConfig },
{
pubsub,
logger: log,
},
);
// Plugin creation are only part of config when using for serve-cli, see node_modules/@graphql-mesh/serve-cli/esm/config.js
// For programmatic hive-gateway usage, we need to define these plugins in the config manually:
const builtinPlugins = await getBuiltinPluginsFromConfig(
{
openTelemetry: {
logger: log
initializeNodeSDK: false, // Already done by `import 'apm/index.ts'` above
inheritContext: true,
propagateContext: true,
spans: {
http: true,
graphqlParse: false,
graphqlValidate: false,
graphqlExecute: false,
subgraphExecute: false,
upstreamFetch: true,
},
},
},
{
cache,
},
);
return defineConfig({
supergraph: './supergraph.grapqhl',
graphiql: false,
// Append extra stuff that @graphql-mesh/serve-cli adds:
pubsub,
cache,
plugins() {
return builtinPlugins;
},
});
}; And then using it as such in const { generateGatewayConfig } = await import('./gateway.config.js');
const { createGatewayRuntime } = await import('@graphql-hive/gateway');
const gatewayConfig = await generateGatewayConfig();
const server = Bun.serve({
fetch: gatewayRuntime,
hostname,
port,
}); Since using a static Anyone that can shed some helpful ideas or light on my situation? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
There is an ongoing work to add Bun to our E2E test suite but overall it should work as is. import { useOpenTelemetry, createGatewayRuntime } from '@graphql-hive/gateway';
createGatewayRuntime({
plugins: ctx => [
useOpenTelemetry({
...ctx,
// other otel options
})
]
}) |
Beta Was this translation helpful? Give feedback.
There is an ongoing work to add Bun to our E2E test suite but overall it should work as is.
graphql-hive/gateway#81
For the plugins that are not available in prgraommatic API as builtin, you can import and use them (not documented yer unfortunately)