Skip to content

Performance: Make NodeSDK instrumentation + body attributes opt-in #66

@heiwen

Description

@heiwen

What is the problem this feature would solve?

Right now the opentelemetry plugin:

  • Initializes the OpenTelemetry NodeSDK by default
  • Automatically records request/response body + sizes, which requires body/stream transformations

Both add noticeable overhead and make it hard to run lightweight or custom OTel setups (Bun, edge, manual SDK, etc), especially with larger streaming calls (e.g. proxying LLM calls). It also kind of goes against the performance spirit of Elysia.

Per the OTel HTTP semantic conventions, body size attributes are opt-in and should only be recorded when explicitly enabled or already known (e.g. via content-length):

https://opentelemetry.io/docs/specs/semconv/http/http-spans/

Specifically:

  • http.request.body
  • http.request.body.size
  • http.response.body
  • http.response.body.size

What is the feature you are proposing to solve the problem?

  1. Make NodeSDK initialisation opt-in:
new Elysia()
  .use(
    opentelemetry({
      // default to empty array
      instrumentations: [getNodeAutoInstrumentations()]
    })
  )
  1. Make body + size capture opt-in:
new Elysia()
  .use(
    opentelemetry({
      // default to false
      captureBodies: true
    })
  )
  1. Less performance critical, but to align with OTEL spec conventions, headers should also be opt-in for security reasons.

This would probably also allow to reduce the dependencies from @opentelemetry/sdk-node to @opentelemetry/sdk-trace-base.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions