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

[sdk-node] automatically configure logs exporter based on enviornment variables

Open pichlermarc opened this issue 1 year ago • 2 comments

Currently, we don't auto-configure a LogRecordProcessor/exporter combination when using the @opentelemetry/sdk-node package. Goal of this issue is to implement exporter selection for metrics based on this specification:

  • https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#exporter-selection

For this issue to be considered done we need to implement the following behavior:

If no log record proccessor is configured by the user:

  • [ ] use OTEL_LOGS_EXPORTER environment variable to determine an exporter and add it to the LoggerProvider that's created by NodeSDK
    • pair it up with a BatchLogRecordProcessor
    • see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#exporter-selection
  • [ ] use the OTEL_EXPORTER_OTLP_LOGS_PROTOCOL to determine the OTLP exporter to use (http/json, http/protobuf, grpc)
    • see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#specify-protocol
  • [ ] use the OTEL_EXPORTER_OTLP_PROTOCOL env var as a fallback to the above to determine the OTLP exporter to use (http/json, http/protobuf, grpc)
  • [ ] fallback to using http/protobuf if none of the two protocol env vars are set

pichlermarc avatar Mar 18 '24 09:03 pichlermarc

Can assign to me.

mhennoch avatar Apr 17 '24 21:04 mhennoch

It's yours :slightly_smiling_face:

pichlermarc avatar Apr 18 '24 12:04 pichlermarc

Hi guys, sorry for bothering you, but is it true that currently logs auto instrumentation is not supported for nodejs like we have it for python?

If yes, is PR #4740 implement this?

evheniyt avatar Jul 09 '24 07:07 evheniyt

@evheniyt Recent versions of instrumentation packages for Bunyan, Winston, and Pino do support auto-instrumenting those libraries to support log sending via the Logs Bridge API (https://opentelemetry.io/docs/specs/otel/logs/bridge-api/). However, for that log sending to work, a global LoggerProvider needs to be setup to receive those log records from the instrumented libraries. This issue is about getting the OTel SDK for Node.js (a.k.a. NodeSDK) to automatically register a global LoggerProvider is a way similar to how it registers a default global TracerProvider for tracing.

trentm avatar Jul 09 '24 21:07 trentm

to automatically register a global LoggerProvider

Currently, when using the NodeSDK, it will only register a global LoggerProvider if you pass in the logRecordProcessor config option. Something like:

const sdk = new NodeSDK({
  // ... other options
  logRecordProcessor: new BatchLogRecordProcessor(new OTLPLogExporter())
});
sdk.start();

(Aside: I notice that the logRecordProcessor option isn't even documented at https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-sdk-node/README.md#configuration)

trentm avatar Jul 09 '24 21:07 trentm