Repository navigation
Description
What happened?
Since #6780 (in 3.0.0-rc.0), isAnyValue() in @opentelemetry/core rejects a plain object when any of its values is undefined. maybeAddAttribute() then drops the whole attribute and logs Invalid attribute value set for key: ....
The same function already skips undefined items inside arrays:
// Special case: `undefined` in an array is allowed because it has
// meaning (the array index of subsequent items). ...
if (item !== undefined && !isAnyValueInternal(item, visited)) {There is no matching skip for object values, so [undefined] is valid but { a: undefined } is not. With the 2.x / 0.2xx SDK the same log records kept the attribute.
This hits code that builds structured attribute values with optional fields. In opentelemetry-js-contrib, @opentelemetry/instrumentation-openai builds gen_ai.input.messages parts like { type: 'text', content: captureMessageContent ? text : undefined }. With content capture off (the default), the whole gen_ai.input.messages / gen_ai.output.messages attribute disappears, not only the content.
Expected: an undefined object value is skipped (omitted from the stored value), the same as setAttribute(key, undefined) at the top level and undefined array items. A nested undefined should not invalidate the parent value.
OpenTelemetry Setup Code
import { logs, SeverityNumber } from '@opentelemetry/api';
import {
LoggerProvider,
InMemoryLogRecordExporter,
SimpleLogRecordProcessor,
} from '@opentelemetry/sdk-logs';
const exporter = new InMemoryLogRecordExporter();
const provider = new LoggerProvider({
processors: [new SimpleLogRecordProcessor({ exporter })],
});
logs.setGlobalLoggerProvider(provider);
logs.getLogger('repro').emit({
severityNumber: SeverityNumber.INFO,
attributes: {
ok: [{ type: 'text' }],
dropped: [{ type: 'text', content: undefined }],
},
});
console.log(exporter.getFinishedLogRecords()[0].attributes);
// actual: { ok: [ { type: 'text' } ] }
// expected: { ok: [ { type: 'text' } ], dropped: [ { type: 'text' } ] }package.json
{
"dependencies": {
"@opentelemetry/api": "1.10.0-rc.0",
"@opentelemetry/core": "3.0.0-rc.0",
"@opentelemetry/sdk-logs": "3.0.0-rc.0"
}
}Relevant log output
Invalid attribute value set for key: dropped
Runtime and Version
Node.js v26.9.0
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
trentm commentedon Oct 14, 2026
Getting a little deeper looking at the culprit functions:
isLogAttributeValuein sdk-logs v2 was more permissive than the currentisAnyValuein core v3.In the 2.x version of
sdk-logs:but in 3.x
core:Another possible consideration, beyond saying "yes, this is an accepted AnyValue", is whether we normalize that attribute object.
I.e. whether the added attribute is
{foo: 'bar', a: undefined}or{foo: 'bar'}.In
sdk-logsv2 it is the former:A possible issue with that is that when sent via OTLP, both
undefinedandnullare represented the same -- asAnyValue {}-- which ends up asnullon the other end.In other words, in sdk-logs v2 this logger.emit:
Looks like this via ConsoleLogRecordExporter:
but like this via OTLP:
Note that this is not what the current sdk-logs v2 is doing (as I showed above).
I agree that the "builds structured attribute values with optional fields" is convenient.
trentm commentedon Oct 14, 2026
My play/test script for use with v3 (i.e. logs in the
apipackage):trentm commentedon Oct 14, 2026
To get the same behaviour the functional (no comments, tests yet) diff is this:
To get the
Expected: an undefined object value is skippedbehaviour is a bit more work.