Skip to content

Commit

Permalink
feat: Add connectivity check to Jaeger endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinMinkov committed Feb 22, 2023
1 parent d6553fb commit a79b6c3
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createServer } from 'http';
import { useGraphQlJit } from '@envelop/graphql-jit';
import { useDisableIntrospection } from '@envelop/disable-introspection';
import { useOpenTelemetry } from '@envelop/opentelemetry';
import http from 'node:http';

import { buildProvider } from './tracing';
import { schema } from './resolvers';
Expand All @@ -24,6 +25,26 @@ function initJaegerProvider() {
'Jaeger service name not found. Please ensure that the Jaeger service name is properly configured and available.'
);
}

// Check if Jaeger endpoint is available.
let [hostname, port] = process.env.JAEGER_ENDPOINT.replace(
'http://',
''
).split(':');
port = port?.split('/')[0];
const req = http.request({
hostname,
method: 'GET',
port,
path: '/',
});
req.on('error', () => {
throw new Error(
'Jaeger endpoint not available. Please ensure that the Jaeger endpoint is properly configured and available.'
);
});
req.end();
req.socket?.end?.();
}
return provider;
}
Expand Down

0 comments on commit a79b6c3

Please sign in to comment.