opentelemetry-js
opentelemetry-js copied to clipboard
Minimize startup work
With traditional long-running servers, cold start time with optl's is negligible (as long as it is reasonable) as it is only incurred at server startup time. With serverless workloads, it's incurred for every request adding latency to the response. It would be great if this could be improved by minimizing the amount of work incurred on startup.
With my setup, loading OPTL increases startup times by ~120%.
Without:
With:

Looking through the tree and codebase, there seems to be work that is being done unnecessarily. For example, it really necessary to load 5 different exporters by default? Perhaps this could be more configurable to only load the configured exporters...
I also wonder if there could be some way to pre-instrument the code (at build time), preventing the need to instrument at runtime.
Thanks!
Could you share your open-telemetry setup code so we can get an overview of your usage? Thanks!
Sure - here it is:
import opentelemetry from '@opentelemetry/sdk-node'
import {diag, DiagConsoleLogger, DiagLogLevel} from '@opentelemetry/api'
import {Resource} from '@opentelemetry/resources'
import {SemanticResourceAttributes} from '@opentelemetry/semantic-conventions'
import {MySQL2Instrumentation} from '@opentelemetry/instrumentation-mysql2'
import {ExpressInstrumentation} from '@opentelemetry/instrumentation-express'
import {HttpInstrumentation} from '@opentelemetry/instrumentation-http'
import {GrpcInstrumentation} from '@opentelemetry/instrumentation-grpc'
import {TraceExporter as CloudTraceExporter} from '@google-cloud/opentelemetry-cloud-trace-exporter'
import {OTLPTraceExporter} from '@opentelemetry/exporter-trace-otlp-grpc'
// For troubleshooting, set the log level to DiagLogLevel.DEBUG
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.NONE)
let traceExporter
if (process.env.K_CONFIGURATION) traceExporter = new CloudTraceExporter()
if (process.env.OTEL_EXPORTER_OTLP_ENDPOINT) {
traceExporter = new OTLPTraceExporter() // new opentelemetry.tracing.ConsoleSpanExporter()
}
const sdk = new opentelemetry.NodeSDK({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: '[NAME]'
}),
traceExporter,
instrumentations: [
new MySQL2Instrumentation(),
new ExpressInstrumentation(),
new GrpcInstrumentation(),
new HttpInstrumentation()
]
})
sdk.start()
process.on('SIGTERM', () => {
sdk.shutdown().finally(() => process.exit(0))
})
export default sdk
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.
bump
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.
unstale