Created
May 16, 2022 16:16
-
-
Save ThallyssonKlein/1bdd1967536d6f5c2c6dcb73b0584376 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NodeTracerProvider } from '@opentelemetry/node' | |
import { Resource } from '@opentelemetry/resources' | |
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http' | |
import { BatchSpanProcessor } from '@opentelemetry/tracing' | |
import { trace } from '@opentelemetry/api' | |
const resource = new Resource({ 'service.name': 'api-feature-flag-manager' }) | |
const provider = new NodeTracerProvider({ resource }) | |
import { registerInstrumentations } from '@opentelemetry/instrumentation' | |
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http' | |
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express' | |
import { MongoDBInstrumentation } from '@opentelemetry/instrumentation-mongodb' | |
import { IORedisInstrumentation } from '@opentelemetry/instrumentation-ioredis' | |
registerInstrumentations({ | |
tracerProvider: provider, | |
instrumentations: [ | |
new ExpressInstrumentation(), | |
new MongoDBInstrumentation(), | |
new IORedisInstrumentation(), | |
new HttpInstrumentation({ | |
ignoreIncomingPaths: ['/v1/status', '/metrics', '/health-check', ...[]], | |
}), | |
], | |
}) | |
const collectorOptions = { | |
url: 'http://localhost:4318/v1/traces', // url is optional and can be omitted - default is http://localhost:55681/v1/traces | |
headers: {}, // an optional object containing custom headers to be sent with each request | |
concurrencyLimit: 10, // an optional limit on pending requests | |
} | |
const otlpExporter = new OTLPTraceExporter(collectorOptions) | |
provider.addSpanProcessor( | |
new BatchSpanProcessor(otlpExporter, { | |
// The maximum queue size. After the size is reached spans are dropped. | |
maxQueueSize: 100, | |
// The maximum batch size of every export. It must be smaller or equal to maxQueueSize. | |
maxExportBatchSize: 10, | |
// The interval between two consecutive exports | |
scheduledDelayMillis: 500, | |
// How long the export can run before it is cancelled | |
exportTimeoutMillis: 30000, | |
}) | |
) | |
provider.register() | |
trace.setGlobalTracerProvider(provider) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment