mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* OT init * add bundle analyzer and change external scripts load strategy * exporters for prod * update discord icon and lazy load metamask package * Fixing opentelemetry url * add logs and url schema * Testing NODE_ENV and opentelemetry * Using jaeger as opentelemetry trace collector * move envs to build time * Fixing opentelemetry URL * fix trace exporter for span processor * ENV configuration * filter out incoming requests * describe feature in docs * clean up * Changing otlp endpoint * fix tests --------- Co-authored-by: Nick Zenchik <[email protected]>
74 lines
2.6 KiB
TypeScript
74 lines
2.6 KiB
TypeScript
/* eslint-disable no-console */
|
|
import { diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api';
|
|
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
|
|
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-proto';
|
|
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
|
|
import { Resource } from '@opentelemetry/resources';
|
|
import {
|
|
PeriodicExportingMetricReader,
|
|
ConsoleMetricExporter,
|
|
} from '@opentelemetry/sdk-metrics';
|
|
import { NodeSDK } from '@opentelemetry/sdk-node';
|
|
import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-node';
|
|
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
|
|
|
|
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);
|
|
|
|
const traceExporter = new OTLPTraceExporter();
|
|
|
|
const sdk = new NodeSDK({
|
|
resource: new Resource({
|
|
[SemanticResourceAttributes.SERVICE_NAME]: 'blockscout_frontend',
|
|
[SemanticResourceAttributes.SERVICE_VERSION]: process.env.NEXT_PUBLIC_GIT_TAG || process.env.NEXT_PUBLIC_GIT_COMMIT_SHA || 'unknown_version',
|
|
[SemanticResourceAttributes.SERVICE_INSTANCE_ID]:
|
|
process.env.NEXT_PUBLIC_APP_INSTANCE ||
|
|
process.env.NEXT_PUBLIC_APP_HOST?.replace('.blockscout.com', '').replaceAll('-', '_') ||
|
|
'unknown_app',
|
|
}),
|
|
spanProcessor: new SimpleSpanProcessor(traceExporter),
|
|
traceExporter,
|
|
metricReader: new PeriodicExportingMetricReader({
|
|
exporter:
|
|
process.env.NODE_ENV === 'production' ?
|
|
new OTLPMetricExporter() :
|
|
new ConsoleMetricExporter(),
|
|
}),
|
|
instrumentations: [
|
|
getNodeAutoInstrumentations({
|
|
'@opentelemetry/instrumentation-http': {
|
|
ignoreIncomingRequestHook: (request) => {
|
|
try {
|
|
if (!request.url) {
|
|
return false;
|
|
}
|
|
const url = new URL(request.url, `http://${ request.headers.host }`);
|
|
if (
|
|
url.pathname.startsWith('/_next/static/') ||
|
|
url.pathname.startsWith('/_next/data/') ||
|
|
url.pathname.startsWith('/assets/') ||
|
|
url.pathname.startsWith('/static/') ||
|
|
url.pathname.startsWith('/favicon/') ||
|
|
url.pathname.startsWith('/envs.js')
|
|
) {
|
|
return true;
|
|
}
|
|
} catch (error) {}
|
|
return false;
|
|
},
|
|
},
|
|
}),
|
|
],
|
|
});
|
|
|
|
if (process.env.OTEL_SDK_ENABLED) {
|
|
sdk.start();
|
|
|
|
process.on('SIGTERM', () => {
|
|
sdk
|
|
.shutdown()
|
|
.then(() => console.log('Tracing terminated'))
|
|
.catch((error) => console.log('Error terminating tracing', error))
|
|
.finally(() => process.exit(0));
|
|
});
|
|
}
|