Skip to content

Have a way to skip console.warn logs on initialisation #201

Closed
@JGAntunes

Description

@JGAntunes

Is your feature request related to a problem? Please describe.

As part of integrating Honeycomb and open telemetry in - https://github.com/netlify/build - we've spotted there's a set of console warnings that always show up when initialising the SDK:

  • // warn if api key is missing
    if (!opts.apiKey) {
    console.warn(MISSING_API_KEY_ERROR);
    }
    // warn if service name is missing
    if (!opts.serviceName) {
    console.warn(MISSING_SERVICE_NAME_ERROR);
    }
    // warn if dataset is set while using an environment-aware key
    if (opts.apiKey && !isClassic(opts.apiKey) && opts.dataset) {
    console.warn(IGNORED_DATASET_ERROR);
    }
    // warn if dataset is missing if using classic key
    if (opts.apiKey && isClassic(opts.apiKey) && !opts.dataset) {
    console.warn(MISSING_DATASET_ERROR);
    }

We're using an open telemetry collector which exports traces to Honeycomb directly, however we would still like to leverage the packaged spanProcessor, traceExporter, etc. that the @honeycombio/opentelemetry-node module exports.

  • export class HoneycombSDK extends NodeSDK {
    constructor(options?: HoneycombOptions) {
    const opts = computeOptions(options);
    super({
    ...opts,
    serviceName: opts?.serviceName,
    resource: configureHoneycombResource(opts),
    metricReader: getHoneycombMetricReader(opts),
    spanProcessor: configureBatchWithBaggageSpanProcessor(opts),
    sampler: configureDeterministicSampler(opts?.sampleRate),
    });
    if (opts.debug) {
    diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);
    diag.debug(JSON.stringify(opts, null, 2));
    }
    }
    }

These warnings however won't let us use the SDK directly in prod since our process execution is customer facing and so are the logs it produces (including the warnings mentioned above ☝️) and for which we have no control over.

Describe the solution you'd like

Having a way to optionally disable the logs? Either by only logging when opts.debug === true or by having a specific flag we could check? (e.g. opts.skipOptionsValidation or something like that)

Describe alternatives you've considered

I guess we can manually setup our own NodeSDK and potentially use the components this module exports directly, something like (still struggling with some type incompatibilies which I think are related with the versions imported):

Nevertheless I think it's extra setup work we could bypass if we had a way to bypass the warning logs 👍

Additional context

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions