Skip to content

Conversation

@btomaj
Copy link

@btomaj btomaj commented Oct 28, 2025

Which problem is this PR solving?

This PR makes console.dir depth configurable in ConsoleSpanExporter, ConsoleMetricExporter, and ConsoleLogRecordExporter to resolve problem using with Cloudflare (excessive depth), and Semantic Conventions for Generative AI (insufficient depth).

Fixes #5800

Short description of the changes

  1. An optional options parameter is added to the constructors of ConsoleSpanExporter and ConsoleLogRecordExporter.
  2. An optional depth property is added to the options parameter of the constructors of ConsoleSpanExporter, ConsoleMetricExporter, and ConsoleLogRecordExporter that controls the depth setting of console.dir().

Type of change

  • New feature (non-breaking change which adds functionality)

NB: ConsoleSpanExporter, ConsoleMetricExporter, and ConsoleLogRecordExporter are not well documented, only used in examples, so there was no existing documentation to update.

How Has This Been Tested?

  • packages/opentelemetry-sdk-trace-base/test/common/export/ConsoleSpanExporter.test.ts
  • packages/sdk-metrics/test/export/ConsoleMetricExporter.test.ts
  • experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

…rter

Add optional depth parameter to ConsoleLogRecordExporter constructor to control
console.dir output depth. Defaults to 3 for backward compatibility.

- Add ConsoleLogRecordOptions interface with depth parameter
- Add constructor to accept options
- Use configurable depth instead of hardcoded value
- Add tests for default, custom numeric, and null depth values
…orter

Add optional depth parameter to ConsoleSpanExporter constructor to control
console.dir output depth. Defaults to 3 for backward compatibility.

- Add ConsoleSpanOptions interface with depth parameter
- Add constructor to accept options
- Use configurable depth instead of hardcoded value
- Add tests for default, custom numeric, and null depth values
…rter

Add optional depth parameter to ConsoleMetricExporter options to control
console.dir output depth. Defaults to null for backward compatibility.

- Add depth parameter to ConsoleMetricExporterOptions interface
- Convert _sendMetrics from static to instance method to access depth
- Use configurable depth instead of hardcoded null value
- Add tests for default null depth and custom numeric depth values
@btomaj btomaj requested a review from a team as a code owner October 28, 2025 03:58
@cjihrig
Copy link
Contributor

cjihrig commented Oct 28, 2025

It's worth noting a few things:

@btomaj
Copy link
Author

btomaj commented Oct 28, 2025

  • There are other console.dir() flags besides depth. If this were to be added, it would feel incomplete to only support depth.

I agree, and I also don't think depth is a very good name. I would have changed the default to null instead of adding it as an option, but I didn't know why it had been set to 3 (instead of the default of 2 when the option is undefined), so it seemed safest to me to declare it as a configurable option. Why has the default been set to 3, and is setting the default to null an option?

On a second reading, I see that you are right. I misunderstood the conversation. Would something like this be a better change?

import { inspect } from 'node:util';

console.log(inspect(obj, { depth: null, colors: true }));

@cjihrig
Copy link
Contributor

cjihrig commented Oct 29, 2025

I agree, and I also don't think depth is a very good name.

depth is a fine name, and matches the actual parameter name used by console.dir(). I was just pointing out that there are other parameters that probably make sense to include if this were to land.

Would something like this be a better change?

In Node, that general approach would likely be fine because that's how console.dir() is actually implemented in Node, so that should solve the Cloudflare use case (although this really should be fixed on their side). I'm unsure about any implications for the browser though. You'll probably need an OTel maintainer to weigh in on that. You also still have the issue of whether or not to make the inspect() options configurable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants