opentelemetry-js icon indicating copy to clipboard operation
opentelemetry-js copied to clipboard

Minimize startup work

Open mbrevda opened this issue 2 years ago • 6 comments
trafficstars

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: Screen Shot 2023-01-11 at 4 33 10 PM With: Screen Shot 2023-01-11 at 4 33 26 PM

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!

mbrevda avatar Jan 11 '23 14:01 mbrevda

Could you share your open-telemetry setup code so we can get an overview of your usage? Thanks!

legendecas avatar Feb 13 '23 11:02 legendecas

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

mbrevda avatar Feb 13 '23 11:02 mbrevda

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.

github-actions[bot] avatar Apr 24 '23 06:04 github-actions[bot]

bump

mbrevda avatar Apr 25 '23 04:04 mbrevda

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.

github-actions[bot] avatar Feb 19 '24 06:02 github-actions[bot]

unstale

mbrevda avatar Feb 19 '24 07:02 mbrevda